]>
Commit | Line | Data |
---|---|---|
a0cf49c1 TH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2008 Timo Hirvonen | |
4 | # | |
5 | ||
6 | test_description='Test diff/status color escape codes' | |
288a4806 ÆAB |
7 | |
8 | TEST_PASSES_SANITIZE_LEAK=true | |
a0cf49c1 TH |
9 | . ./test-lib.sh |
10 | ||
55cccf4b | 11 | ESC=$(printf '\033') |
a0cf49c1 TH |
12 | color() |
13 | { | |
8b124135 | 14 | actual=$(git config --get-color no.such.slot "$1") && |
55cccf4b | 15 | test "$actual" = "${2:+$ESC}$2" |
a0cf49c1 TH |
16 | } |
17 | ||
18 | invalid_color() | |
19 | { | |
8b124135 | 20 | test_must_fail git config --get-color no.such.slot "$1" |
a0cf49c1 TH |
21 | } |
22 | ||
23 | test_expect_success 'reset' ' | |
24 | color "reset" "[m" | |
25 | ' | |
26 | ||
55cccf4b JK |
27 | test_expect_success 'empty color is empty' ' |
28 | color "" "" | |
29 | ' | |
30 | ||
a0cf49c1 TH |
31 | test_expect_success 'attribute before color name' ' |
32 | color "bold red" "[1;31m" | |
33 | ' | |
34 | ||
1751b09a ES |
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 | ||
a0cf49c1 TH |
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 | ||
8b124135 JH |
59 | test_expect_success 'fg bg attr...' ' |
60 | color "blue bold dim ul blink reverse" "[1;2;4;5;7;34m" | |
61 | ' | |
62 | ||
de658515 RE |
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 | ||
ff40d185 JK |
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 | ||
5621068f JK |
72 | test_expect_success '"no-" variant of negation' ' |
73 | color "no-bold no-blink" "[22;25m" | |
74 | ' | |
75 | ||
8b124135 JH |
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 | ||
ff40d185 JK |
80 | test_expect_success 'absurdly long color specification' ' |
81 | color \ | |
54590a0e | 82 | "#ffffff #ffffff bold nobold dim nodim italic noitalic |
9dc3515c JK |
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" | |
ff40d185 JK |
85 | ' |
86 | ||
3759d27a JK |
87 | test_expect_success '0-7 are aliases for basic ANSI color names' ' |
88 | color "0 7" "[30;47m" | |
89 | ' | |
90 | ||
c444f032 ES |
91 | test_expect_success '8-15 are aliases for aixterm color names' ' |
92 | color "12 13" "[94;105m" | |
93 | ' | |
94 | ||
a0cf49c1 TH |
95 | test_expect_success '256 colors' ' |
96 | color "254 bold 255" "[1;38;5;254;48;5;255m" | |
97 | ' | |
98 | ||
17a4be26 JK |
99 | test_expect_success '24-bit colors' ' |
100 | color "#ff00ff black" "[38;2;255;0;255;40m" | |
101 | ' | |
102 | ||
05f1f41c RE |
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 | ||
cb357221 JK |
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 | ||
a0cf49c1 TH |
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 | ||
8b8e8624 | 143 | test_expect_success 'unknown color slots are ignored (diff)' ' |
8b8e8624 JK |
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)' ' | |
9ddc5ac9 JK |
154 | git config color.status.nosuchslotwilleverbedefined white && |
155 | { git status; ret=$?; } && | |
156 | case $ret in 0|1) : ok ;; *) false ;; esac | |
8b8e8624 JK |
157 | ' |
158 | ||
a0cf49c1 | 159 | test_done |