]> granicus.if.org Git - llvm/commitdiff
Reland r374390: [lit] Extend internal diff to support `-` argument
authorJoel E. Denny <jdenny.ornl@gmail.com>
Sat, 12 Oct 2019 11:57:41 +0000 (11:57 +0000)
committerJoel E. Denny <jdenny.ornl@gmail.com>
Sat, 12 Oct 2019 11:57:41 +0000 (11:57 +0000)
To avoid breaking some tests, D66574, D68664, D67643, and D68668
landed together.  However, D68664 introduced an issue now addressed by
D68839, with which these are now all relanding.

Differential Revision: https://reviews.llvm.org/D67643

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@374650 91177308-0d34-0410-b5e6-96231b3b80d8

utils/lit/lit/builtin_commands/diff.py
utils/lit/tests/Inputs/shtest-shell/diff-encodings.txt
utils/lit/tests/Inputs/shtest-shell/diff-pipes.txt
utils/lit/tests/Inputs/shtest-shell/diff-r-error-7.txt [new file with mode: 0644]
utils/lit/tests/Inputs/shtest-shell/diff-r-error-8.txt [new file with mode: 0644]
utils/lit/tests/max-failures.py
utils/lit/tests/shtest-shell.py

index 562b9ac37ac2257afab13f48ad36f8f1062fc7d0..0e912d150fe96630791a0552a9172f8135abbf98 100644 (file)
@@ -27,8 +27,13 @@ def getDirTree(path, basedir=""):
 def compareTwoFiles(flags, filepaths):
     filelines = []
     for file in filepaths:
-        with open(file, 'rb') as file_bin:
-            filelines.append(file_bin.readlines())
+        if file == "-":
+            stdin_fileno = sys.stdin.fileno()
+            with os.fdopen(os.dup(stdin_fileno), 'rb') as stdin_bin:
+                filelines.append(stdin_bin.readlines())
+        else:
+            with open(file, 'rb') as file_bin:
+                filelines.append(file_bin.readlines())
 
     try:
         return compareTwoTextFiles(flags, filepaths, filelines,
@@ -194,10 +199,13 @@ def main(argv):
     exitCode = 0
     try:
         for file in args:
-            if not os.path.isabs(file):
+            if file != "-" and not os.path.isabs(file):
                 file = os.path.realpath(os.path.join(os.getcwd(), file))
 
             if flags.recursive_diff:
+                if file == "-":
+                    sys.stderr.write("Error: cannot recursively compare '-'\n")
+                    sys.exit(1)
                 dir_trees.append(getDirTree(file))
             else:
                 filepaths.append(file)
index d8b9718a0990098c1db76b0611cc0a2036763eac..044908f7725ce46600d9148de2acc8a59550f126 100644 (file)
@@ -5,5 +5,11 @@
 # RUN: diff -u diff-in.utf8 diff-in.bin && false || true
 # RUN: diff -u diff-in.bin diff-in.utf8 && false || true
 
+# RUN: cat diff-in.bin | diff -u - diff-in.bin
+# RUN: cat diff-in.bin | diff -u diff-in.bin -
+# RUN: cat diff-in.bin | diff -u diff-in.utf16 - && false || true
+# RUN: cat diff-in.bin | diff -u diff-in.utf8 - && false || true
+# RUN: cat diff-in.bin | diff -u - diff-in.utf8 && false || true
+
 # Fail so lit will print output.
 # RUN: false
index ce0abca166172a59d57f7d9936df01d8710a9c4c..0bd73a862518eb70efd35cbcb599016c840306bc 100644 (file)
@@ -5,6 +5,16 @@
 # RUN: diff %t.foo %t.foo | FileCheck -allow-empty -check-prefix=EMPTY %s
 # RUN: diff -u %t.foo %t.bar | FileCheck %s && false || true
 
+# Check input pipe.
+# RUN: echo foo | diff -u - %t.foo
+# RUN: echo foo | diff -u %t.foo -
+# RUN: echo bar | diff -u %t.foo - && false || true
+# RUN: echo bar | diff -u - %t.foo && false || true
+
+# Check output and input pipes at the same time.
+# RUN: echo foo | diff - %t.foo | FileCheck -allow-empty -check-prefix=EMPTY %s
+# RUN: echo bar | diff -u %t.foo - | FileCheck %s && false || true
+
 # Fail so lit will print output.
 # RUN: false
 
diff --git a/utils/lit/tests/Inputs/shtest-shell/diff-r-error-7.txt b/utils/lit/tests/Inputs/shtest-shell/diff-r-error-7.txt
new file mode 100644 (file)
index 0000000..08c5044
--- /dev/null
@@ -0,0 +1,2 @@
+# diff -r currently cannot handle stdin.
+# RUN: diff -r - %t
diff --git a/utils/lit/tests/Inputs/shtest-shell/diff-r-error-8.txt b/utils/lit/tests/Inputs/shtest-shell/diff-r-error-8.txt
new file mode 100644 (file)
index 0000000..26361a9
--- /dev/null
@@ -0,0 +1,2 @@
+# diff -r currently cannot handle stdin.
+# RUN: diff -r %t -
index 5149a91ec0025910d71cfe30e8e12304aae6635a..7bd5c32e72e49e7d30993af889c5beeb1df2b901 100644 (file)
@@ -8,7 +8,7 @@
 #
 # END.
 
-# CHECK: Failing Tests (28)
+# CHECK: Failing Tests (30)
 # CHECK: Failing Tests (1)
 # CHECK: Failing Tests (2)
 # CHECK: error: argument --max-failures: requires positive integer, but found '0'
index 6d9b1aa459c2cdb32b8f36e8e2c3540f0250f064..db57c3af1f1f6e2561e26205c917e9396646ee6b 100644 (file)
 # CHECK: error: command failed with exit status: 1
 # CHECK: $ "true"
 
+# CHECK: $ "cat" "diff-in.bin"
+# CHECK-NOT: error
+# CHECK: $ "diff" "-u" "-" "diff-in.bin"
+# CHECK-NOT: error
+
+# CHECK: $ "cat" "diff-in.bin"
+# CHECK-NOT: error
+# CHECK: $ "diff" "-u" "diff-in.bin" "-"
+# CHECK-NOT: error
+
+# CHECK: $ "cat" "diff-in.bin"
+# CHECK-NOT: error
+# CHECK: $ "diff" "-u" "diff-in.utf16" "-"
+# CHECK: # command output:
+# CHECK-NEXT: ---
+# CHECK-NEXT: +++
+# CHECK-NEXT: @@
+# CHECK-NEXT: {{^ .f.o.o.$}}
+# CHECK-NEXT: {{^-.b.a.r.$}}
+# CHECK-NEXT: {{^\+.b.a.r..}}
+# CHECK-NEXT: {{^ .b.a.z.$}}
+# CHECK: error: command failed with exit status: 1
+# CHECK: $ "true"
+
+# CHECK: $ "cat" "diff-in.bin"
+# CHECK-NOT: error
+# CHECK: $ "diff" "-u" "diff-in.utf8" "-"
+# CHECK: # command output:
+# CHECK-NEXT: ---
+# CHECK-NEXT: +++
+# CHECK-NEXT: @@
+# CHECK-NEXT: -foo
+# CHECK-NEXT: -bar
+# CHECK-NEXT: -baz
+# CHECK-NEXT: {{^\+.f.o.o.$}}
+# CHECK-NEXT: {{^\+.b.a.r..}}
+# CHECK-NEXT: {{^\+.b.a.z.$}}
+# CHECK: error: command failed with exit status: 1
+# CHECK: $ "true"
+
+# CHECK: $ "diff" "-u" "-" "diff-in.utf8"
+# CHECK: # command output:
+# CHECK-NEXT: ---
+# CHECK-NEXT: +++
+# CHECK-NEXT: @@
+# CHECK-NEXT: {{^\-.f.o.o.$}}
+# CHECK-NEXT: {{^\-.b.a.r..}}
+# CHECK-NEXT: {{^\-.b.a.z.$}}
+# CHECK-NEXT: +foo
+# CHECK-NEXT: +bar
+# CHECK-NEXT: +baz
+# CHECK: error: command failed with exit status: 1
+# CHECK: $ "true"
+
 # CHECK: $ "false"
 
 # CHECK: ***
 # CHECK-NOT: error
 # CHECK: $ "true"
 
+# CHECK: $ "echo" "foo"
+# CHECK: $ "diff" "-u" "-" "{{[^"]*}}.foo"
+# CHECK-NOT: note
+# CHECK-NOT: error
+
+# CHECK: $ "echo" "foo"
+# CHECK: $ "diff" "-u" "{{[^"]*}}.foo" "-"
+# CHECK-NOT: note
+# CHECK-NOT: error
+
+# CHECK: $ "echo" "bar"
+# CHECK: $ "diff" "-u" "{{[^"]*}}.foo" "-"
+# CHECK: # command output:
+# CHECK: @@
+# CHECK-NEXT: -foo
+# CHECK-NEXT: +bar
+# CHECK: error: command failed with exit status: 1
+# CHECK: $ "true"
+
+# CHECK: $ "echo" "bar"
+# CHECK: $ "diff" "-u" "-" "{{[^"]*}}.foo"
+# CHECK: # command output:
+# CHECK: @@
+# CHECK-NEXT: -bar
+# CHECK-NEXT: +foo
+# CHECK: error: command failed with exit status: 1
+# CHECK: $ "true"
+
+# CHECK: $ "echo" "foo"
+# CHECK: $ "diff" "-" "{{[^"]*}}.foo"
+# CHECK-NOT: note
+# CHECK-NOT: error
+# CHECK: $ "FileCheck"
+# CHECK-NOT: note
+# CHECK-NOT: error
+
+# CHECK: $ "echo" "bar"
+# CHECK: $ "diff" "-u" "{{[^"]*}}.foo" "-"
+# CHECK: note: command had no output on stdout or stderr
+# CHECK: error: command failed with exit status: 1
+# CHECK: $ "FileCheck"
+# CHECK-NOT: note
+# CHECK-NOT: error
+# CHECK: $ "true"
+
 # CHECK: $ "false"
 
 # CHECK: ***
 # CHECK: File {{.*}}dir1{{.*}}extra_file is a regular empty file while file {{.*}}dir2{{.*}}extra_file is a directory
 # CHECK: error: command failed with exit status: 1
 
+# CHECK: FAIL: shtest-shell :: diff-r-error-7.txt
+# CHECK: *** TEST 'shtest-shell :: diff-r-error-7.txt' FAILED ***
+# CHECK: $ "diff" "-r" "-" "{{[^"]*}}"
+# CHECK: # command stderr:
+# CHECK: Error: cannot recursively compare '-'
+# CHECK: error: command failed with exit status: 1
+
+# CHECK: FAIL: shtest-shell :: diff-r-error-8.txt
+# CHECK: *** TEST 'shtest-shell :: diff-r-error-8.txt' FAILED ***
+# CHECK: $ "diff" "-r" "{{[^"]*}}" "-"
+# CHECK: # command stderr:
+# CHECK: Error: cannot recursively compare '-'
+# CHECK: error: command failed with exit status: 1
+
 # CHECK: PASS: shtest-shell :: diff-r.txt
 
 # CHECK: FAIL: shtest-shell :: error-0.txt
 # CHECK: PASS: shtest-shell :: sequencing-0.txt
 # CHECK: XFAIL: shtest-shell :: sequencing-1.txt
 # CHECK: PASS: shtest-shell :: valid-shell.txt
-# CHECK: Failing Tests (28)
+# CHECK: Failing Tests (30)