Skip to content

Commit bb800f7

Browse files
committed
CHECK: regex lines: match full lines when strict mode is enabled
1 parent 8de0e95 commit bb800f7

File tree

7 files changed

+26
-3
lines changed

7 files changed

+26
-3
lines changed

filecheck/FileCheck.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def exit_handler(code):
283283
line = canonicalize_whitespace(line)
284284

285285
# CHECK and CHECK-NEXT
286-
strict_whitespace_match = "" if args.strict_whitespace and args.match_full_lines else " *"
286+
strict_whitespace_match = "" if strict_mode else " *"
287287

288288
check_regex = "{}({}):{}(.*)".format(before_prefix, check_prefix, strict_whitespace_match)
289289
check_match = re.search(check_regex, line)
@@ -296,7 +296,7 @@ def exit_handler(code):
296296
if check_match:
297297
check_keyword = check_match.group(2)
298298
check_expression = check_match.group(3)
299-
if not (args.strict_whitespace and args.match_full_lines):
299+
if not strict_mode:
300300
check_expression = check_expression.strip(' ')
301301

302302
match_type = MatchType.SUBSTRING
@@ -306,6 +306,11 @@ def exit_handler(code):
306306
regex_line = re.sub(r"\{\{(.*?)\}\}", r"\1", regex_line)
307307
match_type = MatchType.REGEX
308308
check_expression = regex_line
309+
if strict_mode:
310+
if check_expression[0] != "^":
311+
check_expression = "^" + check_expression
312+
if check_expression[-1] != "$":
313+
check_expression = check_expression + "$"
309314

310315
check = Check(check_type=check_type,
311316
match_type=match_type,
@@ -325,7 +330,7 @@ def exit_handler(code):
325330

326331
check_keyword = check_match.group(2)
327332
check_expression = check_match.group(3)
328-
if not (args.strict_whitespace and args.match_full_lines):
333+
if not strict_mode:
329334
check_expression = check_expression.strip(' ')
330335

331336
if re.search(r"\{\{.*\}\}", check_expression):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CHECK:Substring2{{.*}}Substring3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Substring1 Substring2 Substring3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --match-full-lines --strict-whitespace
2+
CHECK:{{.*}}filecheck.check:1:7: error: CHECK: expected string not found in input
3+
CHECK:CHECK:Substring2{{.*}}Substring3
4+
CHECK: ^
5+
CHECK:<stdin>:1:1: note: scanning from here
6+
CHECK:Substring1 Substring2 Substring3
7+
CHECK:^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CHECK:Substring1{{.*}}Substring2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Substring1 Substring2 Substring3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --match-full-lines --strict-whitespace
2+
CHECK:{{.*}}filecheck.check:1:7: error: CHECK: expected string not found in input
3+
CHECK:CHECK:Substring1{{.*}}Substring2
4+
CHECK: ^
5+
CHECK:<stdin>:1:1: note: scanning from here
6+
CHECK:Substring1 Substring2 Substring3
7+
CHECK:^

0 commit comments

Comments
 (0)