Skip to content

Commit

Permalink
t1300: put git invocations inside test function
Browse files Browse the repository at this point in the history
This is a very old script, and did a lot of:

  echo whatever >expect
  git config foo bar
  test_expect_success 'cmp .git/config expect'

which meant that we didn't actually check that the call to
git-config succeeded. Fix this, and while we're at it,
modernize the style to use test_cmp.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Oct 12, 2011
1 parent 703f05a commit 5a953fc
Showing 1 changed file with 93 additions and 83 deletions.
176 changes: 93 additions & 83 deletions t/t1300-repo-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ test_description='Test git config in different settings'

. ./test-lib.sh

test -f .git/config && rm .git/config

git config core.penguin "little blue"
test_expect_success 'clear default config' '
rm -f .git/config
'

cat > expect << EOF
[core]
penguin = little blue
EOF

test_expect_success 'initial' 'cmp .git/config expect'

git config Core.Movie BadPhysics
test_expect_success 'initial' '
git config core.penguin "little blue" &&
test_cmp expect .git/config
'

cat > expect << EOF
[core]
penguin = little blue
Movie = BadPhysics
EOF

test_expect_success 'mixed case' 'cmp .git/config expect'

git config Cores.WhatEver Second
test_expect_success 'mixed case' '
git config Core.Movie BadPhysics &&
test_cmp expect .git/config
'

cat > expect << EOF
[core]
Expand All @@ -37,10 +37,10 @@ cat > expect << EOF
[Cores]
WhatEver = Second
EOF

test_expect_success 'similar section' 'cmp .git/config expect'

git config CORE.UPPERCASE true
test_expect_success 'similar section' '
git config Cores.WhatEver Second
test_cmp expect .git/config
'

cat > expect << EOF
[core]
Expand All @@ -50,8 +50,10 @@ cat > expect << EOF
[Cores]
WhatEver = Second
EOF

test_expect_success 'similar section' 'cmp .git/config expect'
test_expect_success 'uppercase section' '
git config CORE.UPPERCASE true &&
test_cmp expect .git/config
'

test_expect_success 'replace with non-match' \
'git config core.penguin kingpin !blue'
Expand All @@ -69,7 +71,7 @@ cat > expect << EOF
WhatEver = Second
EOF

test_expect_success 'non-match result' 'cmp .git/config expect'
test_expect_success 'non-match result' 'test_cmp expect .git/config'

cat > .git/config <<\EOF
[alpha]
Expand All @@ -88,7 +90,7 @@ bar = foo
[beta]
EOF

test_expect_success 'unset with cont. lines is correct' 'cmp .git/config expect'
test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config'

cat > .git/config << EOF
[beta] ; silly comment # another comment
Expand Down Expand Up @@ -116,7 +118,7 @@ noIndent= sillyValue ; 'nother silly comment
[nextSection] noNewline = ouch
EOF

test_expect_success 'multiple unset is correct' 'cmp .git/config expect'
test_expect_success 'multiple unset is correct' 'test_cmp expect .git/config'

cp .git/config2 .git/config

Expand All @@ -140,9 +142,7 @@ noIndent= sillyValue ; 'nother silly comment
[nextSection] noNewline = ouch
EOF

test_expect_success 'all replaced' 'cmp .git/config expect'

git config beta.haha alpha
test_expect_success 'all replaced' 'test_cmp expect .git/config'

cat > expect << EOF
[beta] ; silly comment # another comment
Expand All @@ -153,10 +153,10 @@ noIndent= sillyValue ; 'nother silly comment
haha = alpha
[nextSection] noNewline = ouch
EOF

test_expect_success 'really mean test' 'cmp .git/config expect'

git config nextsection.nonewline wow
test_expect_success 'really mean test' '
git config beta.haha alpha &&
test_cmp expect .git/config
'

cat > expect << EOF
[beta] ; silly comment # another comment
Expand All @@ -168,11 +168,12 @@ noIndent= sillyValue ; 'nother silly comment
[nextSection]
nonewline = wow
EOF

test_expect_success 'really really mean test' 'cmp .git/config expect'
test_expect_success 'really really mean test' '
git config nextsection.nonewline wow &&
test_cmp expect .git/config
'

test_expect_success 'get value' 'test alpha = $(git config beta.haha)'
git config --unset beta.haha

cat > expect << EOF
[beta] ; silly comment # another comment
Expand All @@ -183,10 +184,10 @@ noIndent= sillyValue ; 'nother silly comment
[nextSection]
nonewline = wow
EOF

test_expect_success 'unset' 'cmp .git/config expect'

git config nextsection.NoNewLine "wow2 for me" "for me$"
test_expect_success 'unset' '
git config --unset beta.haha &&
test_cmp expect .git/config
'

cat > expect << EOF
[beta] ; silly comment # another comment
Expand All @@ -198,8 +199,10 @@ noIndent= sillyValue ; 'nother silly comment
nonewline = wow
NoNewLine = wow2 for me
EOF

test_expect_success 'multivar' 'cmp .git/config expect'
test_expect_success 'multivar' '
git config nextsection.NoNewLine "wow2 for me" "for me$" &&
test_cmp expect .git/config
'

test_expect_success 'non-match' \
'git config --get nextsection.nonewline !for'
Expand All @@ -214,8 +217,6 @@ test_expect_success 'ambiguous get' '
test_expect_success 'get multivar' \
'git config --get-all nextsection.nonewline'

git config nextsection.nonewline "wow3" "wow$"

cat > expect << EOF
[beta] ; silly comment # another comment
noIndent= sillyValue ; 'nother silly comment
Expand All @@ -226,8 +227,10 @@ noIndent= sillyValue ; 'nother silly comment
nonewline = wow3
NoNewLine = wow2 for me
EOF

test_expect_success 'multivar replace' 'cmp .git/config expect'
test_expect_success 'multivar replace' '
git config nextsection.nonewline "wow3" "wow$" &&
test_cmp expect .git/config
'

test_expect_success 'ambiguous value' '
test_must_fail git config nextsection.nonewline
Expand All @@ -241,8 +244,6 @@ test_expect_success 'invalid unset' '
test_must_fail git config --unset somesection.nonewline
'

git config --unset nextsection.nonewline "wow3$"

cat > expect << EOF
[beta] ; silly comment # another comment
noIndent= sillyValue ; 'nother silly comment
Expand All @@ -253,7 +254,10 @@ noIndent= sillyValue ; 'nother silly comment
NoNewLine = wow2 for me
EOF

test_expect_success 'multivar unset' 'cmp .git/config expect'
test_expect_success 'multivar unset' '
git config --unset nextsection.nonewline "wow3$" &&
test_cmp expect .git/config
'

test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'

Expand All @@ -276,7 +280,7 @@ noIndent= sillyValue ; 'nother silly comment
Alpha = beta
EOF

test_expect_success 'hierarchical section value' 'cmp .git/config expect'
test_expect_success 'hierarchical section value' 'test_cmp expect .git/config'

cat > expect << EOF
beta.noindent=sillyValue
Expand Down Expand Up @@ -304,15 +308,16 @@ EOF
test_expect_success '--get-regexp' \
'git config --get-regexp in > output && cmp output expect'

git config --add nextsection.nonewline "wow4 for you"

cat > expect << EOF
wow2 for me
wow4 for you
EOF

test_expect_success '--add' \
'git config --get-all nextsection.nonewline > output && cmp output expect'
test_expect_success '--add' '
git config --add nextsection.nonewline "wow4 for you" &&
git config --get-all nextsection.nonewline > output &&
test_cmp expect output
'

cat > .git/config << EOF
[novalue]
Expand Down Expand Up @@ -361,19 +366,17 @@ cat > .git/config << EOF
c = d
EOF

git config a.x y

cat > expect << EOF
[a.b]
c = d
[a]
x = y
EOF

test_expect_success 'new section is partial match of another' 'cmp .git/config expect'

git config b.x y
git config a.b c
test_expect_success 'new section is partial match of another' '
git config a.x y &&
test_cmp expect .git/config
'

cat > expect << EOF
[a.b]
Expand All @@ -385,7 +388,11 @@ cat > expect << EOF
x = y
EOF

test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
test_expect_success 'new variable inserts into proper section' '
git config b.x y &&
git config a.b c &&
test_cmp expect .git/config
'

test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
'test_must_fail git config --file non-existing-config -l'
Expand All @@ -399,9 +406,10 @@ cat > expect << EOF
ein.bahn=strasse
EOF

GIT_CONFIG=other-config git config -l > output

test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
test_expect_success 'alternative GIT_CONFIG' '
GIT_CONFIG=other-config git config -l >output &&
test_cmp expect output
'

test_expect_success 'alternative GIT_CONFIG (--file)' \
'git config --file other-config -l > output && cmp output expect'
Expand All @@ -417,16 +425,17 @@ test_expect_success 'refer config from subdirectory' '
'

GIT_CONFIG=other-config git config anwohner.park ausweis

cat > expect << EOF
[ein]
bahn = strasse
[anwohner]
park = ausweis
EOF

test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'
test_expect_success '--set in alternative GIT_CONFIG' '
GIT_CONFIG=other-config git config anwohner.park ausweis &&
test_cmp expect other-config
'

cat > .git/config << EOF
# Hallo
Expand Down Expand Up @@ -531,7 +540,7 @@ test_expect_success 'section ending' '
git config gitcvs.enabled true &&
git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
cmp .git/config expect
test_cmp expect .git/config
'

Expand Down Expand Up @@ -750,22 +759,21 @@ test_expect_success NOT_MINGW 'get --path copes with unset $HOME' '
test_cmp expect result
'

rm .git/config

git config quote.leading " test"
git config quote.ending "test "
git config quote.semicolon "test;test"
git config quote.hash "test#test"

cat > expect << EOF
[quote]
leading = " test"
ending = "test "
semicolon = "test;test"
hash = "test#test"
EOF

test_expect_success 'quoting' 'cmp .git/config expect'
test_expect_success 'quoting' '
rm .git/config &&
git config quote.leading " test" &&
git config quote.ending "test " &&
git config quote.semicolon "test;test" &&
git config quote.hash "test#test" &&
test_cmp expect .git/config
'

test_expect_success 'key with newline' '
test_must_fail git config "key.with
Expand All @@ -790,9 +798,10 @@ section.noncont=not continued
section.quotecont=cont;inued
EOF

git config --list > result

test_expect_success 'value continued on next line' 'cmp result expect'
test_expect_success 'value continued on next line' '
git config --list > result &&
cmp result expect
'

cat > .git/config <<\EOF
[section "sub=section"]
Expand All @@ -813,16 +822,17 @@ barQsection.sub=section.val3
Qsection.sub=section.val4
Qsection.sub=section.val5Q
EOF
test_expect_success '--null --list' '
git config --null --list | nul_to_q >result &&
echo >>result &&
test_cmp expect result
'

git config --null --list | perl -pe 'y/\000/Q/' > result
echo >>result

test_expect_success '--null --list' 'cmp result expect'

git config --null --get-regexp 'val[0-9]' | perl -pe 'y/\000/Q/' > result
echo >>result

test_expect_success '--null --get-regexp' 'cmp result expect'
test_expect_success '--null --get-regexp' '
git config --null --get-regexp "val[0-9]" | nul_to_q >result &&
echo >>result &&
test_cmp expect result
'

test_expect_success 'inner whitespace kept verbatim' '
git config section.val "foo bar" &&
Expand Down

0 comments on commit 5a953fc

Please sign in to comment.