test.py revision c2c48ffdd623b4e58b34115d1521b0988a42b217
12c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# Copyright (C) 2014 The Android Open Source Project
22c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil#
32c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# Licensed under the Apache License, Version 2.0 (the "License");
42c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# you may not use this file except in compliance with the License.
52c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# You may obtain a copy of the License at
62c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil#
72c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil#   http://www.apache.org/licenses/LICENSE-2.0
82c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil#
92c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# Unless required by applicable law or agreed to in writing, software
102c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# distributed under the License is distributed on an "AS IS" BASIS,
112c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
122c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# See the License for the specific language governing permissions and
132c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil# limitations under the License.
142c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
152c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilfrom common.testing                  import ToUnicode
162c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilfrom file_format.c1visualizer.parser import ParseC1visualizerStream
172c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilfrom file_format.c1visualizer.struct import C1visualizerFile, C1visualizerPass
182c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilfrom file_format.checker.parser      import ParseCheckerStream, ParseCheckerAssertion
192c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilfrom file_format.checker.struct      import CheckerFile, TestCase, TestAssertion, RegexExpression
202c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilfrom match.file                      import MatchFiles
212c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilfrom match.line                      import MatchLines
222c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
232c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilimport io
242c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilimport unittest
252c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
262c27f2ccf316aebf96cf365d33d2834a8206444dDavid BrazdilCheckerException = SystemExit
272c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
282c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilclass MatchLines_Test(unittest.TestCase):
292c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
302c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def createTestAssertion(self, checkerString):
312c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    checkerFile = CheckerFile("<checker-file>")
322c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    testCase = TestCase(checkerFile, "TestMethod TestPass", 0)
332c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    return ParseCheckerAssertion(testCase, checkerString, TestAssertion.Variant.InOrder, 0)
342c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
352c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def tryMatch(self, checkerString, c1String, varState={}):
362c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    return MatchLines(self.createTestAssertion(checkerString), ToUnicode(c1String), varState)
372c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
382c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def matches(self, checkerString, c1String, varState={}):
392c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    return self.tryMatch(checkerString, c1String, varState) is not None
402c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
412c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_TextAndWhitespace(self):
422c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches("foo", "foo"))
432c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches("foo", "  foo  "))
442c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches("foo", "foo bar"))
452c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse(self.matches("foo", "XfooX"))
462c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse(self.matches("foo", "zoo"))
472c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
482c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches("foo bar", "foo   bar"))
492c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches("foo bar", "abc foo bar def"))
502c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches("foo bar", "foo foo bar bar"))
512c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
522c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches("foo bar", "foo X bar"))
532c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse(self.matches("foo bar", "foo Xbar"))
542c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
552c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_Pattern(self):
562c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches("foo{{A|B}}bar", "fooAbar"))
572c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches("foo{{A|B}}bar", "fooBbar"))
582c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse(self.matches("foo{{A|B}}bar", "fooCbar"))
592c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
602c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_VariableReference(self):
61c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    self.assertTrue(self.matches("foo<<X>>bar", "foobar", {"X": ""}))
62c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    self.assertTrue(self.matches("foo<<X>>bar", "fooAbar", {"X": "A"}))
63c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    self.assertTrue(self.matches("foo<<X>>bar", "fooBbar", {"X": "B"}))
64c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    self.assertFalse(self.matches("foo<<X>>bar", "foobar", {"X": "A"}))
65c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    self.assertFalse(self.matches("foo<<X>>bar", "foo bar", {"X": "A"}))
662c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    with self.assertRaises(CheckerException):
67c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil      self.assertTrue(self.matches("foo<<X>>bar", "foobar", {}))
682c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
692c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_VariableDefinition(self):
70c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    self.assertTrue(self.matches("foo<<X:A|B>>bar", "fooAbar"))
71c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    self.assertTrue(self.matches("foo<<X:A|B>>bar", "fooBbar"))
72c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    self.assertFalse(self.matches("foo<<X:A|B>>bar", "fooCbar"))
732c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
74c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    env = self.tryMatch("foo<<X:A.*B>>bar", "fooABbar", {})
752c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertEqual(env, {"X": "AB"})
76c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    env = self.tryMatch("foo<<X:A.*B>>bar", "fooAxxBbar", {})
772c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertEqual(env, {"X": "AxxB"})
782c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
79c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    self.assertTrue(self.matches("foo<<X:A|B>>bar<<X>>baz", "fooAbarAbaz"))
80c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    self.assertTrue(self.matches("foo<<X:A|B>>bar<<X>>baz", "fooBbarBbaz"))
81c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    self.assertFalse(self.matches("foo<<X:A|B>>bar<<X>>baz", "fooAbarBbaz"))
822c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
832c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_NoVariableRedefinition(self):
842c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    with self.assertRaises(CheckerException):
85c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil      self.matches("<<X:...>><<X>><<X:...>><<X>>", "foofoobarbar")
862c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
872c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_EnvNotChangedOnPartialMatch(self):
882c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    env = {"Y": "foo"}
89c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    self.assertFalse(self.matches("<<X:A>>bar", "Abaz", env))
902c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse("X" in env.keys())
912c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
922c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_VariableContentEscaped(self):
93c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    self.assertTrue(self.matches("<<X:..>>foo<<X>>", ".*foo.*"))
94c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil    self.assertFalse(self.matches("<<X:..>>foo<<X>>", ".*fooAAAA"))
952c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
962c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
972c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdilclass MatchFiles_Test(unittest.TestCase):
982c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
992c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def matches(self, checkerString, c1String):
1002c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    checkerString = \
1012c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      """
1022c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil        // CHECK-START: MyMethod MyPass
1032c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      """ + checkerString
1042c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    c1String = \
1052c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      """
1062c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil        begin_compilation
1072c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil          name "MyMethod"
1082c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil          method "MyMethod"
1092c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil          date 1234
1102c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil        end_compilation
1112c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil        begin_cfg
1122c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil          name "MyPass"
1132c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      """ + c1String + \
1142c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      """
1152c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil        end_cfg
1162c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      """
1172c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    checkerFile = ParseCheckerStream("<test-file>", "CHECK", io.StringIO(ToUnicode(checkerString)))
1182c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    c1File = ParseC1visualizerStream("<c1-file>", io.StringIO(ToUnicode(c1String)))
1192c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    try:
1202c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      MatchFiles(checkerFile, c1File)
1212c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      return True
1222c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    except CheckerException:
1232c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      return False
1242c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
1252c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_Text(self):
1262c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches( "// CHECK: foo bar", "foo bar"))
1272c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse(self.matches("// CHECK: foo bar", "abc def"))
1282c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
1292c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_Pattern(self):
1302c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches( "// CHECK: abc {{de.}}", "abc de#"))
1312c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse(self.matches("// CHECK: abc {{de.}}", "abc d#f"))
1322c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
1332c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_Variables(self):
1342c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches(
1352c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
136c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil      // CHECK: foo<<X:.>>bar
137c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil      // CHECK: abc<<X>>def
1382c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
1392c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
1402c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo bar
1412c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      abc def
1422c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
1432c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches(
1442c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
145c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil      // CHECK: foo<<X:([0-9]+)>>bar
146c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil      // CHECK: abc<<X>>def
147c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil      // CHECK: ### <<X>> ###
1482c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
1492c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
1502c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo1234bar
1512c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      abc1234def
1522c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      ### 1234 ###
1532c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
1542c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse(self.matches(
1552c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
156c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil      // CHECK: foo<<X:([0-9]+)>>bar
157c2c48ffdd623b4e58b34115d1521b0988a42b217David Brazdil      // CHECK: abc<<X>>def
1582c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
1592c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
1602c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo1234bar
1612c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      abc1235def
1622c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
1632c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
1642c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_InOrderAssertions(self):
1652c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches(
1662c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
1672c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK: foo
1682c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK: bar
1692c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
1702c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
1712c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo
1722c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      bar
1732c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
1742c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse(self.matches(
1752c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
1762c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK: foo
1772c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK: bar
1782c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
1792c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
1802c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      bar
1812c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo
1822c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
1832c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
1842c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_DagAssertions(self):
1852c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches(
1862c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
1872c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-DAG: foo
1882c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-DAG: bar
1892c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
1902c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
1912c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo
1922c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      bar
1932c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
1942c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches(
1952c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
1962c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-DAG: foo
1972c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-DAG: bar
1982c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
1992c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2002c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      bar
2012c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo
2022c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
2032c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
2042c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_DagAssertionsScope(self):
2052c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches(
2062c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2072c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK:     foo
2082c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-DAG: abc
2092c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-DAG: def
2102c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK:     bar
2112c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
2122c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2132c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo
2142c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      def
2152c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      abc
2162c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      bar
2172c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
2182c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse(self.matches(
2192c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2202c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK:     foo
2212c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-DAG: abc
2222c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-DAG: def
2232c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK:     bar
2242c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
2252c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2262c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo
2272c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      abc
2282c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      bar
2292c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      def
2302c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
2312c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse(self.matches(
2322c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2332c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK:     foo
2342c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-DAG: abc
2352c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-DAG: def
2362c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK:     bar
2372c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
2382c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2392c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo
2402c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      def
2412c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      bar
2422c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      abc
2432c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
2442c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
2452c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_NotAssertions(self):
2462c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches(
2472c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2482c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-NOT: foo
2492c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
2502c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2512c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      abc
2522c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      def
2532c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
2542c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse(self.matches(
2552c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2562c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-NOT: foo
2572c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
2582c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2592c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      abc foo
2602c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      def
2612c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
2622c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse(self.matches(
2632c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2642c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-NOT: foo
2652c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-NOT: bar
2662c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
2672c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2682c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      abc
2692c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      def bar
2702c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
2712c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
2722c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_NotAssertionsScope(self):
2732c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches(
2742c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2752c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK:     abc
2762c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-NOT: foo
2772c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK:     def
2782c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
2792c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2802c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      abc
2812c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      def
2822c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
2832c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches(
2842c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2852c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK:     abc
2862c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-NOT: foo
2872c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK:     def
2882c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
2892c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2902c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      abc
2912c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      def
2922c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo
2932c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
2942c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse(self.matches(
2952c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
2962c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK:     abc
2972c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-NOT: foo
2982c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK:     def
2992c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
3002c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
3012c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      abc
3022c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo
3032c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      def
3042c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
3052c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil
3062c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil  def test_LineOnlyMatchesOnce(self):
3072c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertTrue(self.matches(
3082c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
3092c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-DAG: foo
3102c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-DAG: foo
3112c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
3122c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
3132c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo
3142c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      abc
3152c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo
3162c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
3172c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    self.assertFalse(self.matches(
3182c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
3192c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-DAG: foo
3202c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      // CHECK-DAG: foo
3212c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """,
3222c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """
3232c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      foo
3242c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      abc
3252c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil      bar
3262c27f2ccf316aebf96cf365d33d2834a8206444dDavid Brazdil    """))
327