Merge branch 'mm/pull-upload-pack' into maint
[git/git-svn.git] / t / t4026-color.sh
blob2b32c4fbe67d9dc0a43fc7858ddd3ac400b6171f
1 #!/bin/sh
3 # Copyright (c) 2008 Timo Hirvonen
6 test_description='Test diff/status color escape codes'
7 . ./test-lib.sh
9 color()
11 actual=$(git config --get-color no.such.slot "$1") &&
12 test "$actual" = "\e$2"
15 invalid_color()
17 test_must_fail git config --get-color no.such.slot "$1"
20 test_expect_success 'reset' '
21 color "reset" "[m"
24 test_expect_success 'attribute before color name' '
25 color "bold red" "[1;31m"
28 test_expect_success 'color name before attribute' '
29 color "red bold" "[1;31m"
32 test_expect_success 'attr fg bg' '
33 color "ul blue red" "[4;34;41m"
36 test_expect_success 'fg attr bg' '
37 color "blue ul red" "[4;34;41m"
40 test_expect_success 'fg bg attr' '
41 color "blue red ul" "[4;34;41m"
44 test_expect_success 'fg bg attr...' '
45 color "blue bold dim ul blink reverse" "[1;2;4;5;7;34m"
48 # note that nobold and nodim are the same code (22)
49 test_expect_success 'attr negation' '
50 color "nobold nodim noul noblink noreverse" "[22;24;25;27m"
53 test_expect_success 'long color specification' '
54 color "254 255 bold dim ul blink reverse" "[1;2;4;5;7;38;5;254;48;5;255m"
57 test_expect_success 'absurdly long color specification' '
58 color \
59 "#ffffff #ffffff bold nobold dim nodim ul noul blink noblink reverse noreverse" \
60 "[1;2;4;5;7;22;24;25;27;38;2;255;255;255;48;2;255;255;255m"
63 test_expect_success '0-7 are aliases for basic ANSI color names' '
64 color "0 7" "[30;47m"
67 test_expect_success '256 colors' '
68 color "254 bold 255" "[1;38;5;254;48;5;255m"
71 test_expect_success '24-bit colors' '
72 color "#ff00ff black" "[38;2;255;0;255;40m"
75 test_expect_success '"normal" yields no color at all"' '
76 color "normal black" "[40m"
79 test_expect_success '-1 is a synonym for "normal"' '
80 color "-1 black" "[40m"
83 test_expect_success 'color too small' '
84 invalid_color "-2"
87 test_expect_success 'color too big' '
88 invalid_color "256"
91 test_expect_success 'extra character after color number' '
92 invalid_color "3X"
95 test_expect_success 'extra character after color name' '
96 invalid_color "redX"
99 test_expect_success 'extra character after attribute' '
100 invalid_color "dimX"
103 test_expect_success 'unknown color slots are ignored (diff)' '
104 git config color.diff.nosuchslotwilleverbedefined white &&
105 git diff --color
108 test_expect_success 'unknown color slots are ignored (branch)' '
109 git config color.branch.nosuchslotwilleverbedefined white &&
110 git branch -a
113 test_expect_success 'unknown color slots are ignored (status)' '
114 git config color.status.nosuchslotwilleverbedefined white &&
115 { git status; ret=$?; } &&
116 case $ret in 0|1) : ok ;; *) false ;; esac
119 test_done