tests: make test_must_fail more verbose
[gitweb.git] / t / t1006-cat-file.sh
index 0f7cc0371d78d0dc21048435f44fd5a85a909c24..d8b7f2ffbcc0427b1ae9d48feb4387f580e81d61 100755 (executable)
@@ -28,6 +28,9 @@ run_tests () {
     pretty_content=$5
     no_ts=$6
 
+    batch_output="$sha1 $type $size
+$content"
+
     test_expect_success "$type exists" '
        git cat-file -e $sha1
     '
@@ -67,6 +70,33 @@ run_tests () {
                false
         fi
     '
+
+    test -z "$content" ||
+    test_expect_success "--batch output of $type is correct" '
+       expect="$(maybe_remove_timestamp "$batch_output" $no_ts)"
+       actual="$(maybe_remove_timestamp "$(echo $sha1 | git cat-file --batch)" $no_ts)"
+        if test "z$expect" = "z$actual"
+       then
+               : happy
+       else
+               echo "Oops: expected $expect"
+               echo "but got $actual"
+               false
+        fi
+    '
+
+    test_expect_success "--batch-check output of $type is correct" '
+       expect="$sha1 $type $size"
+       actual="$(echo_without_newline $sha1 | git cat-file --batch-check)"
+        if test "z$expect" = "z$actual"
+       then
+               : happy
+       else
+               echo "Oops: expected $expect"
+               echo "but got $actual"
+               false
+        fi
+    '
 }
 
 hello_content="Hello World"
@@ -118,4 +148,97 @@ test_expect_success \
     "Reach a blob from a tag pointing to it" \
     "test '$hello_content' = \"\$(git cat-file blob $tag_sha1)\""
 
+for batch in batch batch-check
+do
+    for opt in t s e p
+    do
+       test_expect_success "Passing -$opt with --$batch fails" '
+           test_must_fail git cat-file --$batch -$opt $hello_sha1
+       '
+
+       test_expect_success "Passing --$batch with -$opt fails" '
+           test_must_fail git cat-file -$opt --$batch $hello_sha1
+       '
+    done
+
+    test_expect_success "Passing <type> with --$batch fails" '
+       test_must_fail git cat-file --$batch blob $hello_sha1
+    '
+
+    test_expect_success "Passing --$batch with <type> fails" '
+       test_must_fail git cat-file blob --$batch $hello_sha1
+    '
+
+    test_expect_success "Passing sha1 with --$batch fails" '
+       test_must_fail git cat-file --$batch $hello_sha1
+    '
+done
+
+test_expect_success "--batch-check for a non-existent named object" '
+    test "foobar42 missing
+foobar84 missing" = \
+    "$( ( echo foobar42; echo_without_newline foobar84; ) | git cat-file --batch-check)"
+'
+
+test_expect_success "--batch-check for a non-existent hash" '
+    test "0000000000000000000000000000000000000042 missing
+0000000000000000000000000000000000000084 missing" = \
+    "$( ( echo 0000000000000000000000000000000000000042;
+         echo_without_newline 0000000000000000000000000000000000000084; ) \
+       | git cat-file --batch-check)"
+'
+
+test_expect_success "--batch for an existent and a non-existent hash" '
+    test "$tag_sha1 tag $tag_size
+$tag_content
+0000000000000000000000000000000000000000 missing" = \
+    "$( ( echo $tag_sha1;
+         echo_without_newline 0000000000000000000000000000000000000000; ) \
+       | git cat-file --batch)"
+'
+
+test_expect_success "--batch-check for an emtpy line" '
+    test " missing" = "$(echo | git cat-file --batch-check)"
+'
+
+batch_input="$hello_sha1
+$commit_sha1
+$tag_sha1
+deadbeef
+
+"
+
+batch_output="$hello_sha1 blob $hello_size
+$hello_content
+$commit_sha1 commit $commit_size
+$commit_content
+$tag_sha1 tag $tag_size
+$tag_content
+deadbeef missing
+ missing"
+
+test_expect_success '--batch with multiple sha1s gives correct format' '
+       test "$(maybe_remove_timestamp "$batch_output" 1)" = "$(maybe_remove_timestamp "$(echo_without_newline "$batch_input" | git cat-file --batch)" 1)"
+'
+
+batch_check_input="$hello_sha1
+$tree_sha1
+$commit_sha1
+$tag_sha1
+deadbeef
+
+"
+
+batch_check_output="$hello_sha1 blob $hello_size
+$tree_sha1 tree $tree_size
+$commit_sha1 commit $commit_size
+$tag_sha1 tag $tag_size
+deadbeef missing
+ missing"
+
+test_expect_success "--batch-check with multiple sha1s gives correct format" '
+    test "$batch_check_output" = \
+    "$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)"
+'
+
 test_done