Merge branch 'dl/test-must-fail-fixes'

Test clean-up.

* dl/test-must-fail-fixes:
  t1507: inline full_name()
  t1507: run commands within test_expect_success
  t1507: stop losing return codes of git commands
  t1501: remove use of `test_might_fail cp`
  t1409: use test_path_is_missing()
  t1409: let sed open its own input file
  t1307: reorder `nongit test_must_fail`
  t1306: convert `test_might_fail rm` to `rm -f`
  t0020: use ! check_packed_refs_marked
  t0020: don't use `test_must_fail has_cr`
  t0003: don't use `test_must_fail attr_check`
  t0003: use test_must_be_empty()
  t0003: use named parameters in attr_check()
  t0000: replace test_must_fail with run_sub_test_lib_test_err()
  t/lib-git-p4: use test_path_is_missing()
This commit is contained in:
Junio C Hamano 2020-02-05 14:34:57 -08:00
commit 381e8e9de1
9 changed files with 112 additions and 101 deletions

View File

@ -175,7 +175,7 @@ stop_and_cleanup_p4d () {
cleanup_git () {
retry_until_success rm -r "$git"
test_must_fail test -d "$git" &&
test_path_is_missing "$git" &&
retry_until_success mkdir "$git"
}

View File

@ -155,7 +155,7 @@ test_expect_success 'pretend we have a fully passing test suite' "
"
test_expect_success 'pretend we have a partially passing test suite' "
test_must_fail run_sub_test_lib_test \
run_sub_test_lib_test_err \
partial-pass '2/3 tests passing' <<-\\EOF &&
test_expect_success 'passing test #1' 'true'
test_expect_success 'failing test #2' 'false'
@ -219,7 +219,7 @@ test_expect_success 'pretend we have fixed one of two known breakages (run in su
"
test_expect_success 'pretend we have a pass, fail, and known breakage' "
test_must_fail run_sub_test_lib_test \
run_sub_test_lib_test_err \
mixed-results1 'mixed results #1' <<-\\EOF &&
test_expect_success 'passing test' 'true'
test_expect_success 'failing test' 'false'
@ -238,7 +238,7 @@ test_expect_success 'pretend we have a pass, fail, and known breakage' "
"
test_expect_success 'pretend we have a mix of all possible results' "
test_must_fail run_sub_test_lib_test \
run_sub_test_lib_test_err \
mixed-results2 'mixed results #2' <<-\\EOF &&
test_expect_success 'passing test' 'true'
test_expect_success 'passing test' 'true'
@ -274,7 +274,7 @@ test_expect_success 'pretend we have a mix of all possible results' "
"
test_expect_success C_LOCALE_OUTPUT 'test --verbose' '
test_must_fail run_sub_test_lib_test \
run_sub_test_lib_test_err \
t1234-verbose "test verbose" --verbose <<-\EOF &&
test_expect_success "passing test" true
test_expect_success "test with output" "echo foo"
@ -301,7 +301,7 @@ test_expect_success C_LOCALE_OUTPUT 'test --verbose' '
'
test_expect_success 'test --verbose-only' '
test_must_fail run_sub_test_lib_test \
run_sub_test_lib_test_err \
t2345-verbose-only-2 "test verbose-only=2" \
--verbose-only=2 <<-\EOF &&
test_expect_success "passing test" true
@ -834,7 +834,7 @@ then
fi
test_expect_success 'tests clean up even on failures' "
test_must_fail run_sub_test_lib_test \
run_sub_test_lib_test_err \
failing-cleanup 'Failing tests with cleanup commands' <<-\\EOF &&
test_expect_success 'tests clean up even after a failure' '
touch clean-after-failure &&
@ -863,7 +863,7 @@ test_expect_success 'tests clean up even on failures' "
"
test_expect_success 'test_atexit is run' "
test_must_fail run_sub_test_lib_test \
run_sub_test_lib_test_err \
atexit-cleanup 'Run atexit commands' -i <<-\\EOF &&
test_expect_success 'tests clean up even after a failure' '
> ../../clean-atexit &&

View File

@ -5,19 +5,16 @@ test_description=gitattributes
. ./test-lib.sh
attr_check () {
path="$1" expect="$2"
path="$1" expect="$2" git_opts="$3" &&
git $3 check-attr test -- "$path" >actual 2>err &&
echo "$path: test: $2" >expect &&
git $git_opts check-attr test -- "$path" >actual 2>err &&
echo "$path: test: $expect" >expect &&
test_cmp expect actual &&
test_line_count = 0 err
test_must_be_empty err
}
attr_check_quote () {
path="$1"
quoted_path="$2"
expect="$3"
path="$1" quoted_path="$2" expect="$3" &&
git check-attr test -- "$path" >actual &&
echo "\"$quoted_path\": test: $expect" >expect &&
@ -27,7 +24,7 @@ attr_check_quote () {
test_expect_success 'open-quoted pathname' '
echo "\"a test=a" >.gitattributes &&
test_must_fail attr_check a a
attr_check a unspecified
'
@ -112,20 +109,20 @@ test_expect_success 'attribute test' '
test_expect_success 'attribute matching is case sensitive when core.ignorecase=0' '
test_must_fail attr_check F f "-c core.ignorecase=0" &&
test_must_fail attr_check a/F f "-c core.ignorecase=0" &&
test_must_fail attr_check a/c/F f "-c core.ignorecase=0" &&
test_must_fail attr_check a/G a/g "-c core.ignorecase=0" &&
test_must_fail attr_check a/B/g a/b/g "-c core.ignorecase=0" &&
test_must_fail attr_check a/b/G a/b/g "-c core.ignorecase=0" &&
test_must_fail attr_check a/b/H a/b/h "-c core.ignorecase=0" &&
test_must_fail attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=0" &&
test_must_fail attr_check oNoFf unset "-c core.ignorecase=0" &&
test_must_fail attr_check oFfOn set "-c core.ignorecase=0" &&
attr_check F unspecified "-c core.ignorecase=0" &&
attr_check a/F unspecified "-c core.ignorecase=0" &&
attr_check a/c/F unspecified "-c core.ignorecase=0" &&
attr_check a/G unspecified "-c core.ignorecase=0" &&
attr_check a/B/g a/g "-c core.ignorecase=0" &&
attr_check a/b/G unspecified "-c core.ignorecase=0" &&
attr_check a/b/H unspecified "-c core.ignorecase=0" &&
attr_check a/b/D/g a/g "-c core.ignorecase=0" &&
attr_check oNoFf unspecified "-c core.ignorecase=0" &&
attr_check oFfOn unspecified "-c core.ignorecase=0" &&
attr_check NO unspecified "-c core.ignorecase=0" &&
test_must_fail attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=0" &&
attr_check a/b/D/NO unspecified "-c core.ignorecase=0" &&
attr_check a/b/d/YES a/b/d/* "-c core.ignorecase=0" &&
test_must_fail attr_check a/E/f "A/e/F" "-c core.ignorecase=0"
attr_check a/E/f f "-c core.ignorecase=0"
'
@ -149,8 +146,8 @@ test_expect_success 'attribute matching is case insensitive when core.ignorecase
'
test_expect_success CASE_INSENSITIVE_FS 'additional case insensitivity tests' '
test_must_fail attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=0" &&
test_must_fail attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=0" &&
attr_check a/B/D/g a/g "-c core.ignorecase=0" &&
attr_check A/B/D/NO unspecified "-c core.ignorecase=0" &&
attr_check A/b/h a/b/h "-c core.ignorecase=1" &&
attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=1" &&
attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=1"
@ -244,7 +241,7 @@ EOF
git check-attr foo -- "a/b/f" >>actual 2>>err &&
git check-attr foo -- "a/b/c/f" >>actual 2>>err &&
test_cmp expect actual &&
test_line_count = 0 err
test_must_be_empty err
'
test_expect_success '"**" with no slashes test' '
@ -265,7 +262,7 @@ EOF
git check-attr foo -- "a/b/f" >>actual 2>>err &&
git check-attr foo -- "a/b/c/f" >>actual 2>>err &&
test_cmp expect actual &&
test_line_count = 0 err
test_must_be_empty err
'
test_expect_success 'using --git-dir and --work-tree' '

View File

@ -159,8 +159,8 @@ test_expect_success 'checkout with autocrlf=input' '
rm -f tmp one dir/two three &&
git config core.autocrlf input &&
git read-tree --reset -u HEAD &&
test_must_fail has_cr one &&
test_must_fail has_cr dir/two &&
! has_cr one &&
! has_cr dir/two &&
git update-index -- one dir/two &&
test "$one" = $(git hash-object --stdin <one) &&
test "$two" = $(git hash-object --stdin <dir/two) &&
@ -237,9 +237,9 @@ test_expect_success '.gitattributes says two is binary' '
git config core.autocrlf true &&
git read-tree --reset -u HEAD &&
test_must_fail has_cr dir/two &&
! has_cr dir/two &&
verbose has_cr one &&
test_must_fail has_cr three
! has_cr three
'
test_expect_success '.gitattributes says two is input' '
@ -248,7 +248,7 @@ test_expect_success '.gitattributes says two is input' '
echo "two crlf=input" >.gitattributes &&
git read-tree --reset -u HEAD &&
test_must_fail has_cr dir/two
! has_cr dir/two
'
test_expect_success '.gitattributes says two and three are text' '
@ -270,7 +270,7 @@ test_expect_success 'in-tree .gitattributes (1)' '
rm -rf tmp one dir .gitattributes patch.file three &&
git read-tree --reset -u HEAD &&
test_must_fail has_cr one &&
! has_cr one &&
verbose has_cr three
'
@ -280,7 +280,7 @@ test_expect_success 'in-tree .gitattributes (2)' '
git read-tree --reset HEAD &&
git checkout-index -f -q -u -a &&
test_must_fail has_cr one &&
! has_cr one &&
verbose has_cr three
'
@ -291,7 +291,7 @@ test_expect_success 'in-tree .gitattributes (3)' '
git checkout-index -u .gitattributes &&
git checkout-index -u one dir/two three &&
test_must_fail has_cr one &&
! has_cr one &&
verbose has_cr three
'
@ -302,7 +302,7 @@ test_expect_success 'in-tree .gitattributes (4)' '
git checkout-index -u one dir/two three &&
git checkout-index -u .gitattributes &&
test_must_fail has_cr one &&
! has_cr one &&
verbose has_cr three
'

View File

@ -153,7 +153,7 @@ test_expect_success 'Checking attributes in both XDG and local attributes files'
test_expect_success 'Checking attributes in a non-XDG global attributes file' '
test_might_fail rm .gitattributes &&
rm -f .gitattributes &&
echo "f attr_f=test" >"$HOME"/my_gitattributes &&
git config core.attributesfile "$HOME"/my_gitattributes &&
echo "f: attr_f: test" >expected &&
@ -165,7 +165,7 @@ test_expect_success 'Checking attributes in a non-XDG global attributes file' '
test_expect_success 'write: xdg file exists and ~/.gitconfig doesn'\''t' '
mkdir -p "$HOME"/.config/git &&
>"$HOME"/.config/git/config &&
test_might_fail rm "$HOME"/.gitconfig &&
rm -f "$HOME"/.gitconfig &&
git config --global user.name "write_config" &&
echo "[user]" >expected &&
echo " name = write_config" >>expected &&
@ -183,8 +183,8 @@ test_expect_success 'write: xdg file exists and ~/.gitconfig exists' '
test_expect_success 'write: ~/.config/git/ exists and config file doesn'\''t' '
test_might_fail rm "$HOME"/.gitconfig &&
test_might_fail rm "$HOME"/.config/git/config &&
rm -f "$HOME"/.gitconfig &&
rm -f "$HOME"/.config/git/config &&
git config --global user.name "write_gitconfig" &&
echo "[user]" >expected &&
echo " name = write_gitconfig" >>expected &&

View File

@ -74,7 +74,7 @@ test_expect_success 'can parse blob ending with CR' '
'
test_expect_success 'config --blob outside of a repository is an error' '
test_must_fail nongit git config --blob=foo --list
nongit test_must_fail git config --blob=foo --list
'
test_done

View File

@ -8,7 +8,7 @@ test_description='avoid rewriting packed-refs unnecessarily'
# shouldn't upset readers, and it should be omitted if the file is
# ever rewritten.
mark_packed_refs () {
sed -e "s/^\(#.*\)/\1 t1409 /" <.git/packed-refs >.git/packed-refs.new &&
sed -e "s/^\(#.*\)/\1 t1409 /" .git/packed-refs >.git/packed-refs.new &&
mv .git/packed-refs.new .git/packed-refs
}
@ -27,15 +27,15 @@ test_expect_success 'setup' '
'
test_expect_success 'do not create packed-refs file gratuitously' '
test_must_fail test -f .git/packed-refs &&
test_path_is_missing .git/packed-refs &&
git update-ref refs/heads/foo $A &&
test_must_fail test -f .git/packed-refs &&
test_path_is_missing .git/packed-refs &&
git update-ref refs/heads/foo $B &&
test_must_fail test -f .git/packed-refs &&
test_path_is_missing .git/packed-refs &&
git update-ref refs/heads/foo $C $B &&
test_must_fail test -f .git/packed-refs &&
test_path_is_missing .git/packed-refs &&
git update-ref -d refs/heads/foo &&
test_must_fail test -f .git/packed-refs
test_path_is_missing .git/packed-refs
'
test_expect_success 'check that marking the packed-refs file works' '
@ -46,7 +46,7 @@ test_expect_success 'check that marking the packed-refs file works' '
git for-each-ref >actual &&
test_cmp expected actual &&
git pack-refs --all &&
test_must_fail check_packed_refs_marked &&
! check_packed_refs_marked &&
git for-each-ref >actual2 &&
test_cmp expected actual2
'
@ -80,7 +80,7 @@ test_expect_success 'touch packed-refs on delete of packed' '
git pack-refs --all &&
mark_packed_refs &&
git update-ref -d refs/heads/packed-delete &&
test_must_fail check_packed_refs_marked
! check_packed_refs_marked
'
test_expect_success 'leave packed-refs untouched on update of loose' '

View File

@ -350,7 +350,7 @@ test_expect_success 'Multi-worktree setup' '
mkdir work &&
mkdir -p repo.git/repos/foo &&
cp repo.git/HEAD repo.git/index repo.git/repos/foo &&
test_might_fail cp repo.git/sharedindex.* repo.git/repos/foo &&
{ cp repo.git/sharedindex.* repo.git/repos/foo || :; } &&
sane_unset GIT_DIR GIT_CONFIG GIT_WORK_TREE
'

View File

@ -28,14 +28,9 @@ test_expect_success 'setup' '
)
'
full_name () {
(cd clone &&
git rev-parse --symbolic-full-name "$@")
}
commit_subject () {
(cd clone &&
git show -s --pretty=format:%s "$@")
git show -s --pretty=tformat:%s "$@")
}
error_message () {
@ -44,63 +39,78 @@ error_message () {
}
test_expect_success '@{upstream} resolves to correct full name' '
test refs/remotes/origin/master = "$(full_name @{upstream})" &&
test refs/remotes/origin/master = "$(full_name @{UPSTREAM})" &&
test refs/remotes/origin/master = "$(full_name @{UpSTReam})"
echo refs/remotes/origin/master >expect &&
git -C clone rev-parse --symbolic-full-name @{upstream} >actual &&
test_cmp expect actual &&
git -C clone rev-parse --symbolic-full-name @{UPSTREAM} >actual &&
test_cmp expect actual &&
git -C clone rev-parse --symbolic-full-name @{UpSTReam} >actual &&
test_cmp expect actual
'
test_expect_success '@{u} resolves to correct full name' '
test refs/remotes/origin/master = "$(full_name @{u})" &&
test refs/remotes/origin/master = "$(full_name @{U})"
echo refs/remotes/origin/master >expect &&
git -C clone rev-parse --symbolic-full-name @{u} >actual &&
test_cmp expect actual &&
git -C clone rev-parse --symbolic-full-name @{U} >actual &&
test_cmp expect actual
'
test_expect_success 'my-side@{upstream} resolves to correct full name' '
test refs/remotes/origin/side = "$(full_name my-side@{u})"
echo refs/remotes/origin/side >expect &&
git -C clone rev-parse --symbolic-full-name my-side@{u} >actual &&
test_cmp expect actual
'
test_expect_success 'upstream of branch with @ in middle' '
full_name fun@ny@{u} >actual &&
git -C clone rev-parse --symbolic-full-name fun@ny@{u} >actual &&
echo refs/remotes/origin/side >expect &&
test_cmp expect actual &&
full_name fun@ny@{U} >actual &&
git -C clone rev-parse --symbolic-full-name fun@ny@{U} >actual &&
test_cmp expect actual
'
test_expect_success 'upstream of branch with @ at start' '
full_name @funny@{u} >actual &&
git -C clone rev-parse --symbolic-full-name @funny@{u} >actual &&
echo refs/remotes/origin/side >expect &&
test_cmp expect actual
'
test_expect_success 'upstream of branch with @ at end' '
full_name funny@@{u} >actual &&
git -C clone rev-parse --symbolic-full-name funny@@{u} >actual &&
echo refs/remotes/origin/side >expect &&
test_cmp expect actual
'
test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' '
test_must_fail full_name refs/heads/my-side@{upstream}
test_must_fail git -C clone rev-parse --symbolic-full-name refs/heads/my-side@{upstream}
'
test_expect_success 'my-side@{u} resolves to correct commit' '
git checkout side &&
test_commit 5 &&
(cd clone && git fetch) &&
test 2 = "$(commit_subject my-side)" &&
test 5 = "$(commit_subject my-side@{u})"
echo 2 >expect &&
commit_subject my-side >actual &&
test_cmp expect actual &&
echo 5 >expect &&
commit_subject my-side@{u} >actual
'
test_expect_success 'not-tracking@{u} fails' '
test_must_fail full_name non-tracking@{u} &&
test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u} &&
(cd clone && git checkout --no-track -b non-tracking) &&
test_must_fail full_name non-tracking@{u}
test_must_fail git -C clone rev-parse --symbolic-full-name non-tracking@{u}
'
test_expect_success '<branch>@{u}@{1} resolves correctly' '
test_commit 6 &&
(cd clone && git fetch) &&
test 5 = $(commit_subject my-side@{u}@{1}) &&
test 5 = $(commit_subject my-side@{U}@{1})
echo 5 >expect &&
commit_subject my-side@{u}@{1} >actual &&
test_cmp expect actual &&
commit_subject my-side@{U}@{1} >actual &&
test_cmp expect actual
'
test_expect_success '@{u} without specifying branch fails on a detached HEAD' '
@ -149,7 +159,9 @@ test_expect_success 'checkout other@{u}' '
'
test_expect_success 'branch@{u} works when tracking a local branch' '
test refs/heads/master = "$(full_name local-master@{u})"
echo refs/heads/master >expect &&
git -C clone rev-parse --symbolic-full-name local-master@{u} >actual &&
test_cmp expect actual
'
test_expect_success 'branch@{u} error message when no upstream' '
@ -203,35 +215,37 @@ test_expect_success 'pull works when tracking a local branch' '
# makes sense if the previous one succeeded
test_expect_success '@{u} works when tracking a local branch' '
test refs/heads/master = "$(full_name @{u})"
echo refs/heads/master >expect &&
git -C clone rev-parse --symbolic-full-name @{u} >actual &&
test_cmp expect actual
'
commit=$(git rev-parse HEAD)
cat >expect <<EOF
commit $commit
Reflog: master@{0} (C O Mitter <committer@example.com>)
Reflog message: branch: Created from HEAD
Author: A U Thor <author@example.com>
Date: Thu Apr 7 15:15:13 2005 -0700
3
EOF
test_expect_success 'log -g other@{u}' '
commit=$(git rev-parse HEAD) &&
cat >expect <<-EOF &&
commit $commit
Reflog: master@{0} (C O Mitter <committer@example.com>)
Reflog message: branch: Created from HEAD
Author: A U Thor <author@example.com>
Date: Thu Apr 7 15:15:13 2005 -0700
3
EOF
git log -1 -g other@{u} >actual &&
test_cmp expect actual
'
cat >expect <<EOF
commit $commit
Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
Reflog message: branch: Created from HEAD
Author: A U Thor <author@example.com>
Date: Thu Apr 7 15:15:13 2005 -0700
3
EOF
test_expect_success 'log -g other@{u}@{now}' '
commit=$(git rev-parse HEAD) &&
cat >expect <<-EOF &&
commit $commit
Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
Reflog message: branch: Created from HEAD
Author: A U Thor <author@example.com>
Date: Thu Apr 7 15:15:13 2005 -0700
3
EOF
git log -1 -g other@{u}@{now} >actual &&
test_cmp expect actual
'