summaryrefslogtreecommitdiff
path: root/t/t0040-parse-options.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t0040-parse-options.sh')
-rwxr-xr-xt/t0040-parse-options.sh75
1 files changed, 71 insertions, 4 deletions
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index e38241c..bbc821e 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -12,12 +12,14 @@ usage: test-parse-options <options>
-b, --boolean get a boolean
-4, --or4 bitwise-or boolean with ...0100
+ --neg-or4 same as --no-or4
-i, --integer <n> get a integer
-j <n> get a integer, too
--set23 set integer to 23
-t <time> get timestamp of <time>
-L, --length <str> get length of <str>
+ -F, --file <FILE> set file to <FILE>
String options
-s, --string <string>
@@ -29,6 +31,8 @@ String options
Magic arguments
--quux means --quux
+ -NUM set integer to NUM
+ + same as -b
Standard options
--abbrev[=<n>] use <n> digits to display SHA-1s
@@ -53,10 +57,12 @@ abbrev: 7
verbose: 2
quiet: no
dry run: yes
+file: prefix/my.file
EOF
test_expect_success 'short options' '
- test-parse-options -s123 -b -i 1729 -b -vv -n > output 2> output.err &&
+ test-parse-options -s123 -b -i 1729 -b -vv -n -F my.file \
+ > output 2> output.err &&
test_cmp expect output &&
test ! -s output.err
'
@@ -70,11 +76,12 @@ abbrev: 10
verbose: 2
quiet: no
dry run: no
+file: prefix/fi.le
EOF
test_expect_success 'long options' '
test-parse-options --boolean --integer 1729 --boolean --string2=321 \
- --verbose --verbose --no-dry-run --abbrev=10 \
+ --verbose --verbose --no-dry-run --abbrev=10 --file fi.le\
> output 2> output.err &&
test ! -s output.err &&
test_cmp expect output
@@ -84,6 +91,8 @@ test_expect_success 'missing required value' '
test-parse-options -s;
test $? = 129 &&
test-parse-options --string;
+ test $? = 129 &&
+ test-parse-options --file;
test $? = 129
'
@@ -96,6 +105,7 @@ abbrev: 7
verbose: 0
quiet: no
dry run: no
+file: (not set)
arg 00: a1
arg 01: b1
arg 02: --boolean
@@ -117,6 +127,7 @@ abbrev: 7
verbose: 0
quiet: no
dry run: no
+file: (not set)
EOF
test_expect_success 'unambiguously abbreviated option' '
@@ -145,6 +156,7 @@ abbrev: 7
verbose: 0
quiet: no
dry run: no
+file: (not set)
EOF
test_expect_success 'non ambiguous option (after two options it abbreviates)' '
@@ -172,6 +184,7 @@ abbrev: 7
verbose: 0
quiet: no
dry run: no
+file: (not set)
arg 00: --quux
EOF
@@ -190,6 +203,7 @@ abbrev: 7
verbose: 0
quiet: yes
dry run: no
+file: (not set)
arg 00: foo
EOF
@@ -210,6 +224,7 @@ abbrev: 7
verbose: 0
quiet: no
dry run: no
+file: (not set)
EOF
test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' '
@@ -237,6 +252,7 @@ abbrev: 7
verbose: 0
quiet: no
dry run: no
+file: (not set)
EOF
test_expect_success 'OPT_BIT() and OPT_SET_INT() work' '
@@ -245,7 +261,58 @@ test_expect_success 'OPT_BIT() and OPT_SET_INT() work' '
test_cmp expect output
'
-# --or4
-# --no-or4
+test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' '
+ test-parse-options --set23 -bbbbb --neg-or4 > output 2> output.err &&
+ test ! -s output.err &&
+ test_cmp expect output
+'
+
+cat > expect <<EOF
+boolean: 6
+integer: 0
+timestamp: 0
+string: (not set)
+abbrev: 7
+verbose: 0
+quiet: no
+dry run: no
+file: (not set)
+EOF
+
+test_expect_success 'OPT_BIT() works' '
+ test-parse-options -bb --or4 > output 2> output.err &&
+ test ! -s output.err &&
+ test_cmp expect output
+'
+
+test_expect_success 'OPT_NEGBIT() works' '
+ test-parse-options -bb --no-neg-or4 > output 2> output.err &&
+ test ! -s output.err &&
+ test_cmp expect output
+'
+
+test_expect_success 'OPT_BOOLEAN() with PARSE_OPT_NODASH works' '
+ test-parse-options + + + + + + > output 2> output.err &&
+ test ! -s output.err &&
+ test_cmp expect output
+'
+
+cat > expect <<EOF
+boolean: 0
+integer: 12345
+timestamp: 0
+string: (not set)
+abbrev: 7
+verbose: 0
+quiet: no
+dry run: no
+file: (not set)
+EOF
+
+test_expect_success 'OPT_NUMBER_CALLBACK() works' '
+ test-parse-options -12345 > output 2> output.err &&
+ test ! -s output.err &&
+ test_cmp expect output
+'
test_done