t / t4026-color.shon commit gitweb: hack around CGI's list-context param() handling (13dbf46)
   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        actual=$(git config --get-color no.such.slot "$1") &&
  12        test "$actual" = "\e$2"
  13}
  14
  15invalid_color()
  16{
  17        test_must_fail git config --get-color no.such.slot "$1"
  18}
  19
  20test_expect_success 'reset' '
  21        color "reset" "[m"
  22'
  23
  24test_expect_success 'attribute before color name' '
  25        color "bold red" "[1;31m"
  26'
  27
  28test_expect_success 'color name before attribute' '
  29        color "red bold" "[1;31m"
  30'
  31
  32test_expect_success 'attr fg bg' '
  33        color "ul blue red" "[4;34;41m"
  34'
  35
  36test_expect_success 'fg attr bg' '
  37        color "blue ul red" "[4;34;41m"
  38'
  39
  40test_expect_success 'fg bg attr' '
  41        color "blue red ul" "[4;34;41m"
  42'
  43
  44test_expect_success 'fg bg attr...' '
  45        color "blue bold dim ul blink reverse" "[1;2;4;5;7;34m"
  46'
  47
  48test_expect_success 'long color specification' '
  49        color "254 255 bold dim ul blink reverse" "[1;2;4;5;7;38;5;254;48;5;255m"
  50'
  51
  52test_expect_success '256 colors' '
  53        color "254 bold 255" "[1;38;5;254;48;5;255m"
  54'
  55
  56test_expect_success 'color too small' '
  57        invalid_color "-2"
  58'
  59
  60test_expect_success 'color too big' '
  61        invalid_color "256"
  62'
  63
  64test_expect_success 'extra character after color number' '
  65        invalid_color "3X"
  66'
  67
  68test_expect_success 'extra character after color name' '
  69        invalid_color "redX"
  70'
  71
  72test_expect_success 'extra character after attribute' '
  73        invalid_color "dimX"
  74'
  75
  76test_expect_success 'unknown color slots are ignored (diff)' '
  77        git config color.diff.nosuchslotwilleverbedefined white &&
  78        git diff --color
  79'
  80
  81test_expect_success 'unknown color slots are ignored (branch)' '
  82        git config color.branch.nosuchslotwilleverbedefined white &&
  83        git branch -a
  84'
  85
  86test_expect_success 'unknown color slots are ignored (status)' '
  87        git config color.status.nosuchslotwilleverbedefined white || exit
  88        git status
  89        case $? in 0|1) : ok ;; *) false ;; esac
  90'
  91
  92test_done