Timo Hirvonen | a0cf49c | 2008-02-06 14:16:08 +0200 | [diff] [blame] | 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 | |
Jeff King | 55cccf4 | 2017-02-01 01:21:29 +0100 | [diff] [blame] | 9 | ESC=$(printf '\033') |
Timo Hirvonen | a0cf49c | 2008-02-06 14:16:08 +0200 | [diff] [blame] | 10 | color() |
| 11 | { |
Junio C Hamano | 8b12413 | 2010-02-27 18:56:38 -0800 | [diff] [blame] | 12 | actual=$(git config --get-color no.such.slot "$1") && |
Jeff King | 55cccf4 | 2017-02-01 01:21:29 +0100 | [diff] [blame] | 13 | test "$actual" = "${2:+$ESC}$2" |
Timo Hirvonen | a0cf49c | 2008-02-06 14:16:08 +0200 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | invalid_color() |
| 17 | { |
Junio C Hamano | 8b12413 | 2010-02-27 18:56:38 -0800 | [diff] [blame] | 18 | test_must_fail git config --get-color no.such.slot "$1" |
Timo Hirvonen | a0cf49c | 2008-02-06 14:16:08 +0200 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | test_expect_success 'reset' ' |
| 22 | color "reset" "[m" |
| 23 | ' |
| 24 | |
Jeff King | 55cccf4 | 2017-02-01 01:21:29 +0100 | [diff] [blame] | 25 | test_expect_success 'empty color is empty' ' |
| 26 | color "" "" |
| 27 | ' |
| 28 | |
Timo Hirvonen | a0cf49c | 2008-02-06 14:16:08 +0200 | [diff] [blame] | 29 | test_expect_success 'attribute before color name' ' |
| 30 | color "bold red" "[1;31m" |
| 31 | ' |
| 32 | |
| 33 | test_expect_success 'color name before attribute' ' |
| 34 | color "red bold" "[1;31m" |
| 35 | ' |
| 36 | |
| 37 | test_expect_success 'attr fg bg' ' |
| 38 | color "ul blue red" "[4;34;41m" |
| 39 | ' |
| 40 | |
| 41 | test_expect_success 'fg attr bg' ' |
| 42 | color "blue ul red" "[4;34;41m" |
| 43 | ' |
| 44 | |
| 45 | test_expect_success 'fg bg attr' ' |
| 46 | color "blue red ul" "[4;34;41m" |
| 47 | ' |
| 48 | |
Junio C Hamano | 8b12413 | 2010-02-27 18:56:38 -0800 | [diff] [blame] | 49 | test_expect_success 'fg bg attr...' ' |
| 50 | color "blue bold dim ul blink reverse" "[1;2;4;5;7;34m" |
| 51 | ' |
| 52 | |
Jeff King | ff40d18 | 2014-11-20 10:25:52 -0500 | [diff] [blame] | 53 | # note that nobold and nodim are the same code (22) |
| 54 | test_expect_success 'attr negation' ' |
| 55 | color "nobold nodim noul noblink noreverse" "[22;24;25;27m" |
| 56 | ' |
| 57 | |
Jeff King | 5621068 | 2016-06-23 13:38:44 -0400 | [diff] [blame] | 58 | test_expect_success '"no-" variant of negation' ' |
| 59 | color "no-bold no-blink" "[22;25m" |
| 60 | ' |
| 61 | |
Junio C Hamano | 8b12413 | 2010-02-27 18:56:38 -0800 | [diff] [blame] | 62 | test_expect_success 'long color specification' ' |
| 63 | color "254 255 bold dim ul blink reverse" "[1;2;4;5;7;38;5;254;48;5;255m" |
| 64 | ' |
| 65 | |
Jeff King | ff40d18 | 2014-11-20 10:25:52 -0500 | [diff] [blame] | 66 | test_expect_success 'absurdly long color specification' ' |
| 67 | color \ |
Jeff King | 54590a0 | 2016-06-23 13:39:07 -0400 | [diff] [blame] | 68 | "#ffffff #ffffff bold nobold dim nodim italic noitalic |
Jeff King | 9dc3515 | 2016-06-23 13:40:16 -0400 | [diff] [blame] | 69 | ul noul blink noblink reverse noreverse strike nostrike" \ |
| 70 | "[1;2;3;4;5;7;9;22;23;24;25;27;29;38;2;255;255;255;48;2;255;255;255m" |
Jeff King | ff40d18 | 2014-11-20 10:25:52 -0500 | [diff] [blame] | 71 | ' |
| 72 | |
Jeff King | 3759d27 | 2015-01-20 17:14:48 -0500 | [diff] [blame] | 73 | test_expect_success '0-7 are aliases for basic ANSI color names' ' |
| 74 | color "0 7" "[30;47m" |
| 75 | ' |
| 76 | |
Timo Hirvonen | a0cf49c | 2008-02-06 14:16:08 +0200 | [diff] [blame] | 77 | test_expect_success '256 colors' ' |
| 78 | color "254 bold 255" "[1;38;5;254;48;5;255m" |
| 79 | ' |
| 80 | |
Jeff King | 17a4be2 | 2014-11-20 10:25:39 -0500 | [diff] [blame] | 81 | test_expect_success '24-bit colors' ' |
| 82 | color "#ff00ff black" "[38;2;255;0;255;40m" |
| 83 | ' |
| 84 | |
Jeff King | cb35722 | 2014-11-20 10:16:09 -0500 | [diff] [blame] | 85 | test_expect_success '"normal" yields no color at all"' ' |
| 86 | color "normal black" "[40m" |
| 87 | ' |
| 88 | |
| 89 | test_expect_success '-1 is a synonym for "normal"' ' |
| 90 | color "-1 black" "[40m" |
| 91 | ' |
| 92 | |
Timo Hirvonen | a0cf49c | 2008-02-06 14:16:08 +0200 | [diff] [blame] | 93 | test_expect_success 'color too small' ' |
| 94 | invalid_color "-2" |
| 95 | ' |
| 96 | |
| 97 | test_expect_success 'color too big' ' |
| 98 | invalid_color "256" |
| 99 | ' |
| 100 | |
| 101 | test_expect_success 'extra character after color number' ' |
| 102 | invalid_color "3X" |
| 103 | ' |
| 104 | |
| 105 | test_expect_success 'extra character after color name' ' |
| 106 | invalid_color "redX" |
| 107 | ' |
| 108 | |
| 109 | test_expect_success 'extra character after attribute' ' |
| 110 | invalid_color "dimX" |
| 111 | ' |
| 112 | |
Jeff King | 8b8e862 | 2009-12-12 07:25:24 -0500 | [diff] [blame] | 113 | test_expect_success 'unknown color slots are ignored (diff)' ' |
Jeff King | 8b8e862 | 2009-12-12 07:25:24 -0500 | [diff] [blame] | 114 | git config color.diff.nosuchslotwilleverbedefined white && |
| 115 | git diff --color |
| 116 | ' |
| 117 | |
| 118 | test_expect_success 'unknown color slots are ignored (branch)' ' |
| 119 | git config color.branch.nosuchslotwilleverbedefined white && |
| 120 | git branch -a |
| 121 | ' |
| 122 | |
| 123 | test_expect_success 'unknown color slots are ignored (status)' ' |
Jeff King | 9ddc5ac | 2015-03-20 06:12:29 -0400 | [diff] [blame] | 124 | git config color.status.nosuchslotwilleverbedefined white && |
| 125 | { git status; ret=$?; } && |
| 126 | case $ret in 0|1) : ok ;; *) false ;; esac |
Jeff King | 8b8e862 | 2009-12-12 07:25:24 -0500 | [diff] [blame] | 127 | ' |
| 128 | |
Timo Hirvonen | a0cf49c | 2008-02-06 14:16:08 +0200 | [diff] [blame] | 129 | test_done |