[llvm] [utils] support both files originating from split-file in DiffUpdater (PR #166679)

Henrik G. Olsson via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 5 16:58:17 PST 2025


https://github.com/hnrklssn created https://github.com/llvm/llvm-project/pull/166679

With this change DiffUpdater can update expected files even if both files are created by split-files, if one of them ends with ".expected". This is useful when a file is created and then modified during the test.

>From b09911fed5d7bae8f11065920c69fe4875484c67 Mon Sep 17 00:00:00 2001
From: "Henrik G. Olsson" <h_olsson at apple.com>
Date: Wed, 5 Nov 2025 16:47:38 -0800
Subject: [PATCH] [utils] support both files originating from split-file in
 DiffUpdater

With this change DiffUpdater can update expected files even if both
files are created by split-files, if one of them ends with ".expected".
This is useful when a file is created and then modified during the test.
---
 llvm/utils/lit/lit/DiffUpdater.py             | 21 ++++++++++++-------
 .../tests/Inputs/diff-test-update/.gitignore  |  1 +
 .../{split-both.test => split-both.in}        |  4 +---
 .../Inputs/diff-test-update/split-both.out    |  9 ++++++++
 llvm/utils/lit/tests/diff-test-update.py      |  3 ++-
 5 files changed, 26 insertions(+), 12 deletions(-)
 rename llvm/utils/lit/tests/Inputs/diff-test-update/{split-both.test => split-both.in} (56%)
 create mode 100644 llvm/utils/lit/tests/Inputs/diff-test-update/split-both.out

diff --git a/llvm/utils/lit/lit/DiffUpdater.py b/llvm/utils/lit/lit/DiffUpdater.py
index a29c46fb8508f..9e75e4b4513df 100644
--- a/llvm/utils/lit/lit/DiffUpdater.py
+++ b/llvm/utils/lit/lit/DiffUpdater.py
@@ -117,27 +117,32 @@ def get_source_and_target(a, b, test_path, commands):
     Try to figure out which file is the test output and which is the reference.
     """
     split_target_dir = SplitFileTarget.get_target_dir(commands, test_path)
+    a_target = None
+    b_target = None
     if split_target_dir:
         a_target = SplitFileTarget.create(a, commands, test_path, split_target_dir)
         b_target = SplitFileTarget.create(b, commands, test_path, split_target_dir)
-        if a_target and b_target:
-            return None
-        if a_target:
+        if a_target and not b_target:
             return b, a_target
-        if b_target:
+        if b_target and not a_target:
             return a, b_target
 
+    if not a_target:
+        a_target = NormalFileTarget(a)
+    if not b_target:
+        b_target = NormalFileTarget(b)
+
     expected_suffix = ".expected"
     if a.endswith(expected_suffix) and not b.endswith(expected_suffix):
-        return b, NormalFileTarget(a)
+        return b, a_target
     if b.endswith(expected_suffix) and not a.endswith(expected_suffix):
-        return a, NormalFileTarget(b)
+        return a, b_target
 
     tmp_substr = ".tmp"
     if tmp_substr in a and not tmp_substr in b:
-        return a, NormalFileTarget(b)
+        return a, b_target
     if tmp_substr in b and not tmp_substr in a:
-        return b, NormalFileTarget(a)
+        return b, a_target
 
     return None
 
diff --git a/llvm/utils/lit/tests/Inputs/diff-test-update/.gitignore b/llvm/utils/lit/tests/Inputs/diff-test-update/.gitignore
index aea8ee3be4982..5a7c177454546 100644
--- a/llvm/utils/lit/tests/Inputs/diff-test-update/.gitignore
+++ b/llvm/utils/lit/tests/Inputs/diff-test-update/.gitignore
@@ -8,3 +8,4 @@ multiple-split-file-populated.test
 single-split-file-no-expected.test
 split-c-comments.test
 split whitespace.test
+split-both.test
diff --git a/llvm/utils/lit/tests/Inputs/diff-test-update/split-both.test b/llvm/utils/lit/tests/Inputs/diff-test-update/split-both.in
similarity index 56%
rename from llvm/utils/lit/tests/Inputs/diff-test-update/split-both.test
rename to llvm/utils/lit/tests/Inputs/diff-test-update/split-both.in
index f564f446cc94b..df767f704f1c1 100644
--- a/llvm/utils/lit/tests/Inputs/diff-test-update/split-both.test
+++ b/llvm/utils/lit/tests/Inputs/diff-test-update/split-both.in
@@ -1,9 +1,7 @@
 # RUN: split-file %s %t
+# RUN: echo baz > %t/split-both.out
 # RUN: diff %t/split-both.expected %t/split-both.out
 
-# ignore the fact that it's called ".expected"
-# when comparing two files originating in split-file
-
 #--- split-both.expected
 FOO
 #--- split-both.out
diff --git a/llvm/utils/lit/tests/Inputs/diff-test-update/split-both.out b/llvm/utils/lit/tests/Inputs/diff-test-update/split-both.out
new file mode 100644
index 0000000000000..a2f74d4db3fee
--- /dev/null
+++ b/llvm/utils/lit/tests/Inputs/diff-test-update/split-both.out
@@ -0,0 +1,9 @@
+# RUN: split-file %s %t
+# RUN: echo baz > %t/split-both.out
+# RUN: diff %t/split-both.expected %t/split-both.out
+
+#--- split-both.expected
+baz
+#--- split-both.out
+BAR
+
diff --git a/llvm/utils/lit/tests/diff-test-update.py b/llvm/utils/lit/tests/diff-test-update.py
index 8b9f4610f7f95..e23d3879bb56c 100644
--- a/llvm/utils/lit/tests/diff-test-update.py
+++ b/llvm/utils/lit/tests/diff-test-update.py
@@ -5,6 +5,7 @@
 # RUN: cp %S/Inputs/diff-test-update/single-split-file-no-expected.in %S/Inputs/diff-test-update/single-split-file-no-expected.test
 # RUN: cp %S/Inputs/diff-test-update/split-c-comments.in %S/Inputs/diff-test-update/split-c-comments.test
 # RUN: cp %S/Inputs/diff-test-update/split-whitespace.in "%S/Inputs/diff-test-update/split whitespace.test"
+# RUN: cp %S/Inputs/diff-test-update/split-both.in %S/Inputs/diff-test-update/split-both.test
 
 # RUN: not %{lit} --update-tests -v %S/Inputs/diff-test-update | FileCheck %s
 
@@ -15,6 +16,7 @@
 # RUN: diff --strip-trailing-cr %S/Inputs/diff-test-update/single-split-file-no-expected.out %S/Inputs/diff-test-update/single-split-file-no-expected.test
 # RUN: diff --strip-trailing-cr %S/Inputs/diff-test-update/split-c-comments.out %S/Inputs/diff-test-update/split-c-comments.test
 # RUN: diff --strip-trailing-cr %S/Inputs/diff-test-update/split-whitespace.out "%S/Inputs/diff-test-update/split whitespace.test"
+# RUN: diff --strip-trailing-cr %S/Inputs/diff-test-update/split-both.out %S/Inputs/diff-test-update/split-both.test
 
 
 # CHECK: # update-diff-test: could not deduce source and target from {{.*}}1.in and {{.*}}2.in
@@ -22,7 +24,6 @@
 # CHECK: # update-diff-test: copied {{.*}}my-file.txt to {{.*}}my-file.expected
 # CHECK: # update-diff-test: copied {{.*}}1.txt to {{.*}}empty.txt
 # CHECK: # update-diff-test: copied {{.*}}diff-tmp.test.tmp.txt to {{.*}}diff-t-out.txt
-# CHECK: # update-diff-test: could not deduce source and target from {{.*}}split-both.expected and {{.*}}split-both.out
 # CHECK: # update-diff-test: copied {{.*}}unrelated-split.txt to {{.*}}unrelated-split.expected
 
 



More information about the llvm-commits mailing list