Skip to content

Conversation

@boomanaiden154
Copy link
Contributor

This is the default for the builtin shell, so the option can just be a
no-op. It is not necessarily the default for diff in an external shell
though, so allow -c to keep things consistent.

Created using spr 1.3.6
@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2025

@llvm/pr-subscribers-testing-tools

Author: Aiden Grossman (boomanaiden154)

Changes

This is the default for the builtin shell, so the option can just be a
no-op. It is not necessarily the default for diff in an external shell
though, so allow -c to keep things consistent.


Full diff: https://github.com/llvm/llvm-project/pull/157584.diff

3 Files Affected:

  • (modified) llvm/utils/lit/lit/builtin_commands/diff.py (+3-1)
  • (added) llvm/utils/lit/tests/Inputs/shtest-shell/diff-c.txt (+14)
  • (modified) llvm/utils/lit/tests/shtest-shell.py (+18-1)
diff --git a/llvm/utils/lit/lit/builtin_commands/diff.py b/llvm/utils/lit/lit/builtin_commands/diff.py
index f2b5869b35889..f0c51fec9e09b 100644
--- a/llvm/utils/lit/lit/builtin_commands/diff.py
+++ b/llvm/utils/lit/lit/builtin_commands/diff.py
@@ -219,7 +219,7 @@ def main(argv):
 
     args = argv[1:]
     try:
-        opts, args = getopt.gnu_getopt(args, "wbuI:U:r", ["strip-trailing-cr"])
+        opts, args = getopt.gnu_getopt(args, "wcbuI:U:r", ["strip-trailing-cr"])
     except getopt.GetoptError as err:
         sys.stderr.write("Unsupported: 'diff': %s\n" % str(err))
         sys.exit(1)
@@ -249,6 +249,8 @@ def main(argv):
             flags.recursive_diff = True
         elif o == "--strip-trailing-cr":
             flags.strip_trailing_cr = True
+        elif o == "-c":
+            continue
         else:
             assert False, "unhandled option"
 
diff --git a/llvm/utils/lit/tests/Inputs/shtest-shell/diff-c.txt b/llvm/utils/lit/tests/Inputs/shtest-shell/diff-c.txt
new file mode 100644
index 0000000000000..3e76d8d0d7101
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/shtest-shell/diff-c.txt
@@ -0,0 +1,14 @@
+# Check that the -c option for the internal diff implementation works.
+
+# RUN: echo 1 > %t.foo
+# RUN: echo 2 >> %t.foo
+# RUN: echo 3 >> %t.foo
+# RUN: echo 4 >> %t.foo
+# RUN: echo 5 >> %t.foo
+
+# RUN: echo 1 > %t.bar
+# RUN: echo 2 >> %t.bar
+# RUN: echo 4 >> %t.bar
+# RUN: echo 5 >> %t.bar
+
+# RUN: diff -c %t.foo %t.bar
diff --git a/llvm/utils/lit/tests/shtest-shell.py b/llvm/utils/lit/tests/shtest-shell.py
index 8f2b865f333a5..d99df45a7f363 100644
--- a/llvm/utils/lit/tests/shtest-shell.py
+++ b/llvm/utils/lit/tests/shtest-shell.py
@@ -44,6 +44,23 @@
 # CHECK-NEXT: # error: command failed with exit status: 1
 #      CHECK: ***
 
+#      CHECK: FAIL: shtest-shell :: diff-c.txt
+#      CHECK: *** TEST 'shtest-shell :: diff-c.txt' FAILED ***
+#      CHECK: diff -c {{[^"]*}}.foo {{[^"]*}}.bar
+#      CHECK: # .---command stdout{{-*}}
+# CHECK-NEXT: # | *** {{[^"]*}}.foo
+# CHECK-NEXT: # | --- {{[^"]*}}.bar
+# CHECK-NEXT: # | ***************
+# CHECK-NEXT: # | *** 1,5 ****
+# CHECK-NEXT: # |   1
+# CHECK-NEXT: # |   2
+# CHECK-NEXT: # | - 3
+# CHECK-NEXT: # |   4
+# CHECK-NEXT: # |   5
+# CHECK-NEXT: # | --- 1,4 ----
+# CHECK-NEXT: # `---{{-*}}
+# CHECK-NEXT: # error: command failed with exit status: 1
+#      CHECK: ***
 
 # CHECK: FAIL: shtest-shell :: diff-encodings.txt
 # CHECK: *** TEST 'shtest-shell :: diff-encodings.txt' FAILED ***
@@ -635,4 +652,4 @@
 
 # CHECK: PASS: shtest-shell :: valid-shell.txt
 # CHECK: Unresolved Tests (1)
-# CHECK: Failed Tests (36)
+# CHECK: Failed Tests (37)

@boomanaiden154
Copy link
Contributor Author

Looks like the two tests that need this are better off with diff -u...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants