{"thread":{"id":"23104","subject":"[PATCH] Use test_expect_success for test setups","startedAt":"2010-03-20T08:29:11Z","lastAt":"2010-03-20T16:03:52Z","messageCount":4,"participants":["Brian Gernhardt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"137317","messageId":"1269073751-64588-1-git-send-email-brian@gernhardtsoftware.com","threadId":"23104","inReplyTo":null,"subject":"[PATCH] Use test_expect_success for test setups","fromName":"Brian Gernhardt","fromEmail":"brian@gernhardtsoftware.com","sentAt":"2010-03-20T08:29:11Z","receivedAt":"2010-03-20T08:29:11Z","isPatch":true,"sender":{"key":"brian@gernhardtsoftware.com","avatar":"https://avatars.githubusercontent.com/u/133455?v=4"},"body":"Several tests did not use test_expect_success for their setup\ncommands.  Putting these start commands into the testing framework\nmeans both that errors during setup will be caught quickly and that\nnon-error text will be suppressed without -v.\n\nSigned-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>\n---\n\n Noticed some extra output when updating my server's copy of git from\n source.\n\n Tested on OS X using bash and dash.\n\n t/t3020-ls-files-error-unmatch.sh        |    8 ++-\n t/t3800-mktag.sh                         |   10 +++--\n t/t4103-apply-binary.sh                  |   40 +++++++++++--------\n t/t4200-rerere.sh                        |   64 +++++++++++++++--------------\n t/t9501-gitweb-standalone-http-status.sh |    7 ++-\n 5 files changed, 71 insertions(+), 58 deletions(-)\n\ndiff --git a/t/t3020-ls-files-error-unmatch.sh b/t/t3020-ls-files-error-unmatch.sh\nindex f4066cb..a7d8187 100755\n--- a/t/t3020-ls-files-error-unmatch.sh\n+++ b/t/t3020-ls-files-error-unmatch.sh\n@@ -11,9 +11,11 @@ line.\n '\n . ./test-lib.sh\n \n-touch foo bar\n-git update-index --add foo bar\n-git commit -m \"add foo bar\"\n+test_expect_success 'setup' '\n+\ttouch foo bar &&\n+\tgit update-index --add foo bar &&\n+\tgit commit -m \"add foo bar\"\n+'\n \n test_expect_success \\\n     'git ls-files --error-unmatch should fail with unmatched path.' \\\ndiff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh\nindex 6fb027b..8eb4794 100755\n--- a/t/t3800-mktag.sh\n+++ b/t/t3800-mktag.sh\n@@ -22,10 +22,12 @@ check_verify_failure () {\n ###########################################################\n # first create a commit, so we have a valid object/type\n # for the tag.\n-echo Hello >A\n-git update-index --add A\n-git commit -m \"Initial commit\"\n-head=$(git rev-parse --verify HEAD)\n+test_expect_success 'setup' '\n+\techo Hello >A &&\n+\tgit update-index --add A &&\n+\tgit commit -m \"Initial commit\" &&\n+\thead=$(git rev-parse --verify HEAD)\n+'\n \n ############################################################\n #  1. length check\ndiff --git a/t/t4103-apply-binary.sh b/t/t4103-apply-binary.sh\nindex ad4cc1a..c12a4bd 100755\n--- a/t/t4103-apply-binary.sh\n+++ b/t/t4103-apply-binary.sh\n@@ -20,23 +20,29 @@ EOF\n cat file1 >file2\n cat file1 >file4\n \n-git update-index --add --remove file1 file2 file4\n-git commit -m 'Initial Version' 2>/dev/null\n-\n-git checkout -b binary\n-perl -pe 'y/x/\\000/' <file1 >file3\n-cat file3 >file4\n-git add file2\n-perl -pe 'y/\\000/v/' <file3 >file1\n-rm -f file2\n-git update-index --add --remove file1 file2 file3 file4\n-git commit -m 'Second Version'\n-\n-git diff-tree -p master binary >B.diff\n-git diff-tree -p -C master binary >C.diff\n-\n-git diff-tree -p --binary master binary >BF.diff\n-git diff-tree -p --binary -C master binary >CF.diff\n+test_expect_success 'setup' \"\n+\tgit update-index --add --remove file1 file2 file4 &&\n+\tgit commit -m 'Initial Version' 2>/dev/null &&\n+\n+\tgit checkout -b binary &&\n+\tperl -pe 'y/x/\\000/' <file1 >file3 &&\n+\tcat file3 >file4 &&\n+\tgit add file2 &&\n+\tperl -pe 'y/\\000/v/' <file3 >file1 &&\n+\trm -f file2 &&\n+\tgit update-index --add --remove file1 file2 file3 file4 &&\n+\tgit commit -m 'Second Version'\n+\"\n+\n+test_expect_success 'non-binary diffs' '\n+\tgit diff-tree -p master binary >B.diff &&\n+\tgit diff-tree -p -C master binary >C.diff\n+'\n+\n+test_expect_success 'binary diffs' '\n+\tgit diff-tree -p --binary master binary >BF.diff &&\n+\tgit diff-tree -p --binary -C master binary >CF.diff\n+'\n \n test_expect_success 'stat binary diff -- should not fail.' \\\n \t'git checkout master\ndiff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh\nindex bb402c3..70856d0 100755\n--- a/t/t4200-rerere.sh\n+++ b/t/t4200-rerere.sh\n@@ -8,40 +8,42 @@ test_description='git rerere\n \n . ./test-lib.sh\n \n-cat > a1 << EOF\n-Some title\n-==========\n-Whether 'tis nobler in the mind to suffer\n-The slings and arrows of outrageous fortune,\n-Or to take arms against a sea of troubles,\n-And by opposing end them? To die: to sleep;\n-No more; and by a sleep to say we end\n-The heart-ache and the thousand natural shocks\n-That flesh is heir to, 'tis a consummation\n-Devoutly to be wish'd.\n-EOF\n-\n-git add a1\n-git commit -q -a -m initial\n-\n-git checkout -b first\n-cat >> a1 << EOF\n-Some title\n-==========\n-To die, to sleep;\n-To sleep: perchance to dream: ay, there's the rub;\n-For in that sleep of death what dreams may come\n-When we have shuffled off this mortal coil,\n-Must give us pause: there's the respect\n-That makes calamity of so long life;\n-EOF\n-git commit -q -a -m first\n-\n-git checkout -b second master\n-git show first:a1 |\n-sed -e 's/To die, t/To die! T/' -e 's/Some title/Some Title/' > a1\n-echo \"* END *\" >>a1\n-git commit -q -a -m second\n+test_expect_success 'setup' \"\n+\tcat > a1 <<- EOF &&\n+\tSome title\n+\t==========\n+\tWhether 'tis nobler in the mind to suffer\n+\tThe slings and arrows of outrageous fortune,\n+\tOr to take arms against a sea of troubles,\n+\tAnd by opposing end them? To die: to sleep;\n+\tNo more; and by a sleep to say we end\n+\tThe heart-ache and the thousand natural shocks\n+\tThat flesh is heir to, 'tis a consummation\n+\tDevoutly to be wish'd.\n+\tEOF\n+\n+\tgit add a1 &&\n+\tgit commit -q -a -m initial &&\n+\n+\tgit checkout -b first &&\n+\tcat >> a1 <<- EOF &&\n+\tSome title\n+\t==========\n+\tTo die, to sleep;\n+\tTo sleep: perchance to dream: ay, there's the rub;\n+\tFor in that sleep of death what dreams may come\n+\tWhen we have shuffled off this mortal coil,\n+\tMust give us pause: there's the respect\n+\tThat makes calamity of so long life;\n+\tEOF\n+\tgit commit -q -a -m first &&\n+\n+\tgit checkout -b second master &&\n+\tgit show first:a1 |\n+\tsed -e 's/To die, t/To die! T/' -e 's/Some title/Some Title/' > a1 &&\n+\techo '* END *' >>a1 &&\n+\tgit commit -q -a -m second\n+\"\n \n test_expect_success 'nothing recorded without rerere' '\n \t(rm -rf .git/rr-cache; git config rerere.enabled false) &&\ndiff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh\nindex d196cc5..2487da1 100755\n--- a/t/t9501-gitweb-standalone-http-status.sh\n+++ b/t/t9501-gitweb-standalone-http-status.sh\n@@ -15,9 +15,10 @@ code and message.'\n # ----------------------------------------------------------------------\n # snapshot settings\n \n-test_commit \\\n-\t'SnapshotTests' \\\n-\t'i can has snapshot?'\n+test_expect_success 'setup' \"\n+\ttest_commit 'SnapshotTests' 'i can has snapshot?'\n+\"\n+\n \n cat >>gitweb_config.perl <<\\EOF\n $feature{'snapshot'}{'override'} = 0;\n-- \n1.7.0.2.455.g91132\n"},{"id":"137340","messageId":"7v7hp7ov8c.fsf@alter.siamese.dyndns.org","threadId":"23104","inReplyTo":"1269073751-64588-1-git-send-email-brian@gernhardtsoftware.com","subject":"Re: [PATCH] Use test_expect_success for test setups","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-03-20T15:42:27Z","receivedAt":"2010-03-20T15:42:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Brian Gernhardt <brian@gernhardtsoftware.com> writes:\n\n> Several tests did not use test_expect_success for their setup\n> commands.  Putting these start commands into the testing framework\n> means both that errors during setup will be caught quickly and that\n> non-error text will be suppressed without -v.\n\nNice.  Should the one in 4103 be three separate tests?  They seem to be\npreparing the set of test input files and are not expected to fail (unless\nof course you are futzing with diff-tree, but for that we have t4013).\n"},{"id":"137342","messageId":"2DDEFE95-02A7-4DAE-B233-ABE1545EDB65@gernhardtsoftware.com","threadId":"23104","inReplyTo":"7v7hp7ov8c.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Use test_expect_success for test setups","fromName":"Brian Gernhardt","fromEmail":"brian@gernhardtsoftware.com","sentAt":"2010-03-20T15:58:24Z","receivedAt":"2010-03-20T15:58:24Z","isPatch":true,"sender":{"key":"brian@gernhardtsoftware.com","avatar":"https://avatars.githubusercontent.com/u/133455?v=4"},"body":"\nOn Mar 20, 2010, at 11:42 AM, Junio C Hamano wrote:\n\n> Brian Gernhardt <brian@gernhardtsoftware.com> writes:\n> \n>> Several tests did not use test_expect_success for their setup\n>> commands.  Putting these start commands into the testing framework\n>> means both that errors during setup will be caught quickly and that\n>> non-error text will be suppressed without -v.\n> \n> Nice.  Should the one in 4103 be three separate tests?  They seem to be\n> preparing the set of test input files and are not expected to fail (unless\n> of course you are futzing with diff-tree, but for that we have t4013).\n\nI 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.\n\n~~ Brian"},{"id":"137346","messageId":"1269101032-68184-1-git-send-email-brian@gernhardtsoftware.com","threadId":"23104","inReplyTo":"2DDEFE95-02A7-4DAE-B233-ABE1545EDB65@gernhardtsoftware.com","subject":"[PATCH v2] Use test_expect_success for test setups","fromName":"Brian Gernhardt","fromEmail":"brian@gernhardtsoftware.com","sentAt":"2010-03-20T16:03:52Z","receivedAt":"2010-03-20T16:03:52Z","isPatch":true,"sender":{"key":"brian@gernhardtsoftware.com","avatar":"https://avatars.githubusercontent.com/u/133455?v=4"},"body":"Several tests did not use test_expect_success for their setup\ncommands.  Putting these start commands into the testing framework\nmeans both that errors during setup will be caught quickly and that\nnon-error text will be suppressed without -v.\n\nSigned-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>\n---\n\n Updated to only have one setup test in t4103, which also includes the\n initial set of cat commands just in case.\n\n t/t3020-ls-files-error-unmatch.sh        |    8 ++-\n t/t3800-mktag.sh                         |   10 +++--\n t/t4103-apply-binary.sh                  |   56 +++++++++++++------------\n t/t4200-rerere.sh                        |   64 +++++++++++++++--------------\n t/t9501-gitweb-standalone-http-status.sh |    7 ++-\n 5 files changed, 77 insertions(+), 68 deletions(-)\n\ndiff --git a/t/t3020-ls-files-error-unmatch.sh b/t/t3020-ls-files-error-unmatch.sh\nindex f4066cb..a7d8187 100755\n--- a/t/t3020-ls-files-error-unmatch.sh\n+++ b/t/t3020-ls-files-error-unmatch.sh\n@@ -11,9 +11,11 @@ line.\n '\n . ./test-lib.sh\n \n-touch foo bar\n-git update-index --add foo bar\n-git commit -m \"add foo bar\"\n+test_expect_success 'setup' '\n+\ttouch foo bar &&\n+\tgit update-index --add foo bar &&\n+\tgit commit -m \"add foo bar\"\n+'\n \n test_expect_success \\\n     'git ls-files --error-unmatch should fail with unmatched path.' \\\ndiff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh\nindex 6fb027b..8eb4794 100755\n--- a/t/t3800-mktag.sh\n+++ b/t/t3800-mktag.sh\n@@ -22,10 +22,12 @@ check_verify_failure () {\n ###########################################################\n # first create a commit, so we have a valid object/type\n # for the tag.\n-echo Hello >A\n-git update-index --add A\n-git commit -m \"Initial commit\"\n-head=$(git rev-parse --verify HEAD)\n+test_expect_success 'setup' '\n+\techo Hello >A &&\n+\tgit update-index --add A &&\n+\tgit commit -m \"Initial commit\" &&\n+\thead=$(git rev-parse --verify HEAD)\n+'\n \n ############################################################\n #  1. length check\ndiff --git a/t/t4103-apply-binary.sh b/t/t4103-apply-binary.sh\nindex ad4cc1a..962d69e 100755\n--- a/t/t4103-apply-binary.sh\n+++ b/t/t4103-apply-binary.sh\n@@ -10,33 +10,35 @@ test_description='git apply handling binary patches\n \n # setup\n \n-cat >file1 <<EOF\n-A quick brown fox jumps over the lazy dog.\n-A tiny little penguin runs around in circles.\n-There is a flag with Linux written on it.\n-A slow black-and-white panda just sits there,\n-munching on his bamboo.\n-EOF\n-cat file1 >file2\n-cat file1 >file4\n-\n-git update-index --add --remove file1 file2 file4\n-git commit -m 'Initial Version' 2>/dev/null\n-\n-git checkout -b binary\n-perl -pe 'y/x/\\000/' <file1 >file3\n-cat file3 >file4\n-git add file2\n-perl -pe 'y/\\000/v/' <file3 >file1\n-rm -f file2\n-git update-index --add --remove file1 file2 file3 file4\n-git commit -m 'Second Version'\n-\n-git diff-tree -p master binary >B.diff\n-git diff-tree -p -C master binary >C.diff\n-\n-git diff-tree -p --binary master binary >BF.diff\n-git diff-tree -p --binary -C master binary >CF.diff\n+test_expect_success 'setup' \"\n+\tcat >file1 <<-EOF &&\n+\tA quick brown fox jumps over the lazy dog.\n+\tA tiny little penguin runs around in circles.\n+\tThere is a flag with Linux written on it.\n+\tA slow black-and-white panda just sits there,\n+\tmunching on his bamboo.\n+\tEOF\n+\tcat file1 >file2 &&\n+\tcat file1 >file4 &&\n+\n+\tgit update-index --add --remove file1 file2 file4 &&\n+\tgit commit -m 'Initial Version' 2>/dev/null &&\n+\n+\tgit checkout -b binary &&\n+\tperl -pe 'y/x/\\000/' <file1 >file3 &&\n+\tcat file3 >file4 &&\n+\tgit add file2 &&\n+\tperl -pe 'y/\\000/v/' <file3 >file1 &&\n+\trm -f file2 &&\n+\tgit update-index --add --remove file1 file2 file3 file4 &&\n+\tgit commit -m 'Second Version' &&\n+\n+\tgit diff-tree -p master binary >B.diff &&\n+\tgit diff-tree -p -C master binary >C.diff &&\n+\n+\tgit diff-tree -p --binary master binary >BF.diff &&\n+\tgit diff-tree -p --binary -C master binary >CF.diff\n+\"\n \n test_expect_success 'stat binary diff -- should not fail.' \\\n \t'git checkout master\ndiff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh\nindex bb402c3..70856d0 100755\n--- a/t/t4200-rerere.sh\n+++ b/t/t4200-rerere.sh\n@@ -8,40 +8,42 @@ test_description='git rerere\n \n . ./test-lib.sh\n \n-cat > a1 << EOF\n-Some title\n-==========\n-Whether 'tis nobler in the mind to suffer\n-The slings and arrows of outrageous fortune,\n-Or to take arms against a sea of troubles,\n-And by opposing end them? To die: to sleep;\n-No more; and by a sleep to say we end\n-The heart-ache and the thousand natural shocks\n-That flesh is heir to, 'tis a consummation\n-Devoutly to be wish'd.\n-EOF\n-\n-git add a1\n-git commit -q -a -m initial\n-\n-git checkout -b first\n-cat >> a1 << EOF\n-Some title\n-==========\n-To die, to sleep;\n-To sleep: perchance to dream: ay, there's the rub;\n-For in that sleep of death what dreams may come\n-When we have shuffled off this mortal coil,\n-Must give us pause: there's the respect\n-That makes calamity of so long life;\n-EOF\n-git commit -q -a -m first\n-\n-git checkout -b second master\n-git show first:a1 |\n-sed -e 's/To die, t/To die! T/' -e 's/Some title/Some Title/' > a1\n-echo \"* END *\" >>a1\n-git commit -q -a -m second\n+test_expect_success 'setup' \"\n+\tcat > a1 <<- EOF &&\n+\tSome title\n+\t==========\n+\tWhether 'tis nobler in the mind to suffer\n+\tThe slings and arrows of outrageous fortune,\n+\tOr to take arms against a sea of troubles,\n+\tAnd by opposing end them? To die: to sleep;\n+\tNo more; and by a sleep to say we end\n+\tThe heart-ache and the thousand natural shocks\n+\tThat flesh is heir to, 'tis a consummation\n+\tDevoutly to be wish'd.\n+\tEOF\n+\n+\tgit add a1 &&\n+\tgit commit -q -a -m initial &&\n+\n+\tgit checkout -b first &&\n+\tcat >> a1 <<- EOF &&\n+\tSome title\n+\t==========\n+\tTo die, to sleep;\n+\tTo sleep: perchance to dream: ay, there's the rub;\n+\tFor in that sleep of death what dreams may come\n+\tWhen we have shuffled off this mortal coil,\n+\tMust give us pause: there's the respect\n+\tThat makes calamity of so long life;\n+\tEOF\n+\tgit commit -q -a -m first &&\n+\n+\tgit checkout -b second master &&\n+\tgit show first:a1 |\n+\tsed -e 's/To die, t/To die! T/' -e 's/Some title/Some Title/' > a1 &&\n+\techo '* END *' >>a1 &&\n+\tgit commit -q -a -m second\n+\"\n \n test_expect_success 'nothing recorded without rerere' '\n \t(rm -rf .git/rr-cache; git config rerere.enabled false) &&\ndiff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh\nindex d196cc5..2487da1 100755\n--- a/t/t9501-gitweb-standalone-http-status.sh\n+++ b/t/t9501-gitweb-standalone-http-status.sh\n@@ -15,9 +15,10 @@ code and message.'\n # ----------------------------------------------------------------------\n # snapshot settings\n \n-test_commit \\\n-\t'SnapshotTests' \\\n-\t'i can has snapshot?'\n+test_expect_success 'setup' \"\n+\ttest_commit 'SnapshotTests' 'i can has snapshot?'\n+\"\n+\n \n cat >>gitweb_config.perl <<\\EOF\n $feature{'snapshot'}{'override'} = 0;\n-- \n1.7.0.2.455.g91132\n"}]}