1#!/bin/sh
2#
3# Copyright (c) 2008 Timo Hirvonen
4#
5
6test_description='Test diff/status color escape codes'
7. ./test-lib.sh
8
9color()
10{
11 git config diff.color.new "$1" &&
12 test "`git config --get-color diff.color.new`" = "\e$2"
13}
14
15invalid_color()
16{
17 git config diff.color.new "$1" &&
18 test -z "`git config --get-color diff.color.new 2>/dev/null`"
19}
20
21test_expect_success 'reset' '
22 color "reset" "[m"
23'
24
25test_expect_success 'attribute before color name' '
26 color "bold red" "[1;31m"
27'
28
29test_expect_success 'color name before attribute' '
30 color "red bold" "[1;31m"
31'
32
33test_expect_success 'attr fg bg' '
34 color "ul blue red" "[4;34;41m"
35'
36
37test_expect_success 'fg attr bg' '
38 color "blue ul red" "[4;34;41m"
39'
40
41test_expect_success 'fg bg attr' '
42 color "blue red ul" "[4;34;41m"
43'
44
45test_expect_success '256 colors' '
46 color "254 bold 255" "[1;38;5;254;48;5;255m"
47'
48
49test_expect_success 'color too small' '
50 invalid_color "-2"
51'
52
53test_expect_success 'color too big' '
54 invalid_color "256"
55'
56
57test_expect_success 'extra character after color number' '
58 invalid_color "3X"
59'
60
61test_expect_success 'extra character after color name' '
62 invalid_color "redX"
63'
64
65test_expect_success 'extra character after attribute' '
66 invalid_color "dimX"
67'
68
69test_expect_success 'unknown color slots are ignored (diff)' '
70 git config --unset diff.color.new
71 git config color.diff.nosuchslotwilleverbedefined white &&
72 git diff --color
73'
74
75test_expect_success 'unknown color slots are ignored (branch)' '
76 git config color.branch.nosuchslotwilleverbedefined white &&
77 git branch -a
78'
79
80test_expect_success 'unknown color slots are ignored (status)' '
81 git config color.status.nosuchslotwilleverbedefined white || exit
82 git status
83 case $? in 0|1) : ok ;; *) false ;; esac
84'
85
86test_done