{"thread":{"id":"19512","subject":"[PATCH] t5500: Modernize test style","startedAt":"2009-05-26T06:17:14Z","lastAt":"2009-05-26T06:17:14Z","messageCount":1,"participants":["Stephen Boyd"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"114735","messageId":"1243318634-20108-1-git-send-email-bebarino@gmail.com","threadId":"19512","inReplyTo":null,"subject":"[PATCH] t5500: Modernize test style","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-05-26T06:17:14Z","receivedAt":"2009-05-26T06:17:14Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Code outside of the test harness was emitting \"Initializing...\" from\ngit-init. Fixup this test to be more modern:\n\n    - test_expect_object_count() and count_objects() are unused\n\n    - use grep directly instead of test \"...\" = $(grep ...)\n\n    - end the test_expect_success line with a single-quote and put the\n      test on a new line\n\n    - put as much code inside the test harness as possible\n\n    - no_strict_count_check is unused and duplicates the test\n      \"new object count\"\n\n    - use && whenever possible to catch errors early\n\n    - use test_tick instead of GIT_AUTHOR_DATE=$sec\n\n    - remove debugging aid log.txt\n\n    - use subshells instead of cd-ing around\n\nAlso merge the pull test into one large test.\n\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n\nThis is a major rewrite, and probably code churn.\n\n t/t5500-fetch-pack.sh |  276 ++++++++++++++++++++++++++----------------------\n 1 files changed, 149 insertions(+), 127 deletions(-)\n\ndiff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh\nindex c450f33..a8c2ca2 100755\n--- a/t/t5500-fetch-pack.sh\n+++ b/t/t5500-fetch-pack.sh\n@@ -3,9 +3,8 @@\n # Copyright (c) 2005 Johannes Schindelin\n #\n \n-test_description='Testing multi_ack pack fetching\n+test_description='Testing multi_ack pack fetching'\n \n-'\n . ./test-lib.sh\n \n # Test fetch-pack/upload-pack pair.\n@@ -13,77 +12,60 @@ test_description='Testing multi_ack pack fetching\n # Some convenience functions\n \n add () {\n-\tname=$1\n-\ttext=\"$@\"\n-\tbranch=`echo $name | sed -e 's/^\\(.\\).*$/\\1/'`\n-\tparents=\"\"\n+\tname=$1 &&\n+\ttext=\"$@\" &&\n+\tbranch=`echo $name | sed -e 's/^\\(.\\).*$/\\1/'` &&\n+\tparents=\"\" &&\n \n-\tshift\n+\tshift &&\n \twhile test $1; do\n-\t\tparents=\"$parents -p $1\"\n+\t\tparents=\"$parents -p $1\" &&\n \t\tshift\n-\tdone\n+\tdone &&\n \n-\techo \"$text\" > test.txt\n-\tgit update-index --add test.txt\n-\ttree=$(git write-tree)\n+\techo \"$text\" > test.txt &&\n+\tgit update-index --add test.txt &&\n+\ttree=$(git write-tree) &&\n \t# make sure timestamps are in correct order\n-\tsec=$(($sec+1))\n-\tcommit=$(echo \"$text\" | GIT_AUTHOR_DATE=$sec \\\n-\t\tgit commit-tree $tree $parents 2>>log2.txt)\n-\teval \"$name=$commit; export $name\"\n-\techo $commit > .git/refs/heads/$branch\n+\ttest_tick &&\n+\tcommit=$(echo \"$text\" | git commit-tree $tree $parents) &&\n+\teval \"$name=$commit; export $name\" &&\n+\techo $commit > .git/refs/heads/$branch &&\n \teval ${branch}TIP=$commit\n }\n \n-count_objects () {\n-\tls .git/objects/??/* 2>>log2.txt | wc -l | tr -d \" \"\n-}\n-\n-test_expect_object_count () {\n-\tmessage=$1\n-\tcount=$2\n-\n-\toutput=\"$(count_objects)\"\n-\ttest_expect_success \\\n-\t\t\"new object count $message\" \\\n-\t\t\"test $count = $output\"\n-}\n-\n pull_to_client () {\n-\tnumber=$1\n-\theads=$2\n-\tcount=$3\n-\tno_strict_count_check=$4\n-\n-\tcd client\n-\ttest_expect_success \"$number pull\" \\\n-\t\t\"git fetch-pack -k -v .. $heads\"\n-\tcase \"$heads\" in *A*) echo $ATIP > .git/refs/heads/A;; esac\n-\tcase \"$heads\" in *B*) echo $BTIP > .git/refs/heads/B;; esac\n-\tgit symbolic-ref HEAD refs/heads/`echo $heads | sed -e 's/^\\(.\\).*$/\\1/'`\n-\n-\ttest_expect_success \"fsck\" 'git fsck --full > fsck.txt 2>&1'\n-\n-\ttest_expect_success 'check downloaded results' \\\n-\t'mv .git/objects/pack/pack-* . &&\n-\t p=`ls -1 pack-*.pack` &&\n-\t git unpack-objects <$p &&\n-\t git fsck --full'\n-\n-\ttest_expect_success \"new object count after $number pull\" \\\n-\t'idx=`echo pack-*.idx` &&\n-\t pack_count=`git show-index <$idx | wc -l` &&\n-\t test $pack_count = $count'\n-\ttest -z \"$pack_count\" && pack_count=0\n-\tif [ -z \"$no_strict_count_check\" ]; then\n-\t\ttest_expect_success \"minimal count\" \"test $count = $pack_count\"\n-\telse\n-\t\ttest $count != $pack_count && \\\n-\t\t\techo \"WARNING: $pack_count objects transmitted, only $count of which were needed\"\n-\tfi\n-\trm -f pack-*\n-\tcd ..\n+\tnumber=$1 &&\n+\theads=$2 &&\n+\tcount=$3 &&\n+\ttest_expect_success \"$number pull\" '\n+\t\t(\n+\t\t\tcd client &&\n+\t\t\tgit fetch-pack -k -v .. $heads &&\n+\n+\t\t\tcase \"$heads\" in\n+\t\t\t    *A*)\n+\t\t\t\t    echo $ATIP > .git/refs/heads/A;;\n+\t\t\tesac &&\n+\t\t\tcase \"$heads\" in *B*)\n+\t\t\t    echo $BTIP > .git/refs/heads/B;;\n+\t\t\tesac &&\n+\t\t\tgit symbolic-ref HEAD refs/heads/`echo $heads \\\n+\t\t\t\t| sed -e \"s/^\\(.\\).*$/\\1/\"` &&\n+\n+\t\t\tgit fsck --full &&\n+\n+\t\t\tmv .git/objects/pack/pack-* . &&\n+\t\t\tp=`ls -1 pack-*.pack` &&\n+\t\t\tgit unpack-objects <$p &&\n+\t\t\tgit fsck --full &&\n+\n+\t\t\tidx=`echo pack-*.idx` &&\n+\t\t\tpack_count=`git show-index <$idx | wc -l` &&\n+\t\t\ttest $pack_count = $count &&\n+\t\t\trm -f pack-*\n+\t\t)\n+\t'\n }\n \n # Here begins the actual testing\n@@ -94,89 +76,129 @@ pull_to_client () {\n \n # client pulls A20, B1. Then tracks only B. Then pulls A.\n \n-(\n+test_expect_success 'setup' '\n \tmkdir client &&\n-\tcd client &&\n-\tgit init 2>> log2.txt &&\n-\tgit config transfer.unpacklimit 0\n-)\n-\n-add A1\n-\n-prev=1; cur=2; while [ $cur -le 10 ]; do\n-\tadd A$cur $(eval echo \\$A$prev)\n-\tprev=$cur\n-\tcur=$(($cur+1))\n-done\n-\n-add B1 $A1\n-\n-echo $ATIP > .git/refs/heads/A\n-echo $BTIP > .git/refs/heads/B\n-git symbolic-ref HEAD refs/heads/B\n+\t(\n+\t\tcd client &&\n+\t\tgit init &&\n+\t\tgit config transfer.unpacklimit 0\n+\t) &&\n+\tadd A1 &&\n+\tprev=1 &&\n+\tcur=2 &&\n+\twhile [ $cur -le 10 ]; do\n+\t\tadd A$cur $(eval echo \\$A$prev) &&\n+\t\tprev=$cur &&\n+\t\tcur=$(($cur+1))\n+\tdone &&\n+\tadd B1 $A1\n+\techo $ATIP > .git/refs/heads/A &&\n+\techo $BTIP > .git/refs/heads/B &&\n+\tgit symbolic-ref HEAD refs/heads/B\n+'\n \n pull_to_client 1st \"B A\" $((11*3))\n \n-add A11 $A10\n-\n-prev=1; cur=2; while [ $cur -le 65 ]; do\n-\tadd B$cur $(eval echo \\$B$prev)\n-\tprev=$cur\n-\tcur=$(($cur+1))\n-done\n+test_expect_success 'post 1st pull setup' '\n+\tadd A11 $A10 &&\n+\tprev=1 &&\n+\tcur=2 &&\n+\twhile [ $cur -le 65 ]; do\n+\t\tadd B$cur $(eval echo \\$B$prev) &&\n+\t\tprev=$cur &&\n+\t\tcur=$(($cur+1))\n+\tdone\n+'\n \n pull_to_client 2nd \"B\" $((64*3))\n \n-pull_to_client 3rd \"A\" $((1*3)) # old fails\n-\n-test_expect_success \"clone shallow\" 'git clone --depth 2 \"file://$(pwd)/.\" shallow'\n+pull_to_client 3rd \"A\" $((1*3))\n \n-(cd shallow; git count-objects -v) > count.shallow\n-\n-test_expect_success \"clone shallow object count\" \\\n-\t\"test \\\"in-pack: 18\\\" = \\\"$(grep in-pack count.shallow)\\\"\"\n-\n-count_output () {\n-\tsed -e '/^in-pack:/d' -e '/^packs:/d' -e '/^size-pack:/d' -e '/: 0$/d' \"$1\"\n-}\n+test_expect_success 'clone shallow' '\n+\tgit clone --depth 2 \"file://$(pwd)/.\" shallow\n+'\n \n-test_expect_success \"clone shallow object count (part 2)\" '\n-\ttest -z \"$(count_output count.shallow)\"\n+test_expect_success 'clone shallow object count' '\n+\t(\n+\t\tcd shallow &&\n+\t\tgit count-objects -v\n+\t) > count.shallow &&\n+\tgrep \"^in-pack: 18\" count.shallow\n '\n \n-test_expect_success \"fsck in shallow repo\" \\\n-\t\"(cd shallow; git fsck --full)\"\n+test_expect_success 'clone shallow object count (part 2)' '\n+\tsed -e \"/^in-pack:/d\" -e \"/^packs:/d\" -e \"/^size-pack:/d\" \\\n+\t    -e \"/: 0$/d\" count.shallow > count_output &&\n+\t! test -s count_output\n+'\n \n-#test_done; exit\n+test_expect_success 'fsck in shallow repo' '\n+\t(\n+\t\tcd shallow &&\n+\t\tgit fsck --full\n+\t)\n+'\n \n-add B66 $B65\n-add B67 $B66\n+test_expect_success 'add two more' '\n+\tadd B66 $B65 &&\n+\tadd B67 $B66\n+'\n \n-test_expect_success \"pull in shallow repo\" \\\n-\t\"(cd shallow; git pull .. B)\"\n+test_expect_success 'pull in shallow repo' '\n+\t(\n+\t\tcd shallow &&\n+\t\tgit pull .. B\n+\t)\n+'\n \n-(cd shallow; git count-objects -v) > count.shallow\n-test_expect_success \"clone shallow object count\" \\\n-\t\"test \\\"count: 6\\\" = \\\"$(grep count count.shallow)\\\"\"\n+test_expect_success 'clone shallow object count' '\n+\t(\n+\t\tcd shallow &&\n+\t\tgit count-objects -v\n+\t) > count.shallow &&\n+\tgrep \"^count: 6\" count.shallow\n+'\n \n-add B68 $B67\n-add B69 $B68\n+test_expect_success 'add two more (part 2)' '\n+\tadd B68 $B67 &&\n+\tadd B69 $B68\n+'\n \n-test_expect_success \"deepening pull in shallow repo\" \\\n-\t\"(cd shallow; git pull --depth 4 .. B)\"\n+test_expect_success 'deepening pull in shallow repo' '\n+\t(\n+\t\tcd shallow &&\n+\t\tgit pull --depth 4 .. B\n+\t)\n+'\n \n-(cd shallow; git count-objects -v) > count.shallow\n-test_expect_success \"clone shallow object count\" \\\n-\t\"test \\\"count: 12\\\" = \\\"$(grep count count.shallow)\\\"\"\n+test_expect_success 'clone shallow object count' '\n+\t(\n+\t\tcd shallow &&\n+\t\tgit count-objects -v\n+\t) > count.shallow &&\n+\tgrep \"^count: 12\" count.shallow\n+'\n \n-test_expect_success \"deepening fetch in shallow repo\" \\\n-\t\"(cd shallow; git fetch --depth 4 .. A:A)\"\n+test_expect_success 'deepening fetch in shallow repo' '\n+\t(\n+\t\tcd shallow &&\n+\t\tgit fetch --depth 4 .. A:A\n+\t)\n+'\n \n-(cd shallow; git count-objects -v) > count.shallow\n-test_expect_success \"clone shallow object count\" \\\n-\t\"test \\\"count: 18\\\" = \\\"$(grep count count.shallow)\\\"\"\n+test_expect_success 'clone shallow object count' '\n+\t(\n+\t\tcd shallow &&\n+\t\tgit count-objects -v\n+\t) > count.shallow &&\n+\tgrep \"^count: 18\" count.shallow\n+'\n \n-test_expect_success \"pull in shallow repo with missing merge base\" \\\n-\t\"(cd shallow && test_must_fail git pull --depth 4 .. A)\"\n+test_expect_success 'pull in shallow repo with missing merge base' '\n+\t(\n+\t\tcd shallow &&\n+\t\ttest_must_fail git pull --depth 4 .. A\n+\t)\n+'\n \n test_done\n-- \n1.6.3.1.152.g9619f\n"}]}