t5300-pack-object: Set up the objects for --strict tests only once.
[git/mingw.git] / t / t0040-parse-options.sh
blobc23f0ace85c83f54fd7562d72af6ef6c1ea2eca3
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes Schindelin
6 test_description='our own option parser'
8 . ./test-lib.sh
10 cat > expect.err << EOF
11 usage: test-parse-options <options>
13 -b, --boolean get a boolean
14 -i, --integer <n> get a integer
15 -j <n> get a integer, too
17 string options
18 -s, --string <string>
19 get a string
20 --string2 <str> get another string
21 --st <st> get another string (pervert ordering)
22 -o <str> get another string
24 magic arguments
25 --quux means --quux
27 EOF
29 test_expect_success 'test help' '
30 ! test-parse-options -h > output 2> output.err &&
31 test ! -s output &&
32 git diff expect.err output.err
35 cat > expect << EOF
36 boolean: 2
37 integer: 1729
38 string: 123
39 EOF
41 test_expect_success 'short options' '
42 test-parse-options -s123 -b -i 1729 -b > output 2> output.err &&
43 git diff expect output &&
44 test ! -s output.err
46 cat > expect << EOF
47 boolean: 2
48 integer: 1729
49 string: 321
50 EOF
52 test_expect_success 'long options' '
53 test-parse-options --boolean --integer 1729 --boolean --string2=321 \
54 > output 2> output.err &&
55 test ! -s output.err &&
56 git diff expect output
59 cat > expect << EOF
60 boolean: 1
61 integer: 13
62 string: 123
63 arg 00: a1
64 arg 01: b1
65 arg 02: --boolean
66 EOF
68 test_expect_success 'intermingled arguments' '
69 test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
70 > output 2> output.err &&
71 test ! -s output.err &&
72 git diff expect output
75 cat > expect << EOF
76 boolean: 0
77 integer: 2
78 string: (not set)
79 EOF
81 test_expect_success 'unambiguously abbreviated option' '
82 test-parse-options --int 2 --boolean --no-bo > output 2> output.err &&
83 test ! -s output.err &&
84 git diff expect output
87 test_expect_success 'unambiguously abbreviated option with "="' '
88 test-parse-options --int=2 > output 2> output.err &&
89 test ! -s output.err &&
90 git diff expect output
93 test_expect_success 'ambiguously abbreviated option' '
94 test-parse-options --strin 123;
95 test $? = 129
98 cat > expect << EOF
99 boolean: 0
100 integer: 0
101 string: 123
104 test_expect_success 'non ambiguous option (after two options it abbreviates)' '
105 test-parse-options --st 123 > output 2> output.err &&
106 test ! -s output.err &&
107 git diff expect output
110 cat > expect.err << EOF
111 error: did you mean \`--boolean\` (with two dashes ?)
114 test_expect_success 'detect possible typos' '
115 ! test-parse-options -boolean > output 2> output.err &&
116 test ! -s output &&
117 git diff expect.err output.err
120 cat > expect <<EOF
121 boolean: 0
122 integer: 0
123 string: (not set)
124 arg 00: --quux
127 test_expect_success 'keep some options as arguments' '
128 test-parse-options --quux > output 2> output.err &&
129 test ! -s output.err &&
130 git diff expect output
133 test_done