David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 1 | # Copyright (C) 2014 The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
David Brazdil | c4de943 | 2015-05-20 11:03:22 +0100 | [diff] [blame] | 15 | from common.immutables import ImmutableDict |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 16 | from common.testing import ToUnicode |
| 17 | from file_format.c1visualizer.parser import ParseC1visualizerStream |
| 18 | from file_format.c1visualizer.struct import C1visualizerFile, C1visualizerPass |
| 19 | from file_format.checker.parser import ParseCheckerStream, ParseCheckerAssertion |
David Brazdil | b34c35e | 2015-08-20 11:46:04 +0100 | [diff] [blame] | 20 | from file_format.checker.struct import CheckerFile, TestCase, TestAssertion |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 21 | from match.file import MatchTestCase, MatchFailedException |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 22 | from match.line import MatchLines |
| 23 | |
| 24 | import io |
| 25 | import unittest |
| 26 | |
| 27 | CheckerException = SystemExit |
| 28 | |
| 29 | class MatchLines_Test(unittest.TestCase): |
| 30 | |
| 31 | def createTestAssertion(self, checkerString): |
| 32 | checkerFile = CheckerFile("<checker-file>") |
| 33 | testCase = TestCase(checkerFile, "TestMethod TestPass", 0) |
| 34 | return ParseCheckerAssertion(testCase, checkerString, TestAssertion.Variant.InOrder, 0) |
| 35 | |
| 36 | def tryMatch(self, checkerString, c1String, varState={}): |
David Brazdil | c4de943 | 2015-05-20 11:03:22 +0100 | [diff] [blame] | 37 | return MatchLines(self.createTestAssertion(checkerString), |
| 38 | ToUnicode(c1String), |
| 39 | ImmutableDict(varState)) |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 40 | |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 41 | def assertMatches(self, checkerString, c1String, varState={}): |
| 42 | self.assertIsNotNone(self.tryMatch(checkerString, c1String, varState)) |
| 43 | |
| 44 | def assertDoesNotMatch(self, checkerString, c1String, varState={}): |
| 45 | self.assertIsNone(self.tryMatch(checkerString, c1String, varState)) |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 46 | |
| 47 | def test_TextAndWhitespace(self): |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 48 | self.assertMatches("foo", "foo") |
| 49 | self.assertMatches("foo", " foo ") |
| 50 | self.assertMatches("foo", "foo bar") |
| 51 | self.assertDoesNotMatch("foo", "XfooX") |
| 52 | self.assertDoesNotMatch("foo", "zoo") |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 53 | |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 54 | self.assertMatches("foo bar", "foo bar") |
| 55 | self.assertMatches("foo bar", "abc foo bar def") |
| 56 | self.assertMatches("foo bar", "foo foo bar bar") |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 57 | |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 58 | self.assertMatches("foo bar", "foo X bar") |
| 59 | self.assertDoesNotMatch("foo bar", "foo Xbar") |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 60 | |
| 61 | def test_Pattern(self): |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 62 | self.assertMatches("foo{{A|B}}bar", "fooAbar") |
| 63 | self.assertMatches("foo{{A|B}}bar", "fooBbar") |
| 64 | self.assertDoesNotMatch("foo{{A|B}}bar", "fooCbar") |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 65 | |
| 66 | def test_VariableReference(self): |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 67 | self.assertMatches("foo<<X>>bar", "foobar", {"X": ""}) |
| 68 | self.assertMatches("foo<<X>>bar", "fooAbar", {"X": "A"}) |
| 69 | self.assertMatches("foo<<X>>bar", "fooBbar", {"X": "B"}) |
| 70 | self.assertDoesNotMatch("foo<<X>>bar", "foobar", {"X": "A"}) |
| 71 | self.assertDoesNotMatch("foo<<X>>bar", "foo bar", {"X": "A"}) |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 72 | with self.assertRaises(CheckerException): |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 73 | self.tryMatch("foo<<X>>bar", "foobar", {}) |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 74 | |
| 75 | def test_VariableDefinition(self): |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 76 | self.assertMatches("foo<<X:A|B>>bar", "fooAbar") |
| 77 | self.assertMatches("foo<<X:A|B>>bar", "fooBbar") |
| 78 | self.assertDoesNotMatch("foo<<X:A|B>>bar", "fooCbar") |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 79 | |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 80 | env = self.tryMatch("foo<<X:A.*B>>bar", "fooABbar", {}) |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 81 | self.assertEqual(env, {"X": "AB"}) |
David Brazdil | c2c48ff | 2015-05-15 14:24:31 +0100 | [diff] [blame] | 82 | env = self.tryMatch("foo<<X:A.*B>>bar", "fooAxxBbar", {}) |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 83 | self.assertEqual(env, {"X": "AxxB"}) |
| 84 | |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 85 | self.assertMatches("foo<<X:A|B>>bar<<X>>baz", "fooAbarAbaz") |
| 86 | self.assertMatches("foo<<X:A|B>>bar<<X>>baz", "fooBbarBbaz") |
| 87 | self.assertDoesNotMatch("foo<<X:A|B>>bar<<X>>baz", "fooAbarBbaz") |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 88 | |
| 89 | def test_NoVariableRedefinition(self): |
| 90 | with self.assertRaises(CheckerException): |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 91 | self.tryMatch("<<X:...>><<X>><<X:...>><<X>>", "foofoobarbar") |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 92 | |
| 93 | def test_EnvNotChangedOnPartialMatch(self): |
| 94 | env = {"Y": "foo"} |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 95 | self.assertDoesNotMatch("<<X:A>>bar", "Abaz", env) |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 96 | self.assertFalse("X" in env.keys()) |
| 97 | |
| 98 | def test_VariableContentEscaped(self): |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 99 | self.assertMatches("<<X:..>>foo<<X>>", ".*foo.*") |
| 100 | self.assertDoesNotMatch("<<X:..>>foo<<X>>", ".*fooAAAA") |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 101 | |
| 102 | |
| 103 | class MatchFiles_Test(unittest.TestCase): |
| 104 | |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 105 | def assertMatches(self, checkerString, c1String): |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 106 | checkerString = \ |
| 107 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 108 | /// CHECK-START: MyMethod MyPass |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 109 | """ + checkerString |
| 110 | c1String = \ |
| 111 | """ |
| 112 | begin_compilation |
| 113 | name "MyMethod" |
| 114 | method "MyMethod" |
| 115 | date 1234 |
| 116 | end_compilation |
| 117 | begin_cfg |
| 118 | name "MyPass" |
| 119 | """ + c1String + \ |
| 120 | """ |
| 121 | end_cfg |
| 122 | """ |
| 123 | checkerFile = ParseCheckerStream("<test-file>", "CHECK", io.StringIO(ToUnicode(checkerString))) |
| 124 | c1File = ParseC1visualizerStream("<c1-file>", io.StringIO(ToUnicode(c1String))) |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 125 | assert len(checkerFile.testCases) == 1 |
| 126 | assert len(c1File.passes) == 1 |
| 127 | MatchTestCase(checkerFile.testCases[0], c1File.passes[0]) |
| 128 | |
| 129 | def assertDoesNotMatch(self, checkerString, c1String): |
| 130 | with self.assertRaises(MatchFailedException): |
| 131 | self.assertMatches(checkerString, c1String) |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 132 | |
| 133 | def test_Text(self): |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 134 | self.assertMatches("/// CHECK: foo bar", "foo bar") |
| 135 | self.assertDoesNotMatch("/// CHECK: foo bar", "abc def") |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 136 | |
| 137 | def test_Pattern(self): |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 138 | self.assertMatches("/// CHECK: abc {{de.}}", "abc de#") |
| 139 | self.assertDoesNotMatch("/// CHECK: abc {{de.}}", "abc d#f") |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 140 | |
| 141 | def test_Variables(self): |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 142 | self.assertMatches( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 143 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 144 | /// CHECK: foo<<X:.>>bar |
| 145 | /// CHECK: abc<<X>>def |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 146 | """, |
| 147 | """ |
David Brazdil | 4e9aac1 | 2015-05-18 17:45:17 +0100 | [diff] [blame] | 148 | foo0bar |
| 149 | abc0def |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 150 | """) |
| 151 | self.assertMatches( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 152 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 153 | /// CHECK: foo<<X:([0-9]+)>>bar |
| 154 | /// CHECK: abc<<X>>def |
| 155 | /// CHECK: ### <<X>> ### |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 156 | """, |
| 157 | """ |
| 158 | foo1234bar |
| 159 | abc1234def |
| 160 | ### 1234 ### |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 161 | """) |
| 162 | self.assertDoesNotMatch( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 163 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 164 | /// CHECK: foo<<X:([0-9]+)>>bar |
| 165 | /// CHECK: abc<<X>>def |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 166 | """, |
| 167 | """ |
| 168 | foo1234bar |
| 169 | abc1235def |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 170 | """) |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 171 | |
David Brazdil | 4e9aac1 | 2015-05-18 17:45:17 +0100 | [diff] [blame] | 172 | def test_WholeWordMustMatch(self): |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 173 | self.assertMatches("/// CHECK: b{{.}}r", "abc bar def") |
| 174 | self.assertDoesNotMatch("/// CHECK: b{{.}}r", "abc Xbar def") |
| 175 | self.assertDoesNotMatch("/// CHECK: b{{.}}r", "abc barX def") |
| 176 | self.assertDoesNotMatch("/// CHECK: b{{.}}r", "abc b r def") |
David Brazdil | 4e9aac1 | 2015-05-18 17:45:17 +0100 | [diff] [blame] | 177 | |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 178 | def test_InOrderAssertions(self): |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 179 | self.assertMatches( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 180 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 181 | /// CHECK: foo |
| 182 | /// CHECK: bar |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 183 | """, |
| 184 | """ |
| 185 | foo |
| 186 | bar |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 187 | """) |
| 188 | self.assertDoesNotMatch( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 189 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 190 | /// CHECK: foo |
| 191 | /// CHECK: bar |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 192 | """, |
| 193 | """ |
| 194 | bar |
| 195 | foo |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 196 | """) |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 197 | |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame] | 198 | def test_NextLineAssertions(self): |
| 199 | self.assertMatches( |
| 200 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 201 | /// CHECK: foo |
| 202 | /// CHECK-NEXT: bar |
| 203 | /// CHECK-NEXT: abc |
| 204 | /// CHECK: def |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame] | 205 | """, |
| 206 | """ |
| 207 | foo |
| 208 | bar |
| 209 | abc |
| 210 | def |
| 211 | """) |
| 212 | self.assertMatches( |
| 213 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 214 | /// CHECK: foo |
| 215 | /// CHECK-NEXT: bar |
| 216 | /// CHECK: def |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame] | 217 | """, |
| 218 | """ |
| 219 | foo |
| 220 | bar |
| 221 | abc |
| 222 | def |
| 223 | """) |
| 224 | self.assertDoesNotMatch( |
| 225 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 226 | /// CHECK: foo |
| 227 | /// CHECK-NEXT: bar |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame] | 228 | """, |
| 229 | """ |
| 230 | foo |
| 231 | abc |
| 232 | bar |
| 233 | """) |
| 234 | |
| 235 | self.assertDoesNotMatch( |
| 236 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 237 | /// CHECK: foo |
| 238 | /// CHECK-NEXT: bar |
David Brazdil | 7114119 | 2015-05-19 18:29:40 +0100 | [diff] [blame] | 239 | """, |
| 240 | """ |
| 241 | bar |
| 242 | foo |
| 243 | abc |
| 244 | """) |
| 245 | |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 246 | def test_DagAssertions(self): |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 247 | self.assertMatches( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 248 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 249 | /// CHECK-DAG: foo |
| 250 | /// CHECK-DAG: bar |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 251 | """, |
| 252 | """ |
| 253 | foo |
| 254 | bar |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 255 | """) |
| 256 | self.assertMatches( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 257 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 258 | /// CHECK-DAG: foo |
| 259 | /// CHECK-DAG: bar |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 260 | """, |
| 261 | """ |
| 262 | bar |
| 263 | foo |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 264 | """) |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 265 | |
| 266 | def test_DagAssertionsScope(self): |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 267 | self.assertMatches( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 268 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 269 | /// CHECK: foo |
| 270 | /// CHECK-DAG: abc |
| 271 | /// CHECK-DAG: def |
| 272 | /// CHECK: bar |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 273 | """, |
| 274 | """ |
| 275 | foo |
| 276 | def |
| 277 | abc |
| 278 | bar |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 279 | """) |
| 280 | self.assertDoesNotMatch( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 281 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 282 | /// CHECK: foo |
| 283 | /// CHECK-DAG: abc |
| 284 | /// CHECK-DAG: def |
| 285 | /// CHECK: bar |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 286 | """, |
| 287 | """ |
| 288 | foo |
| 289 | abc |
| 290 | bar |
| 291 | def |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 292 | """) |
| 293 | self.assertDoesNotMatch( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 294 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 295 | /// CHECK: foo |
| 296 | /// CHECK-DAG: abc |
| 297 | /// CHECK-DAG: def |
| 298 | /// CHECK: bar |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 299 | """, |
| 300 | """ |
| 301 | foo |
| 302 | def |
| 303 | bar |
| 304 | abc |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 305 | """) |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 306 | |
| 307 | def test_NotAssertions(self): |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 308 | self.assertMatches( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 309 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 310 | /// CHECK-NOT: foo |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 311 | """, |
| 312 | """ |
| 313 | abc |
| 314 | def |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 315 | """) |
| 316 | self.assertDoesNotMatch( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 317 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 318 | /// CHECK-NOT: foo |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 319 | """, |
| 320 | """ |
| 321 | abc foo |
| 322 | def |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 323 | """) |
| 324 | self.assertDoesNotMatch( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 325 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 326 | /// CHECK-NOT: foo |
| 327 | /// CHECK-NOT: bar |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 328 | """, |
| 329 | """ |
| 330 | abc |
| 331 | def bar |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 332 | """) |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 333 | |
| 334 | def test_NotAssertionsScope(self): |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 335 | self.assertMatches( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 336 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 337 | /// CHECK: abc |
| 338 | /// CHECK-NOT: foo |
| 339 | /// CHECK: def |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 340 | """, |
| 341 | """ |
| 342 | abc |
| 343 | def |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 344 | """) |
| 345 | self.assertMatches( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 346 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 347 | /// CHECK: abc |
| 348 | /// CHECK-NOT: foo |
| 349 | /// CHECK: def |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 350 | """, |
| 351 | """ |
| 352 | abc |
| 353 | def |
| 354 | foo |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 355 | """) |
| 356 | self.assertDoesNotMatch( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 357 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 358 | /// CHECK: abc |
| 359 | /// CHECK-NOT: foo |
| 360 | /// CHECK: def |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 361 | """, |
| 362 | """ |
| 363 | abc |
| 364 | foo |
| 365 | def |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 366 | """) |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 367 | |
| 368 | def test_LineOnlyMatchesOnce(self): |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 369 | self.assertMatches( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 370 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 371 | /// CHECK-DAG: foo |
| 372 | /// CHECK-DAG: foo |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 373 | """, |
| 374 | """ |
| 375 | foo |
| 376 | abc |
| 377 | foo |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 378 | """) |
| 379 | self.assertDoesNotMatch( |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 380 | """ |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 381 | /// CHECK-DAG: foo |
| 382 | /// CHECK-DAG: foo |
David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 383 | """, |
| 384 | """ |
| 385 | foo |
| 386 | abc |
| 387 | bar |
David Brazdil | 6423cf5 | 2015-05-20 14:57:54 +0100 | [diff] [blame] | 388 | """) |
David Brazdil | b34c35e | 2015-08-20 11:46:04 +0100 | [diff] [blame] | 389 | |
| 390 | def test_EvalAssertions(self): |
| 391 | self.assertMatches("/// CHECK-EVAL: True", "foo") |
| 392 | self.assertDoesNotMatch("/// CHECK-EVAL: False", "foo") |
| 393 | |
| 394 | self.assertMatches("/// CHECK-EVAL: 1 + 2 == 3", "foo") |
| 395 | self.assertDoesNotMatch("/// CHECK-EVAL: 1 + 2 == 4", "foo") |
| 396 | |
| 397 | twoVarTestCase = """ |
| 398 | /// CHECK-DAG: <<X:\d+>> <<Y:\d+>> |
| 399 | /// CHECK-EVAL: <<X>> > <<Y>> |
| 400 | """ |
| 401 | self.assertMatches(twoVarTestCase, "42 41"); |
| 402 | self.assertDoesNotMatch(twoVarTestCase, "42 43") |