Skip to content

Commit d353c6f

Browse files
committed
Finally create a working test-case for #119
Assisted-by: Cursor
1 parent 6a23bf4 commit d353c6f

1 file changed

Lines changed: 94 additions & 29 deletions

File tree

tests/interdiff-color-context/run-test

Lines changed: 94 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,113 @@
22

33
# This is an interdiff(1) testcase.
44
# Test: --color option should not break context trimming
5+
#
6+
# The bug: When --color is passed to internal diff, ANSI escape codes
7+
# break trim_context()'s ability to detect and strip "unline" content.
8+
# This test verifies the bug is fixed by ensuring --color doesn't break interdiff.
59

610
. ${top_srcdir-.}/tests/common.sh
711

8-
# Create test files
9-
cat << EOF > file
12+
# Create test files that will generate interdiff output
13+
cat << EOF > original.txt
1014
line1
1115
line2
1216
line3
17+
line4
18+
line5
19+
line6
20+
line7
21+
line8
22+
line9
1323
line10
14-
line11
15-
line12
1624
EOF
1725

18-
# First patch
19-
cat << EOF > patch1
20-
--- file
21-
+++ file
22-
@@ -1,3 +1,3 @@
26+
# Create patches that modify overlapping regions to force interdiff generation
27+
cat << EOF > patch1.patch
28+
--- original.txt
29+
+++ version1.txt
30+
@@ -1,6 +1,6 @@
2331
line1
24-
-line2
25-
+MODIFIED2
26-
line3
32+
line2
33+
-line3
34+
+MODIFIED3
35+
line4
36+
line5
37+
line6
38+
@@ -7,4 +7,4 @@
39+
line7
40+
line8
41+
-line9
42+
+MODIFIED9
43+
line10
2744
EOF
2845

29-
# Second patch
30-
cat << EOF > patch2
31-
--- file
32-
+++ file
33-
@@ -4,3 +4,3 @@
34-
line10
35-
-line11
36-
+MODIFIED11
37-
line12
46+
cat << EOF > patch2.patch
47+
--- original.txt
48+
+++ version2.txt
49+
@@ -2,6 +2,6 @@
50+
line2
51+
line3
52+
line4
53+
-line5
54+
+CHANGED5
55+
line6
56+
line7
57+
@@ -8,3 +8,3 @@
58+
line8
59+
line9
60+
-line10
61+
+CHANGED10
3862
EOF
3963

40-
# Generate interdiff with --color=always
41-
${INTERDIFF} --color=always patch1 patch2 2>errors >result || { cat errors; exit 1; }
64+
# Test the key requirement: --color should not break interdiff functionality
65+
# The original bug would cause interdiff to fail or produce incorrect output
66+
67+
# First, test without color to establish baseline
68+
${INTERDIFF} patch1.patch patch2.patch >baseline.out 2>baseline.err
69+
baseline_exit=$?
70+
71+
# Then test with --color=always
72+
${INTERDIFF} --color=always patch1.patch patch2.patch >color.out 2>color.err
73+
color_exit=$?
74+
75+
# Key test 1: Both should have the same exit status
76+
if [ $baseline_exit -ne $color_exit ]; then
77+
echo "ERROR: --color option changes interdiff exit status"
78+
echo "Baseline exit: $baseline_exit, Color exit: $color_exit"
79+
exit 1
80+
fi
81+
82+
# Key test 2: If baseline succeeded, color version should also produce reasonable output
83+
if [ $baseline_exit -eq 0 ]; then
84+
# Strip ANSI codes from color output for comparison
85+
sed 's/\x1b\[[0-9;]*m//g' color.out > color_stripped.out
86+
87+
# The semantic content should be equivalent
88+
if ! diff baseline.out color_stripped.out >/dev/null 2>&1; then
89+
echo "ERROR: --color option changes interdiff semantic output"
90+
echo "This indicates the color implementation interferes with diff processing"
91+
echo
92+
echo "=== Baseline output ==="
93+
cat baseline.out
94+
echo
95+
echo "=== Color output (stripped) ==="
96+
cat color_stripped.out
97+
echo
98+
echo "=== Difference ==="
99+
diff baseline.out color_stripped.out || true
100+
exit 1
101+
fi
102+
fi
42103

43-
# Apply patch1 to create the base state for testing the interdiff
44-
cp file file-with-patch1
45-
${PATCH} file-with-patch1 < patch1 || exit 1
104+
# Key test 3: The color output should not contain malformed content
105+
# Look for signs that trim_context() failed due to color codes
106+
if grep -E '^\x1b\[[0-9;]*m[!]+' color.out >/dev/null 2>&1; then
107+
echo "ERROR: Found colored unline artifacts in output"
108+
echo "This suggests trim_context() failed to strip artificial content"
109+
echo "Raw output:"
110+
cat -v color.out
111+
exit 1
112+
fi
46113

47-
# Test that the interdiff result can be applied cleanly
48-
cp file-with-patch1 file-test
49-
${PATCH} file-test < result || exit 1
114+
echo "SUCCESS: --color option does not break interdiff context trimming"

0 commit comments

Comments
 (0)