diff-highlight: use test_decode_color in tests

The diff-highlight tests use raw color bytes when comparing expected and actual output. Let's use test_decode_color, which is our usual technique in other tests. It makes reading test output diffs a bit easier, since you're not relying on your terminal to interpret the result (or worse, interpreting characters yourself via "cat -A"). This will also make it easier to add tests with new colors/attributes, without having to pre-define the byte sequences ourselves. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 23, 2026 at 02:02 UTC e57daf91ed0bde19595543c68c90948d5c47ebc6
1 file changed +17 -20
contrib/diff-highlight/t/t9400-diff-highlight.sh
+17 -20
@@ -7,9 +7,6 @@ TEST_OUTPUT_DIRECTORY=$(pwd)
7 TEST_DIRECTORY="$CURR_DIR"/../../../t
8 DIFF_HIGHLIGHT="$CURR_DIR"/../diff-highlight
9
10 -CW="$(printf "\033[7m")" # white
11 -CR="$(printf "\033[27m")" # reset
12 -
10 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
11 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12 . "$TEST_DIRECTORY"/test-lib.sh
@@ -42,9 +39,9 @@ dh_test () {
39 } >/dev/null &&
40
41 "$DIFF_HIGHLIGHT" <diff.raw >diff.hi &&
45 - test_strip_patch_header <diff.hi >diff.act &&
42 + test_strip_patch_header <diff.hi | test_decode_color >diff.act &&
43 "$DIFF_HIGHLIGHT" <commit.raw >commit.hi &&
47 - test_strip_patch_header <commit.hi >commit.act &&
44 + test_strip_patch_header <commit.hi | test_decode_color >commit.act &&
45 test_cmp patch.exp diff.act &&
46 test_cmp patch.exp commit.act
47 }
@@ -126,8 +123,8 @@ test_expect_success 'diff-highlight highlights the beginning of a line' '
123 dh_test a b <<-EOF
124 @@ -1,3 +1,3 @@
125 aaa
129 - -${CW}b${CR}bb
130 - +${CW}0${CR}bb
126 + -<REVERSE>b<NOREVERSE>bb
127 + +<REVERSE>0<NOREVERSE>bb
128 ccc
129 EOF
130 '
@@ -148,8 +145,8 @@ test_expect_success 'diff-highlight highlights the end of a line' '
145 dh_test a b <<-EOF
146 @@ -1,3 +1,3 @@
147 aaa
151 - -bb${CW}b${CR}
152 - +bb${CW}0${CR}
148 + -bb<REVERSE>b<NOREVERSE>
149 + +bb<REVERSE>0<NOREVERSE>
150 ccc
151 EOF
152 '
@@ -170,8 +167,8 @@ test_expect_success 'diff-highlight highlights the middle of a line' '
167 dh_test a b <<-EOF
168 @@ -1,3 +1,3 @@
169 aaa
173 - -b${CW}b${CR}b
174 - +b${CW}0${CR}b
170 + -b<REVERSE>b<NOREVERSE>b
171 + +b<REVERSE>0<NOREVERSE>b
172 ccc
173 EOF
174 '
@@ -213,8 +210,8 @@ test_expect_failure 'diff-highlight highlights mismatched hunk size' '
210 dh_test a b <<-EOF
211 @@ -1,3 +1,3 @@
212 aaa
216 - -b${CW}b${CR}b
217 - +b${CW}0${CR}b
213 + -b<REVERSE>b<NOREVERSE>b
214 + +b<REVERSE>0<NOREVERSE>b
215 +ccc
216 EOF
217 '
@@ -232,8 +229,8 @@ test_expect_success 'diff-highlight treats multibyte utf-8 as a unit' '
229 echo "unic${o_stroke}de" >b &&
230 dh_test a b <<-EOF
231 @@ -1 +1 @@
235 - -unic${CW}${o_accent}${CR}de
236 - +unic${CW}${o_stroke}${CR}de
232 + -unic<REVERSE>${o_accent}<NOREVERSE>de
233 + +unic<REVERSE>${o_stroke}<NOREVERSE>de
234 EOF
235 '
236
@@ -250,8 +247,8 @@ test_expect_failure 'diff-highlight treats combining code points as a unit' '
247 echo "unico${combine_circum}de" >b &&
248 dh_test a b <<-EOF
249 @@ -1 +1 @@
253 - -unic${CW}o${combine_accent}${CR}de
254 - +unic${CW}o${combine_circum}${CR}de
250 + -unic<REVERSE>o${combine_accent}<NOREVERSE>de
251 + +unic<REVERSE>o${combine_circum}<NOREVERSE>de
252 EOF
253 '
254
@@ -333,12 +330,12 @@ test_expect_success 'diff-highlight handles --graph with leading dash' '
330 +++ b/file
331 @@ -1,3 +1,3 @@
332 before
336 - -the ${CW}old${CR} line
337 - +the ${CW}new${CR} line
333 + -the <REVERSE>old<NOREVERSE> line
334 + +the <REVERSE>new<NOREVERSE> line
335 -leading dash
336 EOF
337 git log --graph -p -1 | "$DIFF_HIGHLIGHT" >actual.raw &&
341 - trim_graph <actual.raw | sed -n "/^---/,\$p" >actual &&
338 + trim_graph <actual.raw | sed -n "/^---/,\$p" | test_decode_color >actual &&
339 test_cmp expect actual
340 '
341