]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4026-color.sh
Merge branch 'ds/typofix-core-config-doc'
[thirdparty/git.git] / t / t4026-color.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2008 Timo Hirvonen
4 #
5
6 test_description='Test diff/status color escape codes'
7
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 ESC=$(printf '\033')
12 color()
13 {
14 actual=$(git config --get-color no.such.slot "$1") &&
15 test "$actual" = "${2:+$ESC}$2"
16 }
17
18 invalid_color()
19 {
20 test_must_fail git config --get-color no.such.slot "$1"
21 }
22
23 test_expect_success 'reset' '
24 color "reset" "[m"
25 '
26
27 test_expect_success 'empty color is empty' '
28 color "" ""
29 '
30
31 test_expect_success 'attribute before color name' '
32 color "bold red" "[1;31m"
33 '
34
35 test_expect_success 'aixterm bright fg color' '
36 color "brightred" "[91m"
37 '
38
39 test_expect_success 'aixterm bright bg color' '
40 color "green brightblue" "[32;104m"
41 '
42
43 test_expect_success 'color name before attribute' '
44 color "red bold" "[1;31m"
45 '
46
47 test_expect_success 'attr fg bg' '
48 color "ul blue red" "[4;34;41m"
49 '
50
51 test_expect_success 'fg attr bg' '
52 color "blue ul red" "[4;34;41m"
53 '
54
55 test_expect_success 'fg bg attr' '
56 color "blue red ul" "[4;34;41m"
57 '
58
59 test_expect_success 'fg bg attr...' '
60 color "blue bold dim ul blink reverse" "[1;2;4;5;7;34m"
61 '
62
63 test_expect_success 'reset fg bg attr...' '
64 color "reset blue bold dim ul blink reverse" "[;1;2;4;5;7;34m"
65 '
66
67 # note that nobold and nodim are the same code (22)
68 test_expect_success 'attr negation' '
69 color "nobold nodim noul noblink noreverse" "[22;24;25;27m"
70 '
71
72 test_expect_success '"no-" variant of negation' '
73 color "no-bold no-blink" "[22;25m"
74 '
75
76 test_expect_success 'long color specification' '
77 color "254 255 bold dim ul blink reverse" "[1;2;4;5;7;38;5;254;48;5;255m"
78 '
79
80 test_expect_success 'absurdly long color specification' '
81 color \
82 "#ffffff #ffffff bold nobold dim nodim italic noitalic
83 ul noul blink noblink reverse noreverse strike nostrike" \
84 "[1;2;3;4;5;7;9;22;23;24;25;27;29;38;2;255;255;255;48;2;255;255;255m"
85 '
86
87 test_expect_success '0-7 are aliases for basic ANSI color names' '
88 color "0 7" "[30;47m"
89 '
90
91 test_expect_success '8-15 are aliases for aixterm color names' '
92 color "12 13" "[94;105m"
93 '
94
95 test_expect_success '256 colors' '
96 color "254 bold 255" "[1;38;5;254;48;5;255m"
97 '
98
99 test_expect_success '24-bit colors' '
100 color "#ff00ff black" "[38;2;255;0;255;40m"
101 '
102
103 test_expect_success '"default" foreground' '
104 color "default" "[39m"
105 '
106
107 test_expect_success '"normal default" to clear background' '
108 color "normal default" "[49m"
109 '
110
111 test_expect_success '"default" can be combined with attributes' '
112 color "default default no-reverse bold" "[1;27;39;49m"
113 '
114
115 test_expect_success '"normal" yields no color at all"' '
116 color "normal black" "[40m"
117 '
118
119 test_expect_success '-1 is a synonym for "normal"' '
120 color "-1 black" "[40m"
121 '
122
123 test_expect_success 'color too small' '
124 invalid_color "-2"
125 '
126
127 test_expect_success 'color too big' '
128 invalid_color "256"
129 '
130
131 test_expect_success 'extra character after color number' '
132 invalid_color "3X"
133 '
134
135 test_expect_success 'extra character after color name' '
136 invalid_color "redX"
137 '
138
139 test_expect_success 'extra character after attribute' '
140 invalid_color "dimX"
141 '
142
143 test_expect_success 'unknown color slots are ignored (diff)' '
144 git config color.diff.nosuchslotwilleverbedefined white &&
145 git diff --color
146 '
147
148 test_expect_success 'unknown color slots are ignored (branch)' '
149 git config color.branch.nosuchslotwilleverbedefined white &&
150 git branch -a
151 '
152
153 test_expect_success 'unknown color slots are ignored (status)' '
154 git config color.status.nosuchslotwilleverbedefined white &&
155 { git status; ret=$?; } &&
156 case $ret in 0|1) : ok ;; *) false ;; esac
157 '
158
159 test_done