contrib/hooks/post-receive-email: reformat to wrap comments at 76 chars
[git/dscho.git] / t / t0040-parse-options.sh
blobae49424aa02a37df1b00813aa1478d570020c66b
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
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
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
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
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
70 cat > expect << EOF
71 boolean: 0
72 integer: 2
73 string: (not set)
74 EOF
76 test_expect_success 'unambiguously abbreviated option' '
77 test-parse-options --int 2 --boolean --no-bo > output 2> output.err &&
78 test ! -s output.err &&
79 git diff expect output
82 test_expect_success 'unambiguously abbreviated option with "="' '
83 test-parse-options --int=2 > output 2> output.err &&
84 test ! -s output.err &&
85 git diff expect output
88 test_expect_failure 'ambiguously abbreviated option' '
89 test-parse-options --strin 123;
90 test $? != 129
93 test_done