summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rwxr-xr-xt/t3203-branch-output.sh31
-rwxr-xr-xt/t4207-log-decoration-colors.sh22
-rwxr-xr-xt/t6006-rev-list-format.sh129
-rwxr-xr-xt/t6300-for-each-ref.sh39
-rwxr-xr-xt/t7004-tag.sh25
-rw-r--r--t/test-lib-functions.sh1
6 files changed, 175 insertions, 72 deletions
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index a428ae6703..d2aec0f38b 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -2,6 +2,7 @@
test_description='git branch display tests'
. ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-terminal.sh
test_expect_success 'make commits' '
echo content >file &&
@@ -239,4 +240,34 @@ test_expect_success 'git branch --format option' '
test_i18ncmp expect actual
'
+test_expect_success "set up color tests" '
+ echo "<RED>master<RESET>" >expect.color &&
+ echo "master" >expect.bare &&
+ color_args="--format=%(color:red)%(refname:short) --list master"
+'
+
+test_expect_success '%(color) omitted without tty' '
+ TERM=vt100 git branch $color_args >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp expect.bare actual
+'
+
+test_expect_success TTY '%(color) present with tty' '
+ test_terminal env TERM=vt100 git branch $color_args >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp expect.color actual
+'
+
+test_expect_success 'color.branch=always overrides auto-color' '
+ git -c color.branch=always branch $color_args >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp expect.color actual
+'
+
+test_expect_success '--color overrides auto-color' '
+ git branch --color $color_args >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp expect.color actual
+'
+
test_done
diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh
index b972296f06..60f040cab8 100755
--- a/t/t4207-log-decoration-colors.sh
+++ b/t/t4207-log-decoration-colors.sh
@@ -7,11 +7,6 @@ test_description='Test for "git log --decorate" colors'
. ./test-lib.sh
-get_color ()
-{
- git config --get-color no.such.slot "$1"
-}
-
test_expect_success setup '
git config diff.color.commit yellow &&
git config color.decorate.branch green &&
@@ -20,14 +15,14 @@ test_expect_success setup '
git config color.decorate.stash magenta &&
git config color.decorate.HEAD cyan &&
- c_reset=$(get_color reset) &&
+ c_reset="<RESET>" &&
- c_commit=$(get_color yellow) &&
- c_branch=$(get_color green) &&
- c_remoteBranch=$(get_color red) &&
- c_tag=$(get_color "reverse bold yellow") &&
- c_stash=$(get_color magenta) &&
- c_HEAD=$(get_color cyan) &&
+ c_commit="<YELLOW>" &&
+ c_branch="<GREEN>" &&
+ c_remoteBranch="<RED>" &&
+ c_tag="<BOLD;REVERSE;YELLOW>" &&
+ c_stash="<MAGENTA>" &&
+ c_HEAD="<CYAN>" &&
test_commit A &&
git clone . other &&
@@ -59,7 +54,8 @@ EOF
# to this test since it does not contain any decoration, hence --first-parent
test_expect_success 'Commit Decorations Colored Correctly' '
git log --first-parent --abbrev=10 --all --decorate --oneline --color=always |
- sed "s/[0-9a-f]\{10,10\}/COMMIT_ID/" >out &&
+ sed "s/[0-9a-f]\{10,10\}/COMMIT_ID/" |
+ test_decode_color >out &&
test_cmp expected out
'
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index a1dcdb81d7..b326d550f3 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -59,10 +59,14 @@ test_format () {
}
# Feed to --format to provide predictable colored sequences.
+BASIC_COLOR='%Credfoo%Creset'
+COLOR='%C(red)foo%C(reset)'
AUTO_COLOR='%C(auto,red)foo%C(auto,reset)'
+ALWAYS_COLOR='%C(always,red)foo%C(always,reset)'
has_color () {
- printf '\033[31mfoo\033[m\n' >expect &&
- test_cmp expect "$1"
+ test_decode_color <"$1" >decoded &&
+ echo "<RED>foo<RESET>" >expect &&
+ test_cmp expect decoded
}
has_no_color () {
@@ -170,62 +174,84 @@ $added
EOF
-test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<EOF
-commit $head2
-foobarbazxyzzy
-commit $head1
-foobarbazxyzzy
-EOF
-
-test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<EOF
-commit $head2
-foo
-commit $head1
-foo
-EOF
-
-test_expect_success '%C(auto,...) does not enable color by default' '
- git log --format=$AUTO_COLOR -1 >actual &&
- has_no_color actual
+test_expect_success 'basic colors' '
+ cat >expect <<-EOF &&
+ commit $head2
+ <RED>foo<GREEN>bar<BLUE>baz<RESET>xyzzy
+ EOF
+ format="%Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy" &&
+ git rev-list --color --format="$format" -1 master >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp expect actual
'
-test_expect_success '%C(auto,...) enables colors for color.diff' '
- git -c color.diff=always log --format=$AUTO_COLOR -1 >actual &&
- has_color actual
+test_expect_success 'advanced colors' '
+ cat >expect <<-EOF &&
+ commit $head2
+ <BOLD;RED;BYELLOW>foo<RESET>
+ EOF
+ format="%C(red yellow bold)foo%C(reset)" &&
+ git rev-list --color --format="$format" -1 master >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp expect actual
'
-test_expect_success '%C(auto,...) enables colors for color.ui' '
- git -c color.ui=always log --format=$AUTO_COLOR -1 >actual &&
- has_color actual
-'
+for spec in \
+ "%Cred:$BASIC_COLOR" \
+ "%C(...):$COLOR" \
+ "%C(auto,...):$AUTO_COLOR"
+do
+ desc=${spec%%:*}
+ color=${spec#*:}
+ test_expect_success "$desc does not enable color by default" '
+ git log --format=$color -1 >actual &&
+ has_no_color actual
+ '
-test_expect_success '%C(auto,...) respects --color' '
- git log --format=$AUTO_COLOR -1 --color >actual &&
- has_color actual
-'
+ test_expect_success "$desc enables colors for color.diff" '
+ git -c color.diff=always log --format=$color -1 >actual &&
+ has_color actual
+ '
-test_expect_success '%C(auto,...) respects --no-color' '
- git -c color.ui=always log --format=$AUTO_COLOR -1 --no-color >actual &&
- has_no_color actual
-'
+ test_expect_success "$desc enables colors for color.ui" '
+ git -c color.ui=always log --format=$color -1 >actual &&
+ has_color actual
+ '
-test_expect_success TTY '%C(auto,...) respects --color=auto (stdout is tty)' '
- test_terminal env TERM=vt100 \
- git log --format=$AUTO_COLOR -1 --color=auto >actual &&
- has_color actual
-'
+ test_expect_success "$desc respects --color" '
+ git log --format=$color -1 --color >actual &&
+ has_color actual
+ '
-test_expect_success '%C(auto,...) respects --color=auto (stdout not tty)' '
- (
- TERM=vt100 && export TERM &&
- git log --format=$AUTO_COLOR -1 --color=auto >actual &&
+ test_expect_success "$desc respects --no-color" '
+ git -c color.ui=always log --format=$color -1 --no-color >actual &&
has_no_color actual
- )
+ '
+
+ test_expect_success TTY "$desc respects --color=auto (stdout is tty)" '
+ test_terminal env TERM=vt100 \
+ git log --format=$color -1 --color=auto >actual &&
+ has_color actual
+ '
+
+ test_expect_success "$desc respects --color=auto (stdout not tty)" '
+ (
+ TERM=vt100 && export TERM &&
+ git log --format=$color -1 --color=auto >actual &&
+ has_no_color actual
+ )
+ '
+done
+
+test_expect_success '%C(always,...) enables color even without tty' '
+ git log --format=$ALWAYS_COLOR -1 >actual &&
+ has_color actual
'
test_expect_success '%C(auto) respects --color' '
- git log --color --format="%C(auto)%H" -1 >actual &&
- printf "\\033[33m%s\\033[m\\n" $(git rev-parse HEAD) >expect &&
+ git log --color --format="%C(auto)%H" -1 >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ echo "<YELLOW>$(git rev-parse HEAD)<RESET>" >expect &&
test_cmp expect actual
'
@@ -235,6 +261,17 @@ test_expect_success '%C(auto) respects --no-color' '
test_cmp expect actual
'
+test_expect_success 'rev-list %C(auto,...) respects --color' '
+ git rev-list --color --format="%C(auto,green)foo%C(auto,reset)" \
+ -1 HEAD >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ cat >expect <<-EOF &&
+ commit $(git rev-parse HEAD)
+ <GREEN>foo<RESET>
+ EOF
+ test_cmp expect actual
+'
+
iconv -f utf-8 -t $test_encoding > commit-msg <<EOF
Test printing of complex bodies
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 834a9ed168..2274a4b733 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -7,6 +7,7 @@ test_description='for-each-ref test'
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-gpg.sh
+. "$TEST_DIRECTORY"/lib-terminal.sh
# Mon Jul 3 23:18:43 2006 +0000
datestamp=1151968723
@@ -412,21 +413,33 @@ test_expect_success 'Check for invalid refname format' '
test_must_fail git for-each-ref --format="%(refname:INVALID)"
'
-get_color ()
-{
- git config --get-color no.such.slot "$1"
-}
+test_expect_success 'set up color tests' '
+ cat >expected.color <<-EOF &&
+ $(git rev-parse --short refs/heads/master) <GREEN>master<RESET>
+ $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET>
+ $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
+ $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
+ EOF
+ sed "s/<[^>]*>//g" <expected.color >expected.bare &&
+ color_format="%(objectname:short) %(color:green)%(refname:short)"
+'
-cat >expected <<EOF
-$(git rev-parse --short refs/heads/master) $(get_color green)master$(get_color reset)
-$(git rev-parse --short refs/remotes/origin/master) $(get_color green)origin/master$(get_color reset)
-$(git rev-parse --short refs/tags/testtag) $(get_color green)testtag$(get_color reset)
-$(git rev-parse --short refs/tags/two) $(get_color green)two$(get_color reset)
-EOF
+test_expect_success TTY '%(color) shows color with a tty' '
+ test_terminal env TERM=vt100 \
+ git for-each-ref --format="$color_format" >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp expected.color actual
+'
-test_expect_success 'Check %(color:...) ' '
- git for-each-ref --format="%(objectname:short) %(color:green)%(refname:short)" >actual &&
- test_cmp expected actual
+test_expect_success '%(color) does not show color without tty' '
+ TERM=vt100 git for-each-ref --format="$color_format" >actual &&
+ test_cmp expected.bare actual
+'
+
+test_expect_success 'color.ui=always can override tty check' '
+ git -c color.ui=always for-each-ref --format="$color_format" >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp expected.color actual
'
cat >expected <<\EOF
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index 0ef7b94394..dd5ba450ee 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -9,6 +9,7 @@ Tests for operations with tags.'
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-gpg.sh
+. "$TEST_DIRECTORY"/lib-terminal.sh
# creating and listing lightweight tags:
@@ -1900,6 +1901,30 @@ test_expect_success '--format should list tags as per format given' '
test_cmp expect actual
'
+test_expect_success "set up color tests" '
+ echo "<RED>v1.0<RESET>" >expect.color &&
+ echo "v1.0" >expect.bare &&
+ color_args="--format=%(color:red)%(refname:short) --list v1.0"
+'
+
+test_expect_success '%(color) omitted without tty' '
+ TERM=vt100 git tag $color_args >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp expect.bare actual
+'
+
+test_expect_success TTY '%(color) present with tty' '
+ test_terminal env TERM=vt100 git tag $color_args >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp expect.color actual
+'
+
+test_expect_success 'color.ui=always overrides auto-color' '
+ git -c color.ui=always tag $color_args >actual.raw &&
+ test_decode_color <actual.raw >actual &&
+ test_cmp expect.color actual
+'
+
test_expect_success 'setup --merged test tags' '
git tag mergetest-1 HEAD~2 &&
git tag mergetest-2 HEAD~1 &&
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 50a9a1d1c4..1701fe2a06 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -42,6 +42,7 @@ test_decode_color () {
function name(n) {
if (n == 0) return "RESET";
if (n == 1) return "BOLD";
+ if (n == 7) return "REVERSE";
if (n == 30) return "BLACK";
if (n == 31) return "RED";
if (n == 32) return "GREEN";