Use test_expect_success for test setups
PATCH 1/1 Use test_expect_success for test setups
Several tests did not use test_expect_success for their setup commands. Putting these start commands into the testing framework means both that errors during setup will be caught quickly and that non-error text will be suppressed without -v.
---
Noticed some extra output when updating my server's copy of git from source.
Tested on OS X using bash and dash.
t/t3020-ls-files-error-unmatch.sh | 8 ++- t/t3800-mktag.sh | 10 +++-- t/t4103-apply-binary.sh | 40 +++++++++++-------- t/t4200-rerere.sh | 64 +++++++++++++++-------------- t/t9501-gitweb-standalone-http-status.sh | 7 ++- 5 files changed, 71 insertions(+), 58 deletions(-)
t/t3020-ls-files-error-unmatch.sh +5 -3
@@ -11,9 +11,11 @@ line. ' . ./test-lib.sh -touch foo bar -git update-index --add foo bar -git commit -m "add foo bar" +test_expect_success 'setup' ' + touch foo bar && + git update-index --add foo bar && + git commit -m "add foo bar" +' test_expect_success \ 'git ls-files --error-unmatch should fail with unmatched path.' \
t/t3800-mktag.sh +6 -4
@@ -22,10 +22,12 @@ check_verify_failure () { ########################################################### # first create a commit, so we have a valid object/type # for the tag. -echo Hello >A -git update-index --add A -git commit -m "Initial commit" -head=$(git rev-parse --verify HEAD) +test_expect_success 'setup' ' + echo Hello >A && + git update-index --add A && + git commit -m "Initial commit" && + head=$(git rev-parse --verify HEAD) +' ############################################################ # 1. length check
t/t4103-apply-binary.sh +23 -17
@@ -20,23 +20,29 @@ EOF cat file1 >file2 cat file1 >file4 -git update-index --add --remove file1 file2 file4 -git commit -m 'Initial Version' 2>/dev/null - -git checkout -b binary -perl -pe 'y/x/\000/' <file1 >file3 -cat file3 >file4 -git add file2 -perl -pe 'y/\000/v/' <file3 >file1 -rm -f file2 -git update-index --add --remove file1 file2 file3 file4 -git commit -m 'Second Version' - -git diff-tree -p master binary >B.diff -git diff-tree -p -C master binary >C.diff - -git diff-tree -p --binary master binary >BF.diff -git diff-tree -p --binary -C master binary >CF.diff +test_expect_success 'setup' " + git update-index --add --remove file1 file2 file4 && + git commit -m 'Initial Version' 2>/dev/null && + + git checkout -b binary && + perl -pe 'y/x/\000/' <file1 >file3 && + cat file3 >file4 && + git add file2 && + perl -pe 'y/\000/v/' <file3 >file1 && + rm -f file2 && + git update-index --add --remove file1 file2 file3 file4 && + git commit -m 'Second Version' +" + +test_expect_success 'non-binary diffs' ' + git diff-tree -p master binary >B.diff && + git diff-tree -p -C master binary >C.diff +' + +test_expect_success 'binary diffs' ' + git diff-tree -p --binary master binary >BF.diff && + git diff-tree -p --binary -C master binary >CF.diff +' test_expect_success 'stat binary diff -- should not fail.' \ 'git checkout master
t/t4200-rerere.sh +36 -34
76 lines not on this page · raw message
t/t9501-gitweb-standalone-http-status.sh +4 -3
@@ -15,9 +15,10 @@ code and message.' # ---------------------------------------------------------------------- # snapshot settings -test_commit \ - 'SnapshotTests' \ - 'i can has snapshot?' +test_expect_success 'setup' " + test_commit 'SnapshotTests' 'i can has snapshot?' +" + cat >>gitweb_config.perl <<\EOF $feature{'snapshot'}{'override'} = 0;
Signature · 1 line
1.7.0.2.455.g91132
Quoted 4 lines · Brian Gernhardt
Several tests did not use
test_expect_successfor their setup commands. Putting these start commands into the testing framework means both that errors during setup will be caught quickly and that non-error text will be suppressed without -v.
Nice. Should the one in 4103 be three separate tests? They seem to be preparing the set of test input files and are not expected to fail (unless of course you are futzing with diff-tree, but for that we have t4013).
Quoted 10 lines · Junio C Hamano
Quoted 4 lines · Brian Gernhardt
Several tests did not use
test_expect_successfor their setup commands. Putting these start commands into the testing framework means both that errors during setup will be caught quickly and that non-error text will be suppressed without -v.Nice. Should the one in 4103 be three separate tests? They seem to be preparing the set of test input files and are not expected to fail (unless of course you are futzing with diff-tree, but for that we have t4013).
I don't think they need to be. t4103 was the first one I did and I did it as three tests since it was three separate "blocks". I had also tried moving the diff-trees closer to where their result is used until I saw how much they were reused.
~~ Brian
PATCH v2 1/1 Use test_expect_success for test setups
Several tests did not use test_expect_success for their setup commands. Putting these start commands into the testing framework means both that errors during setup will be caught quickly and that non-error text will be suppressed without -v.
---
Updated to only have one setup test in t4103, which also includes the initial set of cat commands just in case.
t/t3020-ls-files-error-unmatch.sh | 8 ++- t/t3800-mktag.sh | 10 +++-- t/t4103-apply-binary.sh | 56 +++++++++++++------------ t/t4200-rerere.sh | 64 +++++++++++++++-------------- t/t9501-gitweb-standalone-http-status.sh | 7 ++- 5 files changed, 77 insertions(+), 68 deletions(-)
t/t3020-ls-files-error-unmatch.sh +5 -3
@@ -11,9 +11,11 @@ line. ' . ./test-lib.sh -touch foo bar -git update-index --add foo bar -git commit -m "add foo bar" +test_expect_success 'setup' ' + touch foo bar && + git update-index --add foo bar && + git commit -m "add foo bar" +' test_expect_success \ 'git ls-files --error-unmatch should fail with unmatched path.' \
t/t3800-mktag.sh +6 -4
@@ -22,10 +22,12 @@ check_verify_failure () { ########################################################### # first create a commit, so we have a valid object/type # for the tag. -echo Hello >A -git update-index --add A -git commit -m "Initial commit" -head=$(git rev-parse --verify HEAD) +test_expect_success 'setup' ' + echo Hello >A && + git update-index --add A && + git commit -m "Initial commit" && + head=$(git rev-parse --verify HEAD) +' ############################################################ # 1. length check
t/t4103-apply-binary.sh +29 -27
62 lines not on this page · raw message
t/t4200-rerere.sh +36 -34
76 lines not on this page · raw message
t/t9501-gitweb-standalone-http-status.sh +4 -3
@@ -15,9 +15,10 @@ code and message.' # ---------------------------------------------------------------------- # snapshot settings -test_commit \ - 'SnapshotTests' \ - 'i can has snapshot?' +test_expect_success 'setup' " + test_commit 'SnapshotTests' 'i can has snapshot?' +" + cat >>gitweb_config.perl <<\EOF $feature{'snapshot'}{'override'} = 0;
Signature · 1 line
1.7.0.2.455.g91132