[PATCH] D41776: [lit] Implement "-r" option for builtin "diff" command + a test using that.
Max Moroz via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 5 09:44:00 PST 2018
Dor1s created this revision.
Dor1s added reviewers: zturner, morehouse, vsk.
That would allow to recursively compare directories in tests using
"diff -r" on Windows in a similar way as it can be done on Linux or Mac.
https://reviews.llvm.org/D41776
Files:
test/tools/llvm-cov/multithreaded-report.test
utils/lit/lit/TestRunner.py
Index: utils/lit/lit/TestRunner.py
===================================================================
--- utils/lit/lit/TestRunner.py
+++ utils/lit/lit/TestRunner.py
@@ -346,40 +346,57 @@
"""executeBuiltinDiff - Compare files line by line."""
args = expand_glob_expressions(cmd.args, cmd_shenv.cwd)[1:]
try:
- opts, args = getopt.gnu_getopt(args, "wbu", ["strip-trailing-cr"])
+ opts, args = getopt.gnu_getopt(args, "wbur", ["strip-trailing-cr"])
except getopt.GetoptError as err:
raise InternalShellError(cmd, "Unsupported: 'diff': %s" % str(err))
filelines, filepaths = ([] for i in range(2))
ignore_all_space = False
ignore_space_change = False
unified_diff = False
+ recursive_diff = False
strip_trailing_cr = False
for o, a in opts:
if o == "-w":
ignore_all_space = True
elif o == "-b":
ignore_space_change = True
elif o == "-u":
unified_diff = True
+ elif o == "-r":
+ recursive_diff = True
elif o == "--strip-trailing-cr":
strip_trailing_cr = True
else:
assert False, "unhandled option"
if len(args) != 2:
raise InternalShellError(cmd, "Error: missing or extra operand")
+ def recursivelyReadDir(path):
+ lines = []
+ for dir, subdirList, fileList in os.walk(path):
+ for file in fileList:
+ with open(os.path.join(dir, file), 'r') as f:
+ lines += f.readlines()
+ if not fileList:
+ # Add empty dirs for comparison as well.
+ lines.append('Empty dir "%s'"." % os.path.relpath(dir, path))
+ return lines
+
stderr = StringIO()
stdout = StringIO()
exitCode = 0
try:
for file in args:
if not os.path.isabs(file):
file = os.path.realpath(os.path.join(cmd_shenv.cwd, file))
filepaths.append(file)
- with open(file, 'r') as f:
- filelines.append(f.readlines())
+ if recursive_diff:
+ filelines.append(recursivelyReadDir(file))
+ else:
+ with open(file, 'r') as f:
+ filelines.append(f.readlines())
def compose2(f, g):
return lambda x: f(g(x))
Index: test/tools/llvm-cov/multithreaded-report.test
===================================================================
--- test/tools/llvm-cov/multithreaded-report.test
+++ test/tools/llvm-cov/multithreaded-report.test
@@ -1,8 +1,5 @@
# Test "report" command with and without multiple threads.
-# Temporarily disable the test on Windows as it doesn't support "diff -r".
-REQUIRES: shell
-
RUN: llvm-cov report -num-threads=1 \
RUN: -path-equivalence=/tmp,%S/Inputs \
RUN: -instr-profile %S/Inputs/multithreaded_report/main.profdata \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41776.128766.patch
Type: text/x-patch
Size: 2920 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180105/f06d4008/attachment.bin>
More information about the llvm-commits
mailing list