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 \ Index: utils/lit/lit/TestRunner.py =================================================================== --- utils/lit/lit/TestRunner.py +++ utils/lit/lit/TestRunner.py @@ -346,7 +346,7 @@ """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)) @@ -354,6 +354,7 @@ 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": @@ -362,6 +363,8 @@ 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: @@ -370,6 +373,18 @@ 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: + lines += "Filename: %s" % os.path.relpath(file, path) + 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 @@ -378,8 +393,11 @@ 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: utils/lit/tests/Inputs/shtest-shell/diff-r.txt =================================================================== --- /dev/null +++ utils/lit/tests/Inputs/shtest-shell/diff-r.txt @@ -0,0 +1,54 @@ +# Check recursive diff ("diff -r"). + +# Create two directories for further comparison. +# RUN: rm -rf %t/dir1 %t/dir2 +# RUN: mkdir -p %t/dir1 %t/dir2 + +# Create same files in both of the dirs. +# RUN: echo "hello" > %t/dir1/f1 +# RUN: echo "hello" > %t/dir2/f1 + +# Create same subdirectories with same contents. +# RUN: mkdir -p %t/dir1/subdir %t/dir2/subdir +# RUN: echo "12345" > %t/dir1/subdir/f01 +# RUN: echo "12345" > %t/dir2/subdir/f01 +# RUN: echo "xxx" > %t/dir1/subdir/f02 +# RUN: echo "xxx" > %t/dir2/subdir/f02 + +# Create empty subdirectories with same names. +# RUN: mkdir -p %t/dir1/empty_subdir %t/dir2/empty_subdir +# RUN: diff -r %t/dir1 %t/dir2 + +# Add two empty files with different names, "diff -r" should fail. +# RUN: touch %t/dir1/dir1unique +# RUN: touch %t/dir2/dir2unique +# RUN: not diff -r %t/dir1 %t/dir2 +# RUN: rm %t/dir1/dir1unique %t/dir2/dir2unique + +# Same filenames but different content, "diff -r" should fail. +# RUN: echo "00000" > %t/dir2/subdir/f01 +# RUN: not diff -r %t/dir1 %t/dir2 +# RUN: echo "12345" > %t/dir2/subdir/f01 + +# An extra file in one of the directories, "dirr -r" should fail. +# RUN: touch %t/dir2/extrafile +# RUN: not diff -r %t/dir1 %t/dir2 + +# Non-empty extra file, "diff -r" should fail. +# RUN: echo "content" > %t/dir2/extrafile +# RUN: not diff -r %t/dir1 %t/dir2 +# RUN: rm %t/dir2/extrafile + +# Empty extra directory, "diff -r" should fail. +# RUN: mkdir -p %t/dir1/extra_subdir +# RUN: not diff -r %t/dir1 %t/dir2 + +# Non-empty extra directory, diff -r should fail. +# RUN: mkdir -p %t/dir1/extra_subdir/dir +# RUN: echo "1337" > %t/dir1/extra_subdir/dir/file +# RUN: not diff -r %t/dir1 %t/dir2 + +# Sanity check for the test directory. +# RUN: rm -rf %t/dir1/extra_subdir +# RUN: diff -r %t/dir1 %t/dir2 +# RUN: rm -rf %t/dir1 %t/dir2