Skip to content

Commit ddf8420

Browse files
avargitster
authored andcommitted
cat-file tests: test bad usage
Stress test the usage emitted when options are combined in ways that isn't supported. Let's test various option combinations, some of these we buggily allow right now. E.g. this reveals a bug in 3214594 (cat-file: support --textconv/--filters in batch mode, 2016-09-09) that we'll fix in a subsequent commit. We're supposed to be emitting a relevant message when --batch-all-objects is combined with --textconv or --filters, but we don't. The cases of needing to assign to opt=2 in the "opt" loop are because on those we do the right thing already, in subsequent commits the "test_expect_failure" cases will be fixed, and the for-loops unified. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent abe6bb3 commit ddf8420

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

t/t1006-cat-file.sh

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,100 @@ test_description='git cat-file'
44

55
. ./test-lib.sh
66

7+
test_cmdmode_usage () {
8+
test_expect_code 129 "$@" 2>err &&
9+
grep "^error:.*is incompatible with" err
10+
}
11+
12+
for switches in \
13+
'-e -p' \
14+
'-p -t' \
15+
'-t -s' \
16+
'-s --textconv' \
17+
'--textconv --filters'
18+
do
19+
test_expect_success "usage: cmdmode $switches" '
20+
test_cmdmode_usage git cat-file $switches
21+
'
22+
done
23+
24+
test_incompatible_usage () {
25+
test_expect_code 129 "$@" 2>err &&
26+
grep -E "^error:.**needs" err
27+
}
28+
29+
for opt in --batch --batch-check
30+
do
31+
test_expect_success "usage: incompatible options: --path with $opt" '
32+
test_incompatible_usage git cat-file --path=foo $opt
33+
'
34+
done
35+
36+
short_modes="-e -p -t -s"
37+
cw_modes="--textconv --filters"
38+
39+
for opt in $cw_modes
40+
do
41+
test_expect_success "usage: $opt requires another option" '
42+
test_expect_code 129 git cat-file $opt
43+
'
44+
45+
test_expect_failure "usage: incompatible options: --batch-all-objects with $opt" '
46+
test_incompatible_usage git cat-file --batch-all-objects $opt
47+
'
48+
done
49+
50+
for opt in $short_modes
51+
do
52+
test_expect_success "usage: $opt requires another option" '
53+
test_expect_code 129 git cat-file $opt
54+
'
55+
56+
for opt2 in --batch \
57+
--batch-check \
58+
--follow-symlinks
59+
do
60+
test_expect_failure "usage: incompatible options: $opt and $opt2" '
61+
test_incompatible_usage git cat-file $opt $opt2
62+
'
63+
done
64+
65+
opt2="--path=foo HEAD:some-path.txt"
66+
test_expect_success "usage: incompatible options: $opt and $opt2" '
67+
test_incompatible_usage git cat-file $opt $opt2
68+
'
69+
done
70+
71+
for opt in $short_modes $cw_modes
72+
do
73+
args="one two three"
74+
test_expect_success "usage: too many arguments: $opt $args" '
75+
test_expect_code 129 git cat-file $opt $args
76+
'
77+
78+
for opt2 in --buffer --follow-symlinks
79+
do
80+
test_expect_success "usage: incompatible arguments: $opt with batch option $opt2" '
81+
test_expect_code 129 git cat-file $opt $opt2
82+
'
83+
done
84+
done
85+
86+
for opt in --buffer \
87+
--follow-symlinks \
88+
--batch-all-objects
89+
do
90+
status=success
91+
if test $opt = "--buffer"
92+
then
93+
status=failure
94+
fi
95+
test_expect_$status "usage: bad option combination: $opt without batch mode" '
96+
test_expect_code 129 git cat-file $opt &&
97+
test_expect_code 129 git cat-file $opt commit HEAD
98+
'
99+
done
100+
7101
echo_without_newline () {
8102
printf '%s' "$*"
9103
}

0 commit comments

Comments
 (0)