@matheusbsbs / matheus-bagliano / commits / 68cfc6f551
Fork 0

t7508-status: test all modes with color

Move a useful script function to decode colored output to text form from t4034 and use it in this test as well. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael J Gruber committed Dec 8, 2009 at 11:12 UTC 68cfc6f551a02d29a2bc48c6473fad6ab42a476f
3 files changed +156 -44
t/t4034-diff-words.sh
+7 -16
@@ -11,18 +11,9 @@ test_expect_success setup '
11
12 '
13
14 -decrypt_color () {
15 - sed \
16 - -e 's/.\[1m/<WHITE>/g' \
17 - -e 's/.\[31m/<RED>/g' \
18 - -e 's/.\[32m/<GREEN>/g' \
19 - -e 's/.\[36m/<BROWN>/g' \
20 - -e 's/.\[m/<RESET>/g'
21 -}
22 -
14 word_diff () {
15 test_must_fail git diff --no-index "$@" pre post > output &&
25 - decrypt_color < output > output.decrypted &&
16 + test_decode_color <output >output.decrypted &&
17 test_cmp expect output.decrypted
18 }
19
@@ -47,7 +38,7 @@ cat > expect <<\EOF
38 <WHITE>index 330b04f..5ed8eff 100644<RESET>
39 <WHITE>--- a/pre<RESET>
40 <WHITE>+++ b/post<RESET>
50 -<BROWN>@@ -1,3 +1,7 @@<RESET>
41 +<CYAN>@@ -1,3 +1,7 @@<RESET>
42 <RED>h(4)<RESET><GREEN>h(4),hh[44]<RESET>
43 <RESET>
44 a = b + c<RESET>
@@ -68,7 +59,7 @@ cat > expect <<\EOF
59 <WHITE>index 330b04f..5ed8eff 100644<RESET>
60 <WHITE>--- a/pre<RESET>
61 <WHITE>+++ b/post<RESET>
71 -<BROWN>@@ -1,3 +1,7 @@<RESET>
62 +<CYAN>@@ -1,3 +1,7 @@<RESET>
63 h(4),<GREEN>hh<RESET>[44]
64 <RESET>
65 a = b + c<RESET>
@@ -104,7 +95,7 @@ cat > expect <<\EOF
95 <WHITE>index 330b04f..5ed8eff 100644<RESET>
96 <WHITE>--- a/pre<RESET>
97 <WHITE>+++ b/post<RESET>
107 -<BROWN>@@ -1,3 +1,7 @@<RESET>
98 +<CYAN>@@ -1,3 +1,7 @@<RESET>
99 h(4)<GREEN>,hh[44]<RESET>
100 <RESET>
101 a = b + c<RESET>
@@ -146,7 +137,7 @@ cat > expect <<\EOF
137 <WHITE>index 330b04f..5ed8eff 100644<RESET>
138 <WHITE>--- a/pre<RESET>
139 <WHITE>+++ b/post<RESET>
149 -<BROWN>@@ -1,3 +1,7 @@<RESET>
140 +<CYAN>@@ -1,3 +1,7 @@<RESET>
141 h(4),<GREEN>hh[44<RESET>]
142 <RESET>
143 a = b + c<RESET>
@@ -168,7 +159,7 @@ cat > expect <<\EOF
159 <WHITE>index c29453b..be22f37 100644<RESET>
160 <WHITE>--- a/pre<RESET>
161 <WHITE>+++ b/post<RESET>
171 -<BROWN>@@ -1 +1 @@<RESET>
162 +<CYAN>@@ -1 +1 @@<RESET>
163 aaa (aaa) <GREEN>aaa<RESET>
164 EOF
165
@@ -187,7 +178,7 @@ cat > expect <<\EOF
178 <WHITE>index 289cb9d..2d06f37 100644<RESET>
179 <WHITE>--- a/pre<RESET>
180 <WHITE>+++ b/post<RESET>
190 -<BROWN>@@ -1 +1 @@<RESET>
181 +<CYAN>@@ -1 +1 @@<RESET>
182 (<RED>:<RESET>
183 EOF
184
t/t7508-status.sh
+138 -28
@@ -8,26 +8,26 @@ test_description='git status'
8 . ./test-lib.sh
9
10 test_expect_success 'setup' '
11 - : > tracked &&
12 - : > modified &&
11 + : >tracked &&
12 + : >modified &&
13 mkdir dir1 &&
14 - : > dir1/tracked &&
15 - : > dir1/modified &&
14 + : >dir1/tracked &&
15 + : >dir1/modified &&
16 mkdir dir2 &&
17 - : > dir1/tracked &&
18 - : > dir1/modified &&
17 + : >dir1/tracked &&
18 + : >dir1/modified &&
19 git add . &&
20
21 git status >output &&
22
23 test_tick &&
24 git commit -m initial &&
25 - : > untracked &&
26 - : > dir1/untracked &&
27 - : > dir2/untracked &&
28 - echo 1 > dir1/modified &&
29 - echo 2 > dir2/modified &&
30 - echo 3 > dir2/added &&
25 + : >untracked &&
26 + : >dir1/untracked &&
27 + : >dir2/untracked &&
28 + echo 1 >dir1/modified &&
29 + echo 2 >dir2/modified &&
30 + echo 3 >dir2/added &&
31 git add dir2/added
32 '
33
@@ -37,7 +37,7 @@ test_expect_success 'status (1)' '
37
38 '
39
40 -cat > expect << \EOF
40 +cat >expect <<\EOF
41 # On branch master
42 # Changes to be committed:
43 # (use "git reset HEAD <file>..." to unstage)
@@ -63,12 +63,12 @@ EOF
63
64 test_expect_success 'status (2)' '
65
66 - git status > output &&
66 + git status >output &&
67 test_cmp expect output
68
69 '
70
71 -cat > expect << \EOF
71 +cat >expect <<\EOF
72 M dir1/modified
73 A dir2/added
74 ?? dir1/untracked
@@ -81,7 +81,7 @@ EOF
81
82 test_expect_success 'status -s (2)' '
83
84 - git status -s > output &&
84 + git status -s >output &&
85 test_cmp expect output
86
87 '
@@ -103,8 +103,8 @@ cat >expect <<EOF
103 EOF
104 test_expect_success 'status -uno' '
105 mkdir dir3 &&
106 - : > dir3/untracked1 &&
107 - : > dir3/untracked2 &&
106 + : >dir3/untracked1 &&
107 + : >dir3/untracked2 &&
108 git status -uno >output &&
109 test_cmp expect output
110 '
@@ -249,7 +249,7 @@ test_expect_success 'status -s (status.showUntrackedFiles all)' '
249 test_cmp expect output
250 '
251
252 -cat > expect << \EOF
252 +cat >expect <<\EOF
253 # On branch master
254 # Changes to be committed:
255 # (use "git reset HEAD <file>..." to unstage)
@@ -275,12 +275,12 @@ EOF
275
276 test_expect_success 'status with relative paths' '
277
278 - (cd dir1 && git status) > output &&
278 + (cd dir1 && git status) >output &&
279 test_cmp expect output
280
281 '
282
283 -cat > expect << \EOF
283 +cat >expect <<\EOF
284 M modified
285 A ../dir2/added
286 ?? untracked
@@ -292,12 +292,12 @@ A ../dir2/added
292 EOF
293 test_expect_success 'status -s with relative paths' '
294
295 - (cd dir1 && git status -s) > output &&
295 + (cd dir1 && git status -s) >output &&
296 test_cmp expect output
297
298 '
299
300 -cat > expect << \EOF
300 +cat >expect <<\EOF
301 M dir1/modified
302 A dir2/added
303 ?? dir1/untracked
@@ -310,12 +310,121 @@ EOF
310
311 test_expect_success 'status --porcelain ignores relative paths setting' '
312
313 - (cd dir1 && git status --porcelain) > output &&
313 + (cd dir1 && git status --porcelain) >output &&
314 test_cmp expect output
315
316 '
317
318 -cat > expect << \EOF
318 +test_expect_success 'setup unique colors' '
319 +
320 + git config status.color.untracked blue
321 +
322 +'
323 +
324 +cat >expect <<\EOF
325 +# On branch master
326 +# Changes to be committed:
327 +# (use "git reset HEAD <file>..." to unstage)
328 +#
329 +# <GREEN>new file: dir2/added<RESET>
330 +#
331 +# Changed but not updated:
332 +# (use "git add <file>..." to update what will be committed)
333 +# (use "git checkout -- <file>..." to discard changes in working directory)
334 +#
335 +# <RED>modified: dir1/modified<RESET>
336 +#
337 +# Untracked files:
338 +# (use "git add <file>..." to include in what will be committed)
339 +#
340 +# <BLUE>dir1/untracked<RESET>
341 +# <BLUE>dir2/modified<RESET>
342 +# <BLUE>dir2/untracked<RESET>
343 +# <BLUE>expect<RESET>
344 +# <BLUE>output<RESET>
345 +# <BLUE>untracked<RESET>
346 +EOF
347 +
348 +test_expect_success 'status with color.ui' '
349 +
350 + git config color.ui always &&
351 + git status | test_decode_color >output &&
352 + test_cmp expect output
353 +
354 +'
355 +
356 +test_expect_success 'status with color.status' '
357 +
358 + git config --unset color.ui &&
359 + git config color.status always &&
360 + git status | test_decode_color >output &&
361 + test_cmp expect output
362 +
363 +'
364 +
365 +cat >expect <<\EOF
366 + <RED>M<RESET> dir1/modified
367 +<GREEN>A<RESET> dir2/added
368 +<BLUE>??<RESET> dir1/untracked
369 +<BLUE>??<RESET> dir2/modified
370 +<BLUE>??<RESET> dir2/untracked
371 +<BLUE>??<RESET> expect
372 +<BLUE>??<RESET> output
373 +<BLUE>??<RESET> untracked
374 +EOF
375 +
376 +test_expect_success 'status -s with color.ui' '
377 +
378 + git config --unset color.status &&
379 + git config color.ui always &&
380 + git status -s | test_decode_color >output &&
381 + test_cmp expect output
382 +
383 +'
384 +
385 +test_expect_success 'status -s with color.status' '
386 +
387 + git config --unset color.ui &&
388 + git config color.status always &&
389 + git status -s | test_decode_color >output &&
390 + test_cmp expect output
391 +
392 +'
393 +
394 +cat >expect <<\EOF
395 + M dir1/modified
396 +A dir2/added
397 +?? dir1/untracked
398 +?? dir2/modified
399 +?? dir2/untracked
400 +?? expect
401 +?? output
402 +?? untracked
403 +EOF
404 +
405 +test_expect_success 'status --porcelain ignores color.ui' '
406 +
407 + git config --unset color.status &&
408 + git config color.ui always &&
409 + git status --porcelain | test_decode_color >output &&
410 + test_cmp expect output
411 +
412 +'
413 +
414 +test_expect_success 'status --porcelain ignores color.status' '
415 +
416 + git config --unset color.ui &&
417 + git config color.status always &&
418 + git status --porcelain | test_decode_color >output &&
419 + test_cmp expect output
420 +
421 +'
422 +
423 +# recover unconditionally from color tests
424 +git config --unset color.status
425 +git config --unset color.ui
426 +
427 +cat >expect <<\EOF
428 # On branch master
429 # Changes to be committed:
430 # (use "git reset HEAD <file>..." to unstage)
@@ -339,15 +448,16 @@ cat > expect << \EOF
448 # untracked
449 EOF
450
451 +
452 test_expect_success 'status without relative paths' '
453
454 git config status.relativePaths false
345 - (cd dir1 && git status) > output &&
455 + (cd dir1 && git status) >output &&
456 test_cmp expect output
457
458 '
459
350 -cat > expect << \EOF
460 +cat >expect <<\EOF
461 M dir1/modified
462 A dir2/added
463 ?? dir1/untracked
@@ -360,7 +470,7 @@ EOF
470
471 test_expect_success 'status -s without relative paths' '
472
363 - (cd dir1 && git status -s) > output &&
473 + (cd dir1 && git status -s) >output &&
474 test_cmp expect output
475
476 '
t/test-lib.sh
+11
@@ -208,6 +208,17 @@ test_set_editor () {
208 export VISUAL
209 }
210
211 +test_decode_color () {
212 + sed -e 's/.\[1m/<WHITE>/g' \
213 + -e 's/.\[31m/<RED>/g' \
214 + -e 's/.\[32m/<GREEN>/g' \
215 + -e 's/.\[33m/<YELLOW>/g' \
216 + -e 's/.\[34m/<BLUE>/g' \
217 + -e 's/.\[35m/<MAGENTA>/g' \
218 + -e 's/.\[36m/<CYAN>/g' \
219 + -e 's/.\[m/<RESET>/g'
220 +}
221 +
222 test_tick () {
223 if test -z "${test_tick+set}"
224 then