|
2 | 2 |
|
3 | 3 | # This is an interdiff(1) testcase. |
4 | 4 | # 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. |
5 | 9 |
|
6 | 10 | . ${top_srcdir-.}/tests/common.sh |
7 | 11 |
|
8 | | -# Create test files |
9 | | -cat << EOF > file |
| 12 | +# Create test files that will generate interdiff output |
| 13 | +cat << EOF > original.txt |
10 | 14 | line1 |
11 | 15 | line2 |
12 | 16 | line3 |
| 17 | +line4 |
| 18 | +line5 |
| 19 | +line6 |
| 20 | +line7 |
| 21 | +line8 |
| 22 | +line9 |
13 | 23 | line10 |
14 | | -line11 |
15 | | -line12 |
16 | 24 | EOF |
17 | 25 |
|
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 @@ |
23 | 31 | 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 |
27 | 44 | EOF |
28 | 45 |
|
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 |
38 | 62 | EOF |
39 | 63 |
|
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 |
42 | 103 |
|
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 |
46 | 113 |
|
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