Skip to content

Commit e57daf9

Browse files
peffgitster
authored andcommitted
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>
1 parent 0c49b95 commit e57daf9

1 file changed

Lines changed: 17 additions & 20 deletions

File tree

contrib/diff-highlight/t/t9400-diff-highlight.sh

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ TEST_OUTPUT_DIRECTORY=$(pwd)
77
TEST_DIRECTORY="$CURR_DIR"/../../../t
88
DIFF_HIGHLIGHT="$CURR_DIR"/../diff-highlight
99

10-
CW="$(printf "\033[7m")" # white
11-
CR="$(printf "\033[27m")" # reset
12-
1310
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
1411
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1512
. "$TEST_DIRECTORY"/test-lib.sh
@@ -42,9 +39,9 @@ dh_test () {
4239
} >/dev/null &&
4340

4441
"$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 &&
4643
"$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 &&
4845
test_cmp patch.exp diff.act &&
4946
test_cmp patch.exp commit.act
5047
}
@@ -126,8 +123,8 @@ test_expect_success 'diff-highlight highlights the beginning of a line' '
126123
dh_test a b <<-EOF
127124
@@ -1,3 +1,3 @@
128125
aaa
129-
-${CW}b${CR}bb
130-
+${CW}0${CR}bb
126+
-<REVERSE>b<NOREVERSE>bb
127+
+<REVERSE>0<NOREVERSE>bb
131128
ccc
132129
EOF
133130
'
@@ -148,8 +145,8 @@ test_expect_success 'diff-highlight highlights the end of a line' '
148145
dh_test a b <<-EOF
149146
@@ -1,3 +1,3 @@
150147
aaa
151-
-bb${CW}b${CR}
152-
+bb${CW}0${CR}
148+
-bb<REVERSE>b<NOREVERSE>
149+
+bb<REVERSE>0<NOREVERSE>
153150
ccc
154151
EOF
155152
'
@@ -170,8 +167,8 @@ test_expect_success 'diff-highlight highlights the middle of a line' '
170167
dh_test a b <<-EOF
171168
@@ -1,3 +1,3 @@
172169
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
175172
ccc
176173
EOF
177174
'
@@ -213,8 +210,8 @@ test_expect_failure 'diff-highlight highlights mismatched hunk size' '
213210
dh_test a b <<-EOF
214211
@@ -1,3 +1,3 @@
215212
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
218215
+ccc
219216
EOF
220217
'
@@ -232,8 +229,8 @@ test_expect_success 'diff-highlight treats multibyte utf-8 as a unit' '
232229
echo "unic${o_stroke}de" >b &&
233230
dh_test a b <<-EOF
234231
@@ -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
237234
EOF
238235
'
239236

@@ -250,8 +247,8 @@ test_expect_failure 'diff-highlight treats combining code points as a unit' '
250247
echo "unico${combine_circum}de" >b &&
251248
dh_test a b <<-EOF
252249
@@ -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
255252
EOF
256253
'
257254

@@ -333,12 +330,12 @@ test_expect_success 'diff-highlight handles --graph with leading dash' '
333330
+++ b/file
334331
@@ -1,3 +1,3 @@
335332
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
338335
-leading dash
339336
EOF
340337
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 &&
342339
test_cmp expect actual
343340
'
344341

0 commit comments

Comments
 (0)