Update draft release notes for 1.5.4.4
[alt-git.git] / t / t0040-parse-options.sh
blob0a3b55d1212ddeda87f1f3ffa4c4e2fbefb44553
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 EOF
26 test_expect_success 'test help' '
27 ! test-parse-options -h > output 2> output.err &&
28 test ! -s output &&
29 git diff expect.err output.err
32 cat > expect << EOF
33 boolean: 2
34 integer: 1729
35 string: 123
36 EOF
38 test_expect_success 'short options' '
39 test-parse-options -s123 -b -i 1729 -b > output 2> output.err &&
40 git diff expect output &&
41 test ! -s output.err
43 cat > expect << EOF
44 boolean: 2
45 integer: 1729
46 string: 321
47 EOF
49 test_expect_success 'long options' '
50 test-parse-options --boolean --integer 1729 --boolean --string2=321 \
51 > output 2> output.err &&
52 test ! -s output.err &&
53 git diff expect output
56 cat > expect << EOF
57 boolean: 1
58 integer: 13
59 string: 123
60 arg 00: a1
61 arg 01: b1
62 arg 02: --boolean
63 EOF
65 test_expect_success 'intermingled arguments' '
66 test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
67 > output 2> output.err &&
68 test ! -s output.err &&
69 git diff expect output
72 cat > expect << EOF
73 boolean: 0
74 integer: 2
75 string: (not set)
76 EOF
78 test_expect_success 'unambiguously abbreviated option' '
79 test-parse-options --int 2 --boolean --no-bo > output 2> output.err &&
80 test ! -s output.err &&
81 git diff expect output
84 test_expect_success 'unambiguously abbreviated option with "="' '
85 test-parse-options --int=2 > output 2> output.err &&
86 test ! -s output.err &&
87 git diff expect output
90 test_expect_failure 'ambiguously abbreviated option' '
91 test-parse-options --strin 123;
92 test $? != 129
95 cat > expect << EOF
96 boolean: 0
97 integer: 0
98 string: 123
99 EOF
101 test_expect_success 'non ambiguous option (after two options it abbreviates)' '
102 test-parse-options --st 123 > output 2> output.err &&
103 test ! -s output.err &&
104 git diff expect output
107 cat > expect.err << EOF
108 error: did you mean \`--boolean\` (with two dashes ?)
111 test_expect_success 'detect possible typos' '
112 ! test-parse-options -boolean > output 2> output.err &&
113 test ! -s output &&
114 git diff expect.err output.err
117 test_done