| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# This is an interdiff(1) testcase. |
| 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. |
| 9 |
|
| 10 |
. ${top_srcdir-.}/tests/common.sh |
| 11 |
|
| 12 |
# Create test files that will generate interdiff output |
| 13 |
cat << EOF > original.txt |
| 14 |
line1 |
| 15 |
line2 |
| 16 |
line3 |
| 17 |
line4 |
| 18 |
line5 |
| 19 |
line6 |
| 20 |
line7 |
| 21 |
line8 |
| 22 |
line9 |
| 23 |
line10 |
| 24 |
EOF |
| 25 |
|
| 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 @@ |
| 31 |
line1 |
| 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 |
| 44 |
EOF |
| 45 |
|
| 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 |
| 62 |
EOF |
| 63 |
|
| 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 |
| 103 |
|
| 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 |
| 113 |
|
| 114 |
echo "SUCCESS: --color option does not break interdiff context trimming" |