Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/FileCheck
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ def similar(a, b):
return SequenceMatcher(None, a, b).ratio()


def escape_non_regex_or_skip(match_obj):
non_regex = match_obj.group('non_regex')
if non_regex:
return re.escape(non_regex)
return match_obj.group()


def escape_non_regex_parts(string):
regex_line = re.sub(r"((?P<non_regex>[^\{{2}]+)|(?P<regex>\{\{(.*?)\}\}))",
escape_non_regex_or_skip,
check_expression)

return regex_line

def dump_check(check):
print("check dump")
print("\tcheck_type: {}".format(check.check_type))
Expand Down Expand Up @@ -82,7 +96,7 @@ with open(check_file) as f:
line = line.rstrip()

if not args.strict_whitespace:
line = re.sub("\\s+", ' ', line).strip()
line = re.sub("\\s+", ' ', line)

# CHECK and CHECK-NEXT
strict_whitespace_match = "" if args.strict_whitespace and args.match_full_lines else " ?"
Expand All @@ -100,9 +114,9 @@ with open(check_file) as f:

match_type = MatchType.SUBSTRING

regex_line = re.sub(r"\{\{(.*?)\}\}", r"\1", check_expression)

if check_expression != regex_line:
if re.search(r"\{\{.*\}\}", check_expression):
regex_line = escape_non_regex_parts(check_expression)
regex_line = re.sub(r"\{\{(.*?)\}\}", r"\1", regex_line)
match_type = MatchType.REGEX
check_expression = regex_line

Expand Down Expand Up @@ -178,6 +192,8 @@ current_scan_base = 0
stdin_input_iter = enumerate(sys.stdin)
for line_idx, line in stdin_input_iter:
line = line.rstrip()
if not args.strict_whitespace:
line = re.sub("\\s+", ' ', line)

input_lines.append(line)

Expand All @@ -189,9 +205,6 @@ for line_idx, line in stdin_input_iter:

elif current_check.check_type == CheckType.CHECK:
if current_check.match_type == MatchType.SUBSTRING:
if not args.strict_whitespace:
line = re.sub("\\s+", ' ', line).strip()

if args.match_full_lines:
if current_check.expression != line:
continue
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/lit.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import lit.formats

config.name = "Doorstop integration tests"
config.name = "FileCheck.py integration tests"
config.test_format = lit.formats.ShTest("0")

# LLVM LIT: Is it possible to pass user defined parameter into a test script?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
; CHECK: {{^}}The following braces must be escaped by FileCheck: ( inside braces ): 0/1{{$}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The following braces must be escaped by FileCheck: ( inside braces ): 0/1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
; RUN: cat %S/filecheck.input | %FILECHECK_EXEC %S/filecheck.check | %FILECHECK_TESTER_EXEC %s --match-full-lines
; CHECK: {{^.*}}FileCheck{{$}}
; CHECK-EMPTY:
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
; RUN: cd / && %CLANG_EXEC -fembed-bitcode -g -O0 -MJ %S/raw_compilation_database.tmp %s -o %s.exe
; RUN: cd %CURRENT_DIR
; RUN: compilation_database.sh %S/raw_compilation_database.tmp %S/compile_commands.tmp
; RUN: compilation_database.py %S/compile_commands.tmp %S/compile_commands.json
; RUN: %MULL_EXEC -enable-ast -test-framework CustomTest -compdb-path %S/compile_commands.json -compilation-flags="" -mutators=scalar_value_mutator -reporters=IDE -reporters=Elements -report-dir=%S -report-name=report %s.exe| %FILECHECK_EXEC %s --strict-whitespace
; CHECK-NOT: No mutants found. Mutation score: infinitely high
; CHECK: Running mutants (threads: 1): 0/1{{.*$}}
; CHECK: {{.*}}:17:3: warning: Replacing scalar with 0 or 42
; CHECK: {{^ }}return SUCCESS;{{$}}
; CHECK: {{^ }}^{{$}}
**/

enum Enum { SUCCESS = 1234 };

Enum foo() {
return SUCCESS;
};

int main() {
return foo() != SUCCESS;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
Extracting bitcode from executable (threads: 1): 0/1
Extracting bitcode from executable (threads: 1): 1/1. Finished in 3ms.

Loading bitcode files (threads: 1): 0/1
Loading bitcode files (threads: 1): 1/1. Finished in 12ms.

AST Search: looking for mutations in the source files (threads: 1): 0/1
AST Search: looking for mutations in the source files (threads: 1): 1/1. Finished in 12ms.

Compiling instrumented code (threads: 1): 0/1
Compiling instrumented code (threads: 1): 1/1. Finished in 12ms.

Loading dynamic libraries (threads: 1): 0/1
Loading dynamic libraries (threads: 1): 1/1. Finished in 0ms.

Searching tests (threads: 1): 0/1
Searching tests (threads: 1): 1/1. Finished in 0ms.

Preparing original test run (threads: 1): 0/1
Preparing original test run (threads: 1): 1/1. Finished in 1ms.

Running original tests (threads: 1): 0/1
Running original tests (threads: 1): 1/1. Finished in 10ms.

Applying function filter: no debug info (threads: 1): 0/1
Applying function filter: no debug info (threads: 1): 1/1. Finished in 13ms.

Applying function filter: file path (threads: 1): 0/1
Applying function filter: file path (threads: 1): 1/1. Finished in 10ms.

Instruction selection (threads: 1): 0/1
Instruction selection (threads: 1): 1/1. Finished in 13ms.

Searching mutants across functions (threads: 1): 0/1
Searching mutants across functions (threads: 1): 1/1. Finished in 10ms.
MutationsFinder: found 1 mutations.

Applying filter: no debug info (threads: 1): 0/1
Applying filter: no debug info (threads: 1): 1/1. Finished in 0ms.

Applying filter: file path (threads: 1): 0/1
Applying filter: file path (threads: 1): 1/1. Finished in 1ms.

Prepare mutations (threads: 1): 0/1
Prepare mutations (threads: 1): 1/1. Finished in 0ms.

Cloning functions for mutation (threads: 1): 0/1
Cloning functions for mutation (threads: 1): 1/1. Finished in 12ms.

Removing original functions (threads: 1): 0/1
Removing original functions (threads: 1): 1/1. Finished in 11ms.

Redirect mutated functions (threads: 1): 0/1
Redirect mutated functions (threads: 1): 1/1. Finished in 0ms.

Applying mutations (threads: 1): 0/1
Applying mutations (threads: 1): 1/1. Finished in 0ms.

Compiling original code (threads: 1): 0/1
Compiling original code (threads: 1): 1/1. Finished in 11ms.

Running mutants (threads: 1): 0/1
Running mutants (threads: 1): 1/1. Finished in 11ms.

Survived mutants (0/1):

/opt/mull-integration-tests/tests/mutations/scalar_value/13_enum_value/sample.cpp:17:3: warning: Replacing scalar with 0 or 42
return SUCCESS;
^
Mutation score: 100%
Mutation Testing Elements reporter: generating report to /opt/mull-integration-tests/tests/mutations/scalar_value/13_enum_value/report.json

Total execution time: 146ms
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
; RUN: cat %S/filecheck.input | (%FILECHECK_EXEC %S/filecheck.check 2>&1; test $? = 0;) | %FILECHECK_TESTER_EXEC %s --strict-whitespace --match-full-lines
; CHECK:{{^.*}}FileCheck{{$}}
; CHECK-EMPTY: