Skip to content

Commit f462731

Browse files
authored
Merge pull request mull-project#149 from tlively/is-part-of-word-check
Ignore check prefixes at the ends of words
2 parents 7611489 + 65175eb commit f462731

File tree

7 files changed

+31
-11
lines changed

7 files changed

+31
-11
lines changed

filecheck/FileCheck.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ class CheckResult(Enum):
138138
CHECK_NOT_WITHOUT_MATCH = 5
139139

140140

141+
# Allow check prefixes only at the beginnings of lines or after non-word characters.
142+
before_prefix = "^(.*?[^\w-])?"
143+
144+
141145
def check_line(line, current_check, match_full_lines):
142146
if current_check.check_type == CheckType.CHECK_EMPTY:
143147
if line != '':
@@ -281,17 +285,17 @@ def exit_handler(code):
281285
# CHECK and CHECK-NEXT
282286
strict_whitespace_match = "" if args.strict_whitespace and args.match_full_lines else " *"
283287

284-
check_regex = ".*?({}):{}(.*)".format(check_prefix, strict_whitespace_match)
288+
check_regex = "{}({}):{}(.*)".format(before_prefix, check_prefix, strict_whitespace_match)
285289
check_match = re.search(check_regex, line)
286290
check_type = CheckType.CHECK
287291
if not check_match:
288-
check_regex = ".*?({}-NEXT):{}(.*)".format(check_prefix, strict_whitespace_match)
292+
check_regex = "{}({}-NEXT):{}(.*)".format(before_prefix, check_prefix, strict_whitespace_match)
289293
check_match = re.search(check_regex, line)
290294
check_type = CheckType.CHECK_NEXT
291295

292296
if check_match:
293-
check_keyword = check_match.group(1)
294-
check_expression = check_match.group(2)
297+
check_keyword = check_match.group(2)
298+
check_expression = check_match.group(3)
295299
if not (args.strict_whitespace and args.match_full_lines):
296300
check_expression = check_expression.strip(' ')
297301

@@ -309,18 +313,18 @@ def exit_handler(code):
309313
expression=check_expression,
310314
source_line=line,
311315
check_line_idx=line_idx,
312-
start_index=check_match.start(2))
316+
start_index=check_match.start(3))
313317

314318
checks.append(check)
315319
continue
316320

317-
check_not_regex = ".*({}-NOT):{}(.*)".format(check_prefix, strict_whitespace_match)
321+
check_not_regex = "{}({}-NOT):{}(.*)".format(before_prefix, check_prefix, strict_whitespace_match)
318322
check_match = re.search(check_not_regex, line)
319323
if check_match:
320324
match_type = MatchType.SUBSTRING
321325

322-
check_keyword = check_match.group(1)
323-
check_expression = check_match.group(2)
326+
check_keyword = check_match.group(2)
327+
check_expression = check_match.group(3)
324328
if not (args.strict_whitespace and args.match_full_lines):
325329
check_expression = check_expression.strip(' ')
326330

@@ -336,15 +340,15 @@ def exit_handler(code):
336340
expression=check_expression,
337341
source_line=line,
338342
check_line_idx=line_idx,
339-
start_index=check_match.start(2))
343+
start_index=check_match.start(3))
340344

341345
checks.append(check)
342346
continue
343347

344-
check_empty_regex = ".*({}-EMPTY):".format(check_prefix)
348+
check_empty_regex = "{}({}-EMPTY):".format(before_prefix, check_prefix)
345349
check_match = re.search(check_empty_regex, line)
346350
if check_match:
347-
check_keyword = check_match.group(1)
351+
check_keyword = check_match.group(2)
348352

349353
check = Check(check_type=CheckType.CHECK_EMPTY,
350354
match_type=MatchType.SUBSTRING,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
string 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
string 2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
string 3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
string 4
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
; CHECK: string 1
2+
; OTHER-CHECK: string 2
3+
; ANOTHER-CHECK: string 3
4+
; YET_ANOTHER-CHECK: string 4
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; RUN: %cat "%S/filecheck.1.input" | %expect_exit 0 --expect-no-content %FILECHECK_EXEC "%S/filecheck.check" --check-prefix CHECK
2+
; RUN: %cat "%S/filecheck.2.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --check-prefix CHECK
3+
4+
; RUN: %cat "%S/filecheck.2.input" | %expect_exit 0 --expect-no-content %FILECHECK_EXEC "%S/filecheck.check" --check-prefix OTHER-CHECK
5+
; RUN: %cat "%S/filecheck.3.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --check-prefix OTHER-CHECK
6+
7+
; RUN: %cat "%S/filecheck.3.input" | %expect_exit 0 --expect-no-content %FILECHECK_EXEC "%S/filecheck.check" --check-prefix ANOTHER-CHECK
8+
; RUN: %cat "%S/filecheck.4.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --check-prefix ANOTHER-CHECK

0 commit comments

Comments
 (0)