Skip to content

Commit 83118de

Browse files
authored
[utils] support both files originating from split-file in DiffUpdater (#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.
1 parent b8868c1 commit 83118de

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

llvm/utils/lit/lit/DiffUpdater.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,27 +117,32 @@ def get_source_and_target(a, b, test_path, commands):
117117
Try to figure out which file is the test output and which is the reference.
118118
"""
119119
split_target_dir = SplitFileTarget.get_target_dir(commands, test_path)
120+
a_target = None
121+
b_target = None
120122
if split_target_dir:
121123
a_target = SplitFileTarget.create(a, commands, test_path, split_target_dir)
122124
b_target = SplitFileTarget.create(b, commands, test_path, split_target_dir)
123-
if a_target and b_target:
124-
return None
125-
if a_target:
125+
if a_target and not b_target:
126126
return b, a_target
127-
if b_target:
127+
if b_target and not a_target:
128128
return a, b_target
129129

130+
if not a_target:
131+
a_target = NormalFileTarget(a)
132+
if not b_target:
133+
b_target = NormalFileTarget(b)
134+
130135
expected_suffix = ".expected"
131136
if a.endswith(expected_suffix) and not b.endswith(expected_suffix):
132-
return b, NormalFileTarget(a)
137+
return b, a_target
133138
if b.endswith(expected_suffix) and not a.endswith(expected_suffix):
134-
return a, NormalFileTarget(b)
139+
return a, b_target
135140

136141
tmp_substr = ".tmp"
137142
if tmp_substr in a and not tmp_substr in b:
138-
return a, NormalFileTarget(b)
143+
return a, b_target
139144
if tmp_substr in b and not tmp_substr in a:
140-
return b, NormalFileTarget(a)
145+
return b, a_target
141146

142147
return None
143148

llvm/utils/lit/tests/Inputs/diff-test-update/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ multiple-split-file-populated.test
88
single-split-file-no-expected.test
99
split-c-comments.test
1010
split whitespace.test
11+
split-both.test

llvm/utils/lit/tests/Inputs/diff-test-update/split-both.test renamed to llvm/utils/lit/tests/Inputs/diff-test-update/split-both.in

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# RUN: split-file %s %t
2+
# RUN: echo baz > %t/split-both.out
23
# RUN: diff %t/split-both.expected %t/split-both.out
34

4-
# ignore the fact that it's called ".expected"
5-
# when comparing two files originating in split-file
6-
75
#--- split-both.expected
86
FOO
97
#--- split-both.out
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# RUN: split-file %s %t
2+
# RUN: echo baz > %t/split-both.out
3+
# RUN: diff %t/split-both.expected %t/split-both.out
4+
5+
#--- split-both.expected
6+
baz
7+
#--- split-both.out
8+
BAR
9+

llvm/utils/lit/tests/diff-test-update.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# RUN: cp %S/Inputs/diff-test-update/single-split-file-no-expected.in %S/Inputs/diff-test-update/single-split-file-no-expected.test
66
# RUN: cp %S/Inputs/diff-test-update/split-c-comments.in %S/Inputs/diff-test-update/split-c-comments.test
77
# RUN: cp %S/Inputs/diff-test-update/split-whitespace.in "%S/Inputs/diff-test-update/split whitespace.test"
8+
# RUN: cp %S/Inputs/diff-test-update/split-both.in %S/Inputs/diff-test-update/split-both.test
89

910
# RUN: not %{lit} --update-tests -v %S/Inputs/diff-test-update | FileCheck %s
1011

@@ -15,14 +16,14 @@
1516
# 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
1617
# RUN: diff --strip-trailing-cr %S/Inputs/diff-test-update/split-c-comments.out %S/Inputs/diff-test-update/split-c-comments.test
1718
# RUN: diff --strip-trailing-cr %S/Inputs/diff-test-update/split-whitespace.out "%S/Inputs/diff-test-update/split whitespace.test"
19+
# RUN: diff --strip-trailing-cr %S/Inputs/diff-test-update/split-both.out %S/Inputs/diff-test-update/split-both.test
1820

1921

2022
# CHECK: # update-diff-test: could not deduce source and target from {{.*}}1.in and {{.*}}2.in
2123
# CHECK: # update-diff-test: could not deduce source and target from {{.*}}1.txt and {{.*}}2.txt
2224
# CHECK: # update-diff-test: copied {{.*}}my-file.txt to {{.*}}my-file.expected
2325
# CHECK: # update-diff-test: copied {{.*}}1.txt to {{.*}}empty.txt
2426
# CHECK: # update-diff-test: copied {{.*}}diff-tmp.test.tmp.txt to {{.*}}diff-t-out.txt
25-
# CHECK: # update-diff-test: could not deduce source and target from {{.*}}split-both.expected and {{.*}}split-both.out
2627
# CHECK: # update-diff-test: copied {{.*}}unrelated-split.txt to {{.*}}unrelated-split.expected
2728

2829

0 commit comments

Comments
 (0)