Skip to content

Commit

Permalink
Merge pull request #146 from stanislaw/self-testing
Browse files Browse the repository at this point in the history
Self testing: fix one edge case and some tests to enable FileCheck.py to pass on more tests
  • Loading branch information
stanislaw authored Jun 6, 2020
2 parents 35348bb + 38b79b3 commit 73e7ec5
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 25 deletions.
4 changes: 2 additions & 2 deletions filecheck/FileCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ def main():
# CHECK and CHECK-NEXT
strict_whitespace_match = "" if args.strict_whitespace and args.match_full_lines else " *"

check_regex = ".*({}):{}(.*)".format(check_prefix, strict_whitespace_match)
check_regex = ".*?({}):{}(.*)".format(check_prefix, strict_whitespace_match)
check_match = re.search(check_regex, line)
check_type = CheckType.CHECK
if not check_match:
check_regex = ".*({}-NEXT):{}(.*)".format(check_prefix, strict_whitespace_match)
check_regex = ".*?({}-NEXT):{}(.*)".format(check_prefix, strict_whitespace_match)
check_match = re.search(check_regex, line)
check_type = CheckType.CHECK_NEXT

Expand Down
53 changes: 35 additions & 18 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ def get_os_filename_string():
assert 0, "error: FileCheck.py could not detect OS"


def get_filecheck_py_exec():
cwd = os.getcwd()
return 'python \\"{cwd}/filecheck/FileCheck.py\\"'.format(cwd=cwd)


def get_filecheck_tester_exec():
cwd = os.getcwd()
os_string = get_os_filename_string()

template = '\\"{cwd}/tests/integration/tools/FileCheck/FileCheck-9.0.1-{os_string}\\"'
return template.format(cwd=cwd, os_string=os_string)


def get_filecheck_llvm_path(filecheck_exec):
cwd = os.getcwd()
os_string = get_os_filename_string()
Expand All @@ -41,19 +28,23 @@ def get_filecheck_llvm_path(filecheck_exec):
)


def get_filecheck_py_exec():
cwd = os.getcwd()
return 'python \\"{cwd}/filecheck/FileCheck.py\\"'.format(cwd=cwd)


def formatted_command(string):
return re.sub('\\s+', ' ', string).strip()


def run_lit_tests(c, filecheck_exec, llvm_only):
def run_lit_tests(c, filecheck_exec, filecheck_tester_exec, llvm_only):
assert c
assert filecheck_exec
assert llvm_only is not None

cwd = os.getcwd()

llvm_only_value = "1" if llvm_only else ""
filecheck_tester_exec = get_filecheck_tester_exec()

command = formatted_command("""
lit
Expand All @@ -71,11 +62,37 @@ def run_lit_tests(c, filecheck_exec, llvm_only):
c.run("{}".format(command))


@task
def test_filecheck_llvm(c):
filecheck_llvm_8_exec = get_filecheck_llvm_path(FILECHECK_LLVM_8_EXEC)
filecheck_llvm_9_exec = get_filecheck_llvm_path(FILECHECK_LLVM_9_EXEC)
filecheck_tester_exec = get_filecheck_llvm_path(FILECHECK_LLVM_9_EXEC)

run_lit_tests(c, filecheck_llvm_8_exec, filecheck_tester_exec, True)
run_lit_tests(c, filecheck_llvm_9_exec, filecheck_tester_exec, True)


@task
def test_filecheck_py_using_file_check_llvm_tester(c):
filecheck_exec = get_filecheck_py_exec()
filecheck_tester_exec = get_filecheck_llvm_path(FILECHECK_LLVM_9_EXEC)

run_lit_tests(c, filecheck_exec, filecheck_tester_exec, False)


@task
def test_filecheck_py_using_filecheck_py_tester(c):
filecheck_exec = get_filecheck_py_exec()
filecheck_tester_exec = filecheck_exec

run_lit_tests(c, filecheck_exec, filecheck_tester_exec, False)


@task
def test(c):
run_lit_tests(c, get_filecheck_llvm_path(FILECHECK_LLVM_8_EXEC), True)
run_lit_tests(c, get_filecheck_llvm_path(FILECHECK_LLVM_9_EXEC), True)
run_lit_tests(c, get_filecheck_py_exec(), False)
test_filecheck_llvm(c)
test_filecheck_py_using_file_check_llvm_tester(c)


@task
def clean(c):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
; CHECK:{{^.*filecheck.check:1:(9|10): error: CHECK: expected string not found in input$}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A-very-long-path/filecheck.check:1:9: error: CHECK: expected string not found in input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
; RUN: %cat "%S/filecheck.input" | %expect_exit 0 --expect-no-content %FILECHECK_EXEC "%S/filecheck.check"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
; CHECK: hello1
; CHECK: foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hello1
hello2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" | %FILECHECK_TESTER_EXEC "%s" --match-full-lines

; CHECK: {{.*filecheck.check:2:10: error: CHECK: expected string not found in input$}}
; CHECK: {{^}}; CHECK: foo{{$}}
; CHECK: {{^}} ^{{$}}
; CHECK: {{^<stdin>:.*:.*: note: scanning from here$}}
; CHECK: hello2
; CHECK: ^{{$}}
; CHECK: {{^<stdin>:.*:.*: note: possible intended match here$}}
; CHECK: hello2
; CHECK: ^
; CHECK-EMPTY:
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: %cat "%S/filecheck.input" | %expect_exit 0 --expect-no-content %FILECHECK_EXEC "%S/filecheck.check"
; RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --match-full-lines | %FILECHECK_TESTER_EXEC "%s" --match-full-lines --strict-whitespace -check-prefix=OPTION
; RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --match-full-lines | %FILECHECK_TESTER_EXEC "%s" --match-full-lines --strict-whitespace --check-prefix=OPTION

; OPTION:{{^.*}}filecheck.check:1:10: error: CHECK: expected string not found in input{{$}}
; OPTION:; CHECK: hello world
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: %cat "%S/filecheck.input" | %expect_exit 0 --expect-no-content %FILECHECK_EXEC "%S/filecheck.check"
; RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --strict-whitespace | %FILECHECK_TESTER_EXEC "%s" --match-full-lines -check-prefix=OPTION
; RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --strict-whitespace | %FILECHECK_TESTER_EXEC "%s" --match-full-lines --check-prefix=OPTION

; OPTION: {{^.*}}filecheck.check:1:10: error: CHECK: expected string not found in input{{$}}
; OPTION: ; CHECK: hello world hello world
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: %cat "%S/filecheck.input" | %expect_exit 0 --expect-no-content %FILECHECK_EXEC "%S/filecheck.check"
; RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --strict-whitespace | %FILECHECK_TESTER_EXEC "%s" --strict-whitespace --match-full-lines -check-prefix=OPTION
; RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --strict-whitespace | %FILECHECK_TESTER_EXEC "%s" --strict-whitespace --match-full-lines --check-prefix=OPTION

; OPTION:{{^.*}}filecheck.check:1:10: error: CHECK: expected string not found in input{{$}}
; OPTION:; CHECK: hello world hello world
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" | %FILECHECK_TESTER_EXEC "%s" --strict-whitespace --match-full-lines -check-prefix=NO_OPTION
; RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" | %FILECHECK_TESTER_EXEC "%s" --strict-whitespace --match-full-lines --check-prefix=NO_OPTION
; RUN: %cat "%S/filecheck.input" | %expect_exit 0 --expect-no-content %FILECHECK_EXEC "%S/filecheck.check" --strict-whitespace

; NO_OPTION:{{^.*}}filecheck.check:1:14: error: CHECK-NOT: excluded string found in input{{$}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: %cat "%S/filecheck.input" | %expect_exit 0 --expect-no-content %FILECHECK_EXEC "%S/filecheck.check"
; RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --strict-whitespace | %FILECHECK_TESTER_EXEC "%s" --strict-whitespace --match-full-lines -check-prefix=OPTION
; RUN: %cat "%S/filecheck.input" | %expect_exit 1 %FILECHECK_EXEC "%S/filecheck.check" --strict-whitespace | %FILECHECK_TESTER_EXEC "%s" --strict-whitespace --match-full-lines --check-prefix=OPTION

; OPTION:{{^.*}}filecheck.check:1:10: error: CHECK: expected string not found in input{{$}}
; OPTION:; CHECK: hello world hello world
Expand Down

0 comments on commit 73e7ec5

Please sign in to comment.