Code

Merge git://git.kernel.org/pub/scm/gitk/gitk
[git.git] / t / t0040-parse-options.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Johannes Schindelin
4 #
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)
23 EOF
25 test_expect_success 'test help' '
26         ! test-parse-options -h > output 2> output.err &&
27         test ! -s output &&
28         git diff expect.err output.err
29 '
31 cat > expect << EOF
32 boolean: 2
33 integer: 1729
34 string: 123
35 EOF
37 test_expect_success 'short options' '
38         test-parse-options -s123 -b -i 1729 -b > output 2> output.err &&
39         git diff expect output &&
40         test ! -s output.err
41 '
42 cat > expect << EOF
43 boolean: 2
44 integer: 1729
45 string: 321
46 EOF
48 test_expect_success 'long options' '
49         test-parse-options --boolean --integer 1729 --boolean --string2=321 \
50                 > output 2> output.err &&
51         test ! -s output.err &&
52         git diff expect output
53 '
55 cat > expect << EOF
56 boolean: 1
57 integer: 13
58 string: 123
59 arg 00: a1
60 arg 01: b1
61 arg 02: --boolean
62 EOF
64 test_expect_success 'intermingled arguments' '
65         test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
66                 > output 2> output.err &&
67         test ! -s output.err &&
68         git diff expect output
69 '
71 cat > expect << EOF
72 boolean: 0
73 integer: 2
74 string: (not set)
75 EOF
77 test_expect_success 'unambiguously abbreviated option' '
78         test-parse-options --int 2 --boolean --no-bo > output 2> output.err &&
79         test ! -s output.err &&
80         git diff expect output
81 '
83 test_expect_success 'unambiguously abbreviated option with "="' '
84         test-parse-options --int=2 > output 2> output.err &&
85         test ! -s output.err &&
86         git diff expect output
87 '
89 test_expect_failure 'ambiguously abbreviated option' '
90         test-parse-options --strin 123;
91         test $? != 129
92 '
94 cat > expect << EOF
95 boolean: 0
96 integer: 0
97 string: 123
98 EOF
100 test_expect_success 'non ambiguous option (after two options it abbreviates)' '
101         test-parse-options --st 123 > output 2> output.err &&
102         test ! -s output.err &&
103         git diff expect output
106 test_done