Skip to content

Commit f130e2d

Browse files
author
John Cai
committed
catfile: test --stdin-cmd success and failure
WIP: Add tests that verify the behavior of the object command in --stdin-cmd mode. Signed-off-by: John Cai <johncai86@gmail.com>
1 parent 3a11e0b commit f130e2d

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

t/t1006-cat-file.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,4 +964,70 @@ test_expect_success 'cat-file --batch-all-objects --batch-check ignores replace'
964964
test_cmp expect actual
965965
'
966966

967+
F='%s\0'
968+
969+
test_expect_sucess 'stdin-cmd not enough arguments' '
970+
echo 'object ' >cmd &&
971+
test_expect_code 128 git cat-file --batch --stdin-cmd < cmd 2>err &&
972+
grep -E "^fatal:.*too few arguments for object" err
973+
'
974+
975+
test_expect_success 'stdin-cmd unknown command' '
976+
echo unknown_command >cmd &&
977+
test_expect_code 128 git cat-file --batch --stdin-cmd < cmd 2>err &&
978+
grep -E "^fatal:.*unknown command.*" err &&
979+
test_expect_code 128 git cat-file --batch --stdin-cmd -z < cmd 2>err &&
980+
grep -E "^fatal:.*unknown command.*" err
981+
'
982+
983+
test_expect_success 'setup object data' '
984+
content="Object Data" &&
985+
size=$(strlen "$content") &&
986+
sha1=$(echo_without_newline "$content" | git hash-object -w --stdin)
987+
'
988+
989+
test_expect_success 'stdin-cmd calling object works' '
990+
echo "object $sha1" | git cat-file --batch --stdin-cmd >actual &&
991+
echo "$sha1 blob $size" >expect &&
992+
echo `git cat-file -p "$sha1"` >>expect &&
993+
test_cmp expect actual
994+
'
995+
996+
test_expect_success 'stdin-cmd -z calling object works' '
997+
printf $F "object $sha1" | git cat-file --batch --stdin-cmd -z >actual &&
998+
echo "$sha1 blob $size" >expect &&
999+
echo `git cat-file -p "$sha1"` >>expect &&
1000+
test_cmp expect actual
1001+
'
1002+
1003+
test_expect_success 'setup object data' '
1004+
content="Object Data" &&
1005+
size=$(strlen "$content") &&
1006+
sha1=$(echo_without_newline "$content" | git hash-object -w --stdin)
1007+
'
1008+
1009+
test_expect_success 'stdin-cmd calling object works' '
1010+
echo "object $sha1" | git cat-file --batch --stdin-cmd >actual &&
1011+
echo "$sha1 blob $size" >expect &&
1012+
echo `git cat-file -p "$sha1"` >>expect &&
1013+
test_cmp expect actual
1014+
'
1015+
1016+
test_expect_success 'stdin-cmd -z calling object works' '
1017+
printf $F "object $sha1" | git cat-file --batch --stdin-cmd -z >actual &&
1018+
echo "$sha1 blob $size" >expect &&
1019+
echo `git cat-file -p "$sha1"` >>expect &&
1020+
test_cmp expect actual
1021+
'
1022+
1023+
test_expect_success 'stdin-cmd fflush works' '
1024+
printf "fflush\n" > cmd &&
1025+
test_expect_code 0 git cat-file --batch --stdin-cmd < cmd 2>err
1026+
'
1027+
1028+
test_expect_success 'stdin-cmd -z fflush works' '
1029+
printf $F 'fflush' > cmd &&
1030+
test_expect_code 0 git cat-file --batch --stdin-cmd -z < cmd 2>err
1031+
'
1032+
9671033
test_done

0 commit comments

Comments
 (0)