diff --git a/llvm/utils/lit/lit/Test.py b/llvm/utils/lit/lit/Test.py index 729097772417..83a09eb784fd 100644 --- a/llvm/utils/lit/lit/Test.py +++ b/llvm/utils/lit/lit/Test.py @@ -307,6 +307,11 @@ class Test: def getFullName(self): return self.suite.config.name + " :: " + "/".join(self.path_in_suite) + def getSummaryName(self, printPathRelativeCWD): + if printPathRelativeCWD: + return os.path.relpath(self.getFilePath()) + return self.getFullName() + def getFilePath(self): if self.file_path: return self.file_path diff --git a/llvm/utils/lit/lit/cl_arguments.py b/llvm/utils/lit/lit/cl_arguments.py index 8f9211ee3f53..8238bc42395a 100644 --- a/llvm/utils/lit/lit/cl_arguments.py +++ b/llvm/utils/lit/lit/cl_arguments.py @@ -91,6 +91,13 @@ def parse_args(): help="Enable -v, but for all tests not just failed tests.", action="store_true", ) + format_group.add_argument( + "-r", + "--relative-paths", + dest="printPathRelativeCWD", + help="Print paths relative to CWD", + action="store_true", + ) format_group.add_argument( "-o", "--output", diff --git a/llvm/utils/lit/lit/display.py b/llvm/utils/lit/lit/display.py index 3a224f734bf7..b565bbc7a4f9 100644 --- a/llvm/utils/lit/lit/display.py +++ b/llvm/utils/lit/lit/display.py @@ -136,9 +136,7 @@ class Display(object): # Show the test failure output, if requested. if (test.isFailure() and self.opts.showOutput) or self.opts.showAllOutput: if test.isFailure(): - print( - "%s TEST '%s' FAILED %s" % ("*" * 20, test.getFullName(), "*" * 20) - ) + print("%s TEST '%s' FAILED %s" % ("*" * 20, test_name, "*" * 20)) out = test.result.output # Encode/decode so that, when using Python 3.6.5 in Windows 10, # print(out) doesn't raise UnicodeEncodeError if out contains @@ -159,7 +157,7 @@ class Display(object): # Report test metrics, if present. if test.result.metrics: - print("%s TEST '%s' RESULTS %s" % ("*" * 10, test.getFullName(), "*" * 10)) + print("%s TEST '%s' RESULTS %s" % ("*" * 10, test_name, "*" * 10)) items = sorted(test.result.metrics.items()) for metric_name, value in items: print("%s: %s " % (metric_name, value.format())) diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py index 5255e2c5e1b5..a585cc0abdd4 100755 --- a/llvm/utils/lit/lit/main.py +++ b/llvm/utils/lit/lit/main.py @@ -329,12 +329,13 @@ def print_results(tests, elapsed, opts): sorted(tests_by_code[code], key=lambda t: t.getFullName()), code, opts.shown_codes, + opts.printPathRelativeCWD, ) print_summary(total_tests, tests_by_code, opts.quiet, elapsed) -def print_group(tests, code, shown_codes): +def print_group(tests, code, shown_codes, printPathRelativeCWD): if not tests: return if not code.isFailure and code not in shown_codes: @@ -342,7 +343,7 @@ def print_group(tests, code, shown_codes): print("*" * 20) print("{} Tests ({}):".format(code.label, len(tests))) for test in tests: - print(" %s" % test.getFullName()) + print(" %s" % test.getSummaryName(printPathRelativeCWD)) sys.stdout.write("\n") diff --git a/llvm/utils/lit/tests/Inputs/print-relative-path/lit.cfg b/llvm/utils/lit/tests/Inputs/print-relative-path/lit.cfg new file mode 100644 index 000000000000..2cf5104e124d --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/print-relative-path/lit.cfg @@ -0,0 +1,7 @@ +import lit.formats + +config.name = "print-relative-path" +config.suffixes = [".txt"] +config.test_format = lit.formats.ShTest() +config.test_source_root = None +config.test_exec_root = None diff --git a/llvm/utils/lit/tests/Inputs/print-relative-path/test.txt b/llvm/utils/lit/tests/Inputs/print-relative-path/test.txt new file mode 100644 index 000000000000..0ddee88ac0bf --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/print-relative-path/test.txt @@ -0,0 +1 @@ +# RUN: echo %var diff --git a/llvm/utils/lit/tests/Inputs/print-relative-path/test2.txt b/llvm/utils/lit/tests/Inputs/print-relative-path/test2.txt new file mode 100644 index 000000000000..3c0fa612b5fb --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/print-relative-path/test2.txt @@ -0,0 +1,2 @@ +# RUN: false + diff --git a/llvm/utils/lit/tests/print-relative-path.py b/llvm/utils/lit/tests/print-relative-path.py new file mode 100644 index 000000000000..7f3809ccd012 --- /dev/null +++ b/llvm/utils/lit/tests/print-relative-path.py @@ -0,0 +1,18 @@ +# RUN: %{lit} --ignore-fail --show-pass %{inputs}/print-relative-path | FileCheck --check-prefix=CHECK-DEFAULT %s +# RUN: %{lit} --ignore-fail --show-pass -r %{inputs}/print-relative-path | FileCheck --check-prefix=CHECK-RELATIVE %s +# RUN: %{lit} --ignore-fail --show-pass --relative-paths %{inputs}/print-relative-path | FileCheck --check-prefix=CHECK-RELATIVE %s + + +# CHECK-DEFAULT: PASS: print-relative-path :: test.txt (1 of 2) +# CHECK-DEFAULT: FAIL: print-relative-path :: test2.txt (2 of 2) +# CHECK-DEFAULT: Passed Tests (1): +# CHECK-DEFAULT: print-relative-path :: test.txt +# CHECK-DEFAULT: Failed Tests (1): +# CHECK-DEFAULT: print-relative-path :: test2.txt + +# CHECK-RELATIVE: PASS: print-relative-path :: test.txt (1 of 2) +# CHECK-RELATIVE: FAIL: print-relative-path :: test2.txt (2 of 2) +# CHECK-RELATIVE: Passed Tests (1): +# CHECK-RELATIVE: Inputs/print-relative-path/test.txt +# CHECK-RELATIVE: Failed Tests (1): +# CHECK-RELATIVE: Inputs/print-relative-path/test2.txt