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,
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)
# 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: $ "cat" "{{[^"]*}}.foo"
+# CHECK: $ "diff" "-u" "-" "{{[^"]*}}.foo"
+# CHECK-NOT: note
+# CHECK-NOT: error
+
+# CHECK: $ "cat" "{{[^"]*}}.foo"
+# CHECK: $ "diff" "-u" "{{[^"]*}}.foo" "-"
+# CHECK-NOT: note
+# CHECK-NOT: error
+
+# CHECK: $ "cat" "{{[^"]*}}.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: $ "cat" "{{[^"]*}}.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: $ "cat" "{{[^"]*}}.foo"
+# CHECK: $ "diff" "-" "{{[^"]*}}.foo"
+# CHECK-NOT: note
+# CHECK-NOT: error
+# CHECK: $ "FileCheck"
+# CHECK-NOT: note
+# CHECK-NOT: error
+
+# CHECK: $ "cat" "{{[^"]*}}.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: ***
# CHECK: PASS: shtest-shell :: valid-shell.txt
-# CHECK: Failing Tests (31)
+# CHECK: Failing Tests (33)