зеркало из https://github.com/microsoft/git.git
t1300: extract and use test_cmp_config()
In many config-related tests it's common to check if a config variable has expected value and we want to print the differences when the test fails. Doing it the normal way is three lines of shell code. Let's add a function do to all this (and a little more). This function has uses outside t1300 as well but I'm not going to convert them all. And it will be used in the next commit where per-worktree config feature is introduced. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
c4df23f792
Коммит
a5db0b77b9
|
@ -76,15 +76,11 @@ EOF
|
||||||
test_expect_success 'non-match result' 'test_cmp expect .git/config'
|
test_expect_success 'non-match result' 'test_cmp expect .git/config'
|
||||||
|
|
||||||
test_expect_success 'find mixed-case key by canonical name' '
|
test_expect_success 'find mixed-case key by canonical name' '
|
||||||
echo Second >expect &&
|
test_cmp_config Second cores.whatever
|
||||||
git config cores.whatever >actual &&
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'find mixed-case key by non-canonical name' '
|
test_expect_success 'find mixed-case key by non-canonical name' '
|
||||||
echo Second >expect &&
|
test_cmp_config Second CoReS.WhAtEvEr
|
||||||
git config CoReS.WhAtEvEr >actual &&
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'subsections are not canonicalized by git-config' '
|
test_expect_success 'subsections are not canonicalized by git-config' '
|
||||||
|
@ -94,12 +90,8 @@ test_expect_success 'subsections are not canonicalized by git-config' '
|
||||||
[section "SubSection"]
|
[section "SubSection"]
|
||||||
key = two
|
key = two
|
||||||
EOF
|
EOF
|
||||||
echo one >expect &&
|
test_cmp_config one section.subsection.key &&
|
||||||
git config section.subsection.key >actual &&
|
test_cmp_config two section.SubSection.key
|
||||||
test_cmp expect actual &&
|
|
||||||
echo two >expect &&
|
|
||||||
git config section.SubSection.key >actual &&
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
'
|
||||||
|
|
||||||
cat > .git/config <<\EOF
|
cat > .git/config <<\EOF
|
||||||
|
@ -212,9 +204,7 @@ test_expect_success 'really really mean test' '
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'get value' '
|
test_expect_success 'get value' '
|
||||||
echo alpha >expect &&
|
test_cmp_config alpha beta.haha
|
||||||
git config beta.haha >actual &&
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
'
|
||||||
|
|
||||||
cat > expect << EOF
|
cat > expect << EOF
|
||||||
|
@ -251,15 +241,11 @@ test_expect_success 'non-match' '
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'non-match value' '
|
test_expect_success 'non-match value' '
|
||||||
echo wow >expect &&
|
test_cmp_config wow --get nextsection.nonewline !for
|
||||||
git config --get nextsection.nonewline !for >actual &&
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'multi-valued get returns final one' '
|
test_expect_success 'multi-valued get returns final one' '
|
||||||
echo "wow2 for me" >expect &&
|
test_cmp_config "wow2 for me" --get nextsection.nonewline
|
||||||
git config --get nextsection.nonewline >actual &&
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'multi-valued get-all returns all' '
|
test_expect_success 'multi-valued get-all returns all' '
|
||||||
|
@ -520,21 +506,11 @@ test_expect_success 'editing stdin is an error' '
|
||||||
|
|
||||||
test_expect_success 'refer config from subdirectory' '
|
test_expect_success 'refer config from subdirectory' '
|
||||||
mkdir x &&
|
mkdir x &&
|
||||||
(
|
test_cmp_config -C x strasse --get --file ../other-config ein.bahn
|
||||||
cd x &&
|
|
||||||
echo strasse >expect &&
|
|
||||||
git config --get --file ../other-config ein.bahn >actual &&
|
|
||||||
test_cmp expect actual
|
|
||||||
)
|
|
||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'refer config from subdirectory via --file' '
|
test_expect_success 'refer config from subdirectory via --file' '
|
||||||
(
|
test_cmp_config -C x strasse --file=../other-config --get ein.bahn
|
||||||
cd x &&
|
|
||||||
git config --file=../other-config --get ein.bahn >actual &&
|
|
||||||
test_cmp expect actual
|
|
||||||
)
|
|
||||||
'
|
'
|
||||||
|
|
||||||
cat > expect << EOF
|
cat > expect << EOF
|
||||||
|
@ -688,16 +664,13 @@ test_expect_success numbers '
|
||||||
|
|
||||||
test_expect_success '--int is at least 64 bits' '
|
test_expect_success '--int is at least 64 bits' '
|
||||||
git config giga.watts 121g &&
|
git config giga.watts 121g &&
|
||||||
echo 129922760704 >expect &&
|
echo >expect &&
|
||||||
git config --int --get giga.watts >actual &&
|
test_cmp_config 129922760704 --int --get giga.watts
|
||||||
test_cmp expect actual
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'invalid unit' '
|
test_expect_success 'invalid unit' '
|
||||||
git config aninvalid.unit "1auto" &&
|
git config aninvalid.unit "1auto" &&
|
||||||
echo 1auto >expect &&
|
test_cmp_config 1auto aninvalid.unit &&
|
||||||
git config aninvalid.unit >actual &&
|
|
||||||
test_cmp expect actual &&
|
|
||||||
test_must_fail git config --int --get aninvalid.unit 2>actual &&
|
test_must_fail git config --int --get aninvalid.unit 2>actual &&
|
||||||
test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
|
test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
|
||||||
'
|
'
|
||||||
|
@ -1039,9 +1012,7 @@ test_expect_success '--null --get-regexp' '
|
||||||
|
|
||||||
test_expect_success 'inner whitespace kept verbatim' '
|
test_expect_success 'inner whitespace kept verbatim' '
|
||||||
git config section.val "foo bar" &&
|
git config section.val "foo bar" &&
|
||||||
echo "foo bar" >expect &&
|
test_cmp_config "foo bar" section.val
|
||||||
git config section.val >actual &&
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success SYMLINKS 'symlinked configuration' '
|
test_expect_success SYMLINKS 'symlinked configuration' '
|
||||||
|
@ -1809,21 +1780,15 @@ big = 1M
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
test_expect_success 'identical modern --type specifiers are allowed' '
|
test_expect_success 'identical modern --type specifiers are allowed' '
|
||||||
git config --type=int --type=int core.big >actual &&
|
test_cmp_config 1048576 --type=int --type=int core.big
|
||||||
echo 1048576 >expect &&
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'identical legacy --type specifiers are allowed' '
|
test_expect_success 'identical legacy --type specifiers are allowed' '
|
||||||
git config --int --int core.big >actual &&
|
test_cmp_config 1048576 --int --int core.big
|
||||||
echo 1048576 >expect &&
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'identical mixed --type specifiers are allowed' '
|
test_expect_success 'identical mixed --type specifiers are allowed' '
|
||||||
git config --int --type=int core.big >actual &&
|
test_cmp_config 1048576 --int --type=int core.big
|
||||||
echo 1048576 >expect &&
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'non-identical modern --type specifiers are not allowed' '
|
test_expect_success 'non-identical modern --type specifiers are not allowed' '
|
||||||
|
@ -1842,21 +1807,15 @@ test_expect_success 'non-identical mixed --type specifiers are not allowed' '
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--type allows valid type specifiers' '
|
test_expect_success '--type allows valid type specifiers' '
|
||||||
echo "true" >expect &&
|
test_cmp_config true --type=bool core.foo
|
||||||
git config --type=bool core.foo >actual &&
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--no-type unsets type specifiers' '
|
test_expect_success '--no-type unsets type specifiers' '
|
||||||
echo "10" >expect &&
|
test_cmp_config 10 --type=bool --no-type core.number
|
||||||
git config --type=bool --no-type core.number >actual &&
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'unset type specifiers may be reset to conflicting ones' '
|
test_expect_success 'unset type specifiers may be reset to conflicting ones' '
|
||||||
echo 1048576 >expect &&
|
test_cmp_config 1048576 --type=bool --no-type --type=int core.big
|
||||||
git config --type=bool --no-type --type=int core.big >actual &&
|
|
||||||
test_cmp expect actual
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '--type rejects unknown specifiers' '
|
test_expect_success '--type rejects unknown specifiers' '
|
||||||
|
|
|
@ -747,6 +747,29 @@ test_cmp() {
|
||||||
$GIT_TEST_CMP "$@"
|
$GIT_TEST_CMP "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check that the given config key has the expected value.
|
||||||
|
#
|
||||||
|
# test_cmp_config [-C <dir>] <expected-value>
|
||||||
|
# [<git-config-options>...] <config-key>
|
||||||
|
#
|
||||||
|
# for example to check that the value of core.bar is foo
|
||||||
|
#
|
||||||
|
# test_cmp_config foo core.bar
|
||||||
|
#
|
||||||
|
test_cmp_config() {
|
||||||
|
local GD &&
|
||||||
|
if test "$1" = "-C"
|
||||||
|
then
|
||||||
|
shift &&
|
||||||
|
GD="-C $1" &&
|
||||||
|
shift
|
||||||
|
fi &&
|
||||||
|
printf "%s\n" "$1" >expect.config &&
|
||||||
|
shift &&
|
||||||
|
git $GD config "$@" >actual.config &&
|
||||||
|
test_cmp expect.config actual.config
|
||||||
|
}
|
||||||
|
|
||||||
# test_cmp_bin - helper to compare binary files
|
# test_cmp_bin - helper to compare binary files
|
||||||
|
|
||||||
test_cmp_bin() {
|
test_cmp_bin() {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче