4
5
. ./test-lib.sh
6
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
+
101
echo_without_newline () {
102
printf '%s' "$*"
103
}