|
1 | 1 | #!/bin/sh |
2 | 2 |
|
3 | 3 | # This is an interdiff(1) testcase. |
4 | | -# Test: Verify that --color option doesn't break context trimming |
5 | | -# |
6 | | -# This test ensures that when interdiff uses the --color option, |
7 | | -# the context trimming functionality (which prevents patch fuzz) |
8 | | -# still works correctly. The test creates a scenario similar to |
9 | | -# the fuzz1 test but with color output enabled. |
10 | | -# |
11 | | -# EXPECTED FAILURE: This test currently fails because interdiff cannot |
12 | | -# parse colored diff output when --color=always produces ANSI escape |
13 | | -# sequences. The test will pass when this bug is fixed. |
| 4 | +# Test: --color option should not break context trimming |
14 | 5 |
|
15 | 6 | . ${top_srcdir-.}/tests/common.sh |
16 | 7 |
|
17 | | -# Create a base file with enough lines to test context trimming |
| 8 | +# Create test files |
18 | 9 | cat << EOF > file |
19 | | -LINE 1 |
20 | | -line 2 |
21 | | -line 3 |
22 | | -line 4 |
23 | | -line 5 |
24 | | -if |
25 | | -1 |
26 | | -fi |
27 | | -if |
28 | | -2 |
29 | | -fi |
30 | | -A |
31 | | -B |
32 | | -C |
33 | | -D |
34 | | -E |
35 | | -F |
| 10 | +line1 |
| 11 | +line2 |
| 12 | +line3 |
| 13 | +line10 |
| 14 | +line11 |
| 15 | +line12 |
36 | 16 | EOF |
37 | 17 |
|
38 | | -# Create first patch: change line 1 to uppercase |
| 18 | +# First patch |
39 | 19 | cat << EOF > patch1 |
40 | 20 | --- file |
41 | 21 | +++ file |
42 | | -@@ -1,4 +1,4 @@ |
43 | | --line 1 |
44 | | -+LINE 1 |
45 | | - line 2 |
46 | | - line 3 |
47 | | - line 4 |
| 22 | +@@ -1,3 +1,3 @@ |
| 23 | + line1 |
| 24 | +-line2 |
| 25 | ++MODIFIED2 |
| 26 | + line3 |
48 | 27 | EOF |
49 | 28 |
|
50 | | -# Create second patch: remove some lines in the middle |
51 | | -# This creates a situation where context trimming is needed |
| 29 | +# Second patch |
52 | 30 | cat << EOF > patch2 |
53 | 31 | --- file |
54 | 32 | +++ file |
55 | | -@@ -5,9 +5,6 @@ |
56 | | - line 5 |
57 | | - if |
58 | | - 1 |
59 | | --fi |
60 | | --if |
61 | | --2 |
62 | | - fi |
63 | | - A |
64 | | - B |
| 33 | +@@ -4,3 +4,3 @@ |
| 34 | + line10 |
| 35 | +-line11 |
| 36 | ++MODIFIED11 |
| 37 | + line12 |
65 | 38 | EOF |
66 | 39 |
|
67 | | -# Test 1: Run interdiff without --color (baseline) |
68 | | -${INTERDIFF} patch1 patch2 2>errors-no-color >patch1-2-no-color |
69 | | -[ -s errors-no-color -o "$?" -gt "0" ] && { cat errors-no-color; exit 1; } |
| 40 | +# Generate interdiff with --color=always |
| 41 | +${INTERDIFF} --color=always patch1 patch2 2>errors >result || { cat errors; exit 1; } |
70 | 42 |
|
71 | | -# Test 2: Run interdiff with --color=never (should be same as baseline) |
72 | | -${INTERDIFF} --color=never patch1 patch2 2>errors-color-never >patch1-2-color-never |
73 | | -[ -s errors-color-never -o "$?" -gt "0" ] && { cat errors-color-never; exit 1; } |
| 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 |
74 | 46 |
|
75 | | -# Test 3: Run interdiff with --color=always (the main test) |
76 | | -# First check if the underlying diff supports --color |
77 | | -if diff --color=always -u /dev/null /dev/null >/dev/null 2>&1; then |
78 | | - ${INTERDIFF} --color=always patch1 patch2 2>errors-color-always >patch1-2-color-always |
79 | | - color_always_exit_code=$? |
80 | | - |
81 | | - # This test should FAIL if interdiff can't handle colored diff output |
82 | | - # The bug is that interdiff fails to parse ANSI color codes in diff output |
83 | | - if [ -s errors-color-always -o "$color_always_exit_code" -gt "0" ]; then |
84 | | - if grep -q "Line not understood" errors-color-always; then |
85 | | - echo "FAIL: interdiff cannot parse colored diff output (--color=always broken)" |
86 | | - echo "ERROR: interdiff fails with 'Line not understood' when diff produces ANSI color codes" |
87 | | - cat errors-color-always |
88 | | - exit 1 |
89 | | - else |
90 | | - echo "ERROR: --color=always failed for unexpected reason" |
91 | | - cat errors-color-always |
92 | | - exit 1 |
93 | | - fi |
94 | | - else |
95 | | - color_always_supported=1 |
96 | | - echo "SUCCESS: --color=always works correctly" |
97 | | - fi |
98 | | -else |
99 | | - # If diff doesn't support --color, skip the color=always test |
100 | | - # but still test that context trimming works with other modes |
101 | | - color_always_supported=0 |
102 | | - echo "SKIP: System diff doesn't support --color, skipping --color=always test" |
103 | | -fi |
104 | | - |
105 | | -# Test 4: Run interdiff with --color (auto mode, should default to never in non-tty) |
106 | | -${INTERDIFF} --color patch1 patch2 2>errors-color-auto >patch1-2-color-auto |
107 | | -[ -s errors-color-auto -o "$?" -gt "0" ] && { cat errors-color-auto; exit 1; } |
108 | | - |
109 | | -# Verify that all generated patches can be applied without fuzz |
110 | | -# This is the critical test - if context trimming is broken, patch will complain about fuzz |
111 | | - |
112 | | -# Test the baseline patch |
113 | | -cp file file-test1 |
114 | | -${PATCH} file-test1 < patch1-2-no-color >patch-errors1 2>&1 || { cat patch-errors1; exit 1; } |
115 | | -if grep -i fuzz patch-errors1; then |
116 | | - echo "ERROR: Baseline patch caused fuzz - context trimming broken" |
117 | | - exit 1 |
118 | | -fi |
119 | | - |
120 | | -# Test the --color=never patch (should be identical to baseline) |
121 | | -cp file file-test2 |
122 | | -${PATCH} file-test2 < patch1-2-color-never >patch-errors2 2>&1 || { cat patch-errors2; exit 1; } |
123 | | -if grep -i fuzz patch-errors2; then |
124 | | - echo "ERROR: --color=never patch caused fuzz" |
125 | | - exit 1 |
126 | | -fi |
127 | | - |
128 | | -# Test the --color=always patch (main test) - only if color is supported and working |
129 | | -if [ "$color_always_supported" = "1" ]; then |
130 | | - cp file file-test3 |
131 | | - ${PATCH} file-test3 < patch1-2-color-always >patch-errors3 2>&1 || { cat patch-errors3; exit 1; } |
132 | | - if grep -i fuzz patch-errors3; then |
133 | | - echo "ERROR: --color=always patch caused fuzz - context trimming broken with color" |
134 | | - exit 1 |
135 | | - fi |
136 | | - echo "SUCCESS: --color=always patch applied without fuzz" |
137 | | -else |
138 | | - echo "SKIP: --color=always patch test skipped (not supported or failed earlier)" |
139 | | -fi |
140 | | - |
141 | | -# Test the --color (auto) patch |
142 | | -cp file file-test4 |
143 | | -${PATCH} file-test4 < patch1-2-color-auto >patch-errors4 2>&1 || { cat patch-errors4; exit 1; } |
144 | | -if grep -i fuzz patch-errors4; then |
145 | | - echo "ERROR: --color (auto) patch caused fuzz" |
146 | | - exit 1 |
147 | | -fi |
148 | | - |
149 | | -# Additional verification: ensure the patches produce the same logical result |
150 | | -# (ignoring ANSI color codes which might be present in the --color=always version) |
151 | | -if [ "$color_always_supported" = "1" ]; then |
152 | | - # Strip ANSI color codes from the color=always output for comparison |
153 | | - sed 's/\x1b\[[0-9;]*m//g' patch1-2-color-always > patch1-2-color-always-stripped |
154 | | - |
155 | | - # Compare the logical content (the never and stripped always should be identical) |
156 | | - if ! cmp patch1-2-color-never patch1-2-color-always-stripped; then |
157 | | - echo "ERROR: --color=always produces different logical output than --color=never" |
158 | | - echo "=== --color=never ===" |
159 | | - cat patch1-2-color-never |
160 | | - echo "=== --color=always (stripped) ===" |
161 | | - cat patch1-2-color-always-stripped |
162 | | - exit 1 |
163 | | - fi |
164 | | -fi |
165 | | - |
166 | | -# Verify that all patched files end up in the same state |
167 | | -if ! cmp file-test1 file-test2; then |
168 | | - echo "ERROR: Different results between no-color and --color=never" |
169 | | - exit 1 |
170 | | -fi |
171 | | - |
172 | | -if [ "$color_always_supported" = "1" ]; then |
173 | | - if ! cmp file-test1 file-test3; then |
174 | | - echo "ERROR: Different results between no-color and --color=always" |
175 | | - exit 1 |
176 | | - fi |
177 | | -fi |
178 | | - |
179 | | -if ! cmp file-test1 file-test4; then |
180 | | - echo "ERROR: Different results between no-color and --color (auto)" |
181 | | - exit 1 |
182 | | -fi |
183 | | - |
184 | | -# If we get here, the core functionality works (--color=never and --color auto work) |
185 | | -# The test only fails if --color=always is broken (which it currently is) |
186 | | -echo "SUCCESS: Context trimming works correctly with supported color modes" |
187 | | -exit 0 |
| 47 | +# Test that the interdiff result can be applied cleanly |
| 48 | +cp file-with-patch1 file-test |
| 49 | +${PATCH} file-test < result || exit 1 |
0 commit comments