chainlint.sed: drop subshell-closing ">" annotation
[git/debian.git] / t / t4026-color.sh
blobcc73161b466b56615e969685f874130af951ddfd
1 #!/bin/sh
3 # Copyright (c) 2008 Timo Hirvonen
6 test_description='Test diff/status color escape codes'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 ESC=$(printf '\033')
12 color()
14 actual=$(git config --get-color no.such.slot "$1") &&
15 test "$actual" = "${2:+$ESC}$2"
18 invalid_color()
20 test_must_fail git config --get-color no.such.slot "$1"
23 test_expect_success 'reset' '
24 color "reset" "[m"
27 test_expect_success 'empty color is empty' '
28 color "" ""
31 test_expect_success 'attribute before color name' '
32 color "bold red" "[1;31m"
35 test_expect_success 'aixterm bright fg color' '
36 color "brightred" "[91m"
39 test_expect_success 'aixterm bright bg color' '
40 color "green brightblue" "[32;104m"
43 test_expect_success 'color name before attribute' '
44 color "red bold" "[1;31m"
47 test_expect_success 'attr fg bg' '
48 color "ul blue red" "[4;34;41m"
51 test_expect_success 'fg attr bg' '
52 color "blue ul red" "[4;34;41m"
55 test_expect_success 'fg bg attr' '
56 color "blue red ul" "[4;34;41m"
59 test_expect_success 'fg bg attr...' '
60 color "blue bold dim ul blink reverse" "[1;2;4;5;7;34m"
63 # note that nobold and nodim are the same code (22)
64 test_expect_success 'attr negation' '
65 color "nobold nodim noul noblink noreverse" "[22;24;25;27m"
68 test_expect_success '"no-" variant of negation' '
69 color "no-bold no-blink" "[22;25m"
72 test_expect_success 'long color specification' '
73 color "254 255 bold dim ul blink reverse" "[1;2;4;5;7;38;5;254;48;5;255m"
76 test_expect_success 'absurdly long color specification' '
77 color \
78 "#ffffff #ffffff bold nobold dim nodim italic noitalic
79 ul noul blink noblink reverse noreverse strike nostrike" \
80 "[1;2;3;4;5;7;9;22;23;24;25;27;29;38;2;255;255;255;48;2;255;255;255m"
83 test_expect_success '0-7 are aliases for basic ANSI color names' '
84 color "0 7" "[30;47m"
87 test_expect_success '8-15 are aliases for aixterm color names' '
88 color "12 13" "[94;105m"
91 test_expect_success '256 colors' '
92 color "254 bold 255" "[1;38;5;254;48;5;255m"
95 test_expect_success '24-bit colors' '
96 color "#ff00ff black" "[38;2;255;0;255;40m"
99 test_expect_success '"normal" yields no color at all"' '
100 color "normal black" "[40m"
103 test_expect_success '-1 is a synonym for "normal"' '
104 color "-1 black" "[40m"
107 test_expect_success 'color too small' '
108 invalid_color "-2"
111 test_expect_success 'color too big' '
112 invalid_color "256"
115 test_expect_success 'extra character after color number' '
116 invalid_color "3X"
119 test_expect_success 'extra character after color name' '
120 invalid_color "redX"
123 test_expect_success 'extra character after attribute' '
124 invalid_color "dimX"
127 test_expect_success 'unknown color slots are ignored (diff)' '
128 git config color.diff.nosuchslotwilleverbedefined white &&
129 git diff --color
132 test_expect_success 'unknown color slots are ignored (branch)' '
133 git config color.branch.nosuchslotwilleverbedefined white &&
134 git branch -a
137 test_expect_success 'unknown color slots are ignored (status)' '
138 git config color.status.nosuchslotwilleverbedefined white &&
139 { git status; ret=$?; } &&
140 case $ret in 0|1) : ok ;; *) false ;; esac
143 test_done