push test: simplify check of push result
authorJonathan Nieder <jrnieder@gmail.com>
Mon, 18 Mar 2013 23:13:41 +0000 (16:13 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 Mar 2013 18:07:26 +0000 (11:07 -0700)
This test checks each ref with code like the following:

r=$(git show-ref -s --verify refs/$ref) &&
test "z$r" = "z$the_first_commit"

Afterward it counts refs:

test 1 = $(git for-each-ref refs/remotes/origin | wc -l)

Simpler to test the number and values of relevant refs in for-each-ref
output at the same time using test_cmp. This makes the test more
readable and provides more helpful "./t5516-push-push.sh -v" output
when the test fails.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5516-fetch-push.sh
index 5b89c111f1fd7c950e3536c51f52d4856d61d154..2f1255d467192eb4e54dd065bf9ce956b842eab9 100755 (executable)
@@ -30,11 +30,10 @@ mk_test () {
                cd testrepo &&
                for ref in "$@"
                do
                cd testrepo &&
                for ref in "$@"
                do
-                       r=$(git show-ref -s --verify refs/$ref) &&
-                       test "z$r" = "z$the_first_commit" || {
-                               echo "Oops, refs/$ref is wrong"
-                               exit 1
-                       }
+                       echo "$the_first_commit" >expect &&
+                       git show-ref -s --verify refs/$ref >actual &&
+                       test_cmp expect actual ||
+                       exit
                done &&
                git fsck --full
        )
                done &&
                git fsck --full
        )
@@ -82,15 +81,13 @@ mk_child() {
 check_push_result () {
        (
                cd testrepo &&
 check_push_result () {
        (
                cd testrepo &&
-               it="$1" &&
-               shift
+               echo "$1" >expect &&
+               shift &&
                for ref in "$@"
                do
                for ref in "$@"
                do
-                       r=$(git show-ref -s --verify refs/$ref) &&
-                       test "z$r" = "z$it" || {
-                               echo "Oops, refs/$ref is wrong"
-                               exit 1
-                       }
+                       git show-ref -s --verify refs/$ref >actual &&
+                       test_cmp expect actual ||
+                       exit
                done &&
                git fsck --full
        )
                done &&
                git fsck --full
        )
@@ -118,10 +115,9 @@ test_expect_success 'fetch without wildcard' '
                cd testrepo &&
                git fetch .. refs/heads/master:refs/remotes/origin/master &&
 
                cd testrepo &&
                git fetch .. refs/heads/master:refs/remotes/origin/master &&
 
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
        )
 '
 
@@ -133,10 +129,9 @@ test_expect_success 'fetch with wildcard' '
                git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
                git fetch up &&
 
                git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
                git fetch up &&
 
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
        )
 '
 
@@ -150,10 +145,9 @@ test_expect_success 'fetch with insteadOf' '
                git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
                git fetch up &&
 
                git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
                git fetch up &&
 
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
        )
 '
 
@@ -167,10 +161,9 @@ test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
                git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
                git fetch up &&
 
                git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
                git fetch up &&
 
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
        )
 '
 
@@ -180,10 +173,9 @@ test_expect_success 'push without wildcard' '
        git push testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
        git push testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
        )
 '
 
@@ -193,10 +185,9 @@ test_expect_success 'push with wildcard' '
        git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
        (
                cd testrepo &&
        git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
        )
 '
 
@@ -207,10 +198,9 @@ test_expect_success 'push with insteadOf' '
        git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
        git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
        )
 '
 
@@ -221,10 +211,9 @@ test_expect_success 'push with pushInsteadOf' '
        git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
        git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
        )
 '
 
@@ -237,10 +226,9 @@ test_expect_success 'push with pushInsteadOf and explicit pushurl (pushInsteadOf
        git push r refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
        git push r refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        )
 '
 
        )
 '
 
@@ -827,9 +815,9 @@ test_expect_success 'fetch with branches' '
        (
                cd testrepo &&
                git fetch branch1 &&
        (
                cd testrepo &&
                git fetch branch1 &&
-               r=$(git show-ref -s --verify refs/heads/branch1) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/heads | wc -l)
+               echo "$the_commit commit        refs/heads/branch1" >expect &&
+               git for-each-ref refs/heads >actual &&
+               test_cmp expect actual
        ) &&
        git checkout master
 '
        ) &&
        git checkout master
 '
@@ -840,9 +828,9 @@ test_expect_success 'fetch with branches containing #' '
        (
                cd testrepo &&
                git fetch branch2 &&
        (
                cd testrepo &&
                git fetch branch2 &&
-               r=$(git show-ref -s --verify refs/heads/branch2) &&
-               test "z$r" = "z$the_first_commit" &&
-               test 1 = $(git for-each-ref refs/heads | wc -l)
+               echo "$the_first_commit commit  refs/heads/branch2" >expect &&
+               git for-each-ref refs/heads >actual &&
+               test_cmp expect actual
        ) &&
        git checkout master
 '
        ) &&
        git checkout master
 '
@@ -854,9 +842,9 @@ test_expect_success 'push with branches' '
        git push branch1 &&
        (
                cd testrepo &&
        git push branch1 &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/heads/master) &&
-               test "z$r" = "z$the_first_commit" &&
-               test 1 = $(git for-each-ref refs/heads | wc -l)
+               echo "$the_first_commit commit  refs/heads/master" >expect &&
+               git for-each-ref refs/heads >actual &&
+               test_cmp expect actual
        )
 '
 
        )
 '
 
@@ -866,9 +854,9 @@ test_expect_success 'push with branches containing #' '
        git push branch2 &&
        (
                cd testrepo &&
        git push branch2 &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/heads/branch3) &&
-               test "z$r" = "z$the_first_commit" &&
-               test 1 = $(git for-each-ref refs/heads | wc -l)
+               echo "$the_first_commit commit  refs/heads/branch3" >expect &&
+               git for-each-ref refs/heads >actual &&
+               test_cmp expect actual
        ) &&
        git checkout master
 '
        ) &&
        git checkout master
 '
@@ -951,9 +939,9 @@ test_expect_success 'push --porcelain' '
        git push >.git/bar --porcelain  testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
        git push >.git/bar --porcelain  testrepo refs/heads/master:refs/remotes/origin/master &&
        (
                cd testrepo &&
-               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
-               test "z$r" = "z$the_commit" &&
-               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+               echo "$the_commit commit        refs/remotes/origin/master" >expect &&
+               git for-each-ref refs/remotes/origin >actual &&
+               test_cmp expect actual
        ) &&
        test_cmp .git/foo .git/bar
 '
        ) &&
        test_cmp .git/foo .git/bar
 '