]>
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' | |
7 | . ./test-lib.sh | |
8 | ||
55cccf4b | 9 | ESC=$(printf '\033') |
a0cf49c1 TH |
10 | color() |
11 | { | |
8b124135 | 12 | actual=$(git config --get-color no.such.slot "$1") && |
55cccf4b | 13 | test "$actual" = "${2:+$ESC}$2" |
a0cf49c1 TH |
14 | } |
15 | ||
16 | invalid_color() | |
17 | { | |
8b124135 | 18 | test_must_fail git config --get-color no.such.slot "$1" |
a0cf49c1 TH |
19 | } |
20 | ||
21 | test_expect_success 'reset' ' | |
22 | color "reset" "[m" | |
23 | ' | |
24 | ||
55cccf4b JK |
25 | test_expect_success 'empty color is empty' ' |
26 | color "" "" | |
27 | ' | |
28 | ||
a0cf49c1 TH |
29 | test_expect_success 'attribute before color name' ' |
30 | color "bold red" "[1;31m" | |
31 | ' | |
32 | ||
1751b09a ES |
33 | test_expect_success 'aixterm bright fg color' ' |
34 | color "brightred" "[91m" | |
35 | ' | |
36 | ||
37 | test_expect_success 'aixterm bright bg color' ' | |
38 | color "green brightblue" "[32;104m" | |
39 | ' | |
40 | ||
a0cf49c1 TH |
41 | test_expect_success 'color name before attribute' ' |
42 | color "red bold" "[1;31m" | |
43 | ' | |
44 | ||
45 | test_expect_success 'attr fg bg' ' | |
46 | color "ul blue red" "[4;34;41m" | |
47 | ' | |
48 | ||
49 | test_expect_success 'fg attr bg' ' | |
50 | color "blue ul red" "[4;34;41m" | |
51 | ' | |
52 | ||
53 | test_expect_success 'fg bg attr' ' | |
54 | color "blue red ul" "[4;34;41m" | |
55 | ' | |
56 | ||
8b124135 JH |
57 | test_expect_success 'fg bg attr...' ' |
58 | color "blue bold dim ul blink reverse" "[1;2;4;5;7;34m" | |
59 | ' | |
60 | ||
ff40d185 JK |
61 | # note that nobold and nodim are the same code (22) |
62 | test_expect_success 'attr negation' ' | |
63 | color "nobold nodim noul noblink noreverse" "[22;24;25;27m" | |
64 | ' | |
65 | ||
5621068f JK |
66 | test_expect_success '"no-" variant of negation' ' |
67 | color "no-bold no-blink" "[22;25m" | |
68 | ' | |
69 | ||
8b124135 JH |
70 | test_expect_success 'long color specification' ' |
71 | color "254 255 bold dim ul blink reverse" "[1;2;4;5;7;38;5;254;48;5;255m" | |
72 | ' | |
73 | ||
ff40d185 JK |
74 | test_expect_success 'absurdly long color specification' ' |
75 | color \ | |
54590a0e | 76 | "#ffffff #ffffff bold nobold dim nodim italic noitalic |
9dc3515c JK |
77 | ul noul blink noblink reverse noreverse strike nostrike" \ |
78 | "[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 |
79 | ' |
80 | ||
3759d27a JK |
81 | test_expect_success '0-7 are aliases for basic ANSI color names' ' |
82 | color "0 7" "[30;47m" | |
83 | ' | |
84 | ||
c444f032 ES |
85 | test_expect_success '8-15 are aliases for aixterm color names' ' |
86 | color "12 13" "[94;105m" | |
87 | ' | |
88 | ||
a0cf49c1 TH |
89 | test_expect_success '256 colors' ' |
90 | color "254 bold 255" "[1;38;5;254;48;5;255m" | |
91 | ' | |
92 | ||
17a4be26 JK |
93 | test_expect_success '24-bit colors' ' |
94 | color "#ff00ff black" "[38;2;255;0;255;40m" | |
95 | ' | |
96 | ||
cb357221 JK |
97 | test_expect_success '"normal" yields no color at all"' ' |
98 | color "normal black" "[40m" | |
99 | ' | |
100 | ||
101 | test_expect_success '-1 is a synonym for "normal"' ' | |
102 | color "-1 black" "[40m" | |
103 | ' | |
104 | ||
a0cf49c1 TH |
105 | test_expect_success 'color too small' ' |
106 | invalid_color "-2" | |
107 | ' | |
108 | ||
109 | test_expect_success 'color too big' ' | |
110 | invalid_color "256" | |
111 | ' | |
112 | ||
113 | test_expect_success 'extra character after color number' ' | |
114 | invalid_color "3X" | |
115 | ' | |
116 | ||
117 | test_expect_success 'extra character after color name' ' | |
118 | invalid_color "redX" | |
119 | ' | |
120 | ||
121 | test_expect_success 'extra character after attribute' ' | |
122 | invalid_color "dimX" | |
123 | ' | |
124 | ||
8b8e8624 | 125 | test_expect_success 'unknown color slots are ignored (diff)' ' |
8b8e8624 JK |
126 | git config color.diff.nosuchslotwilleverbedefined white && |
127 | git diff --color | |
128 | ' | |
129 | ||
130 | test_expect_success 'unknown color slots are ignored (branch)' ' | |
131 | git config color.branch.nosuchslotwilleverbedefined white && | |
132 | git branch -a | |
133 | ' | |
134 | ||
135 | test_expect_success 'unknown color slots are ignored (status)' ' | |
9ddc5ac9 JK |
136 | git config color.status.nosuchslotwilleverbedefined white && |
137 | { git status; ret=$?; } && | |
138 | case $ret in 0|1) : ok ;; *) false ;; esac | |
8b8e8624 JK |
139 | ' |
140 | ||
a0cf49c1 | 141 | test_done |