Code

8e4d74b2005b4c55eefc460d47ed121f664b85f5
[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
22 EOF
24 test_expect_success 'test help' '
25         ! test-parse-options -h > output 2> output.err &&
26         test ! -s output &&
27         git diff expect.err output.err
28 '
30 cat > expect << EOF
31 boolean: 2
32 integer: 1729
33 string: 123
34 EOF
36 test_expect_success 'short options' '
37         test-parse-options -s123 -b -i 1729 -b > output 2> output.err &&
38         git diff expect output &&
39         test ! -s output.err
40 '
41 cat > expect << EOF
42 boolean: 2
43 integer: 1729
44 string: 321
45 EOF
47 test_expect_success 'long options' '
48         test-parse-options --boolean --integer 1729 --boolean --string2=321 \
49                 > output 2> output.err &&
50         test ! -s output.err &&
51         git diff expect output
52 '
54 cat > expect << EOF
55 boolean: 1
56 integer: 13
57 string: 123
58 arg 00: a1
59 arg 01: b1
60 arg 02: --boolean
61 EOF
63 test_expect_success 'intermingled arguments' '
64         test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
65                 > output 2> output.err &&
66         test ! -s output.err &&
67         git diff expect output
68 '
70 test_done