2 test_description="argument parsing"
3 . $(dirname "$0")/test-lib.sh || exit 1
5 test_begin_subtest "sanity check"
6 $TEST_DIRECTORY/arg-test pos1 --keyword=one --boolean --string=foo pos2 --int=7 --flag=one --flag=three > OUTPUT
16 test_expect_equal_file EXPECTED OUTPUT
18 test_begin_subtest "sanity check zero values"
19 $TEST_DIRECTORY/arg-test --keyword=zero --boolean=false --int=0 > OUTPUT
25 test_expect_equal_file EXPECTED OUTPUT
27 test_begin_subtest "space instead of = between parameter name and value"
28 # Note: spaces aren't allowed for booleans. false turns into a positional arg!
29 $TEST_DIRECTORY/arg-test --keyword one --boolean false --string foo --int 7 --flag one --flag three > OUTPUT
36 positional arg 1 false
38 test_expect_equal_file EXPECTED OUTPUT
40 test_begin_subtest "--boolean=true"
41 $TEST_DIRECTORY/arg-test --boolean=true > OUTPUT
45 test_expect_equal_file EXPECTED OUTPUT
47 test_begin_subtest "--boolean=false"
48 $TEST_DIRECTORY/arg-test --boolean=false > OUTPUT
52 test_expect_equal_file EXPECTED OUTPUT
54 test_begin_subtest "--no-boolean"
55 $TEST_DIRECTORY/arg-test --no-boolean > OUTPUT
59 test_expect_equal_file EXPECTED OUTPUT
61 test_begin_subtest "--no-flag"
62 $TEST_DIRECTORY/arg-test --flag=one --flag=three --no-flag=three > OUTPUT
66 test_expect_equal_file EXPECTED OUTPUT
68 test_begin_subtest "test keyword arguments without value"
69 $TEST_DIRECTORY/arg-test --boolkeyword bananas > OUTPUT
72 positional arg 1 bananas
74 test_expect_equal_file EXPECTED OUTPUT
76 test_begin_subtest "test keyword arguments with non-default value separated by a space"
77 $TEST_DIRECTORY/arg-test --boolkeyword false bananas > OUTPUT
80 positional arg 1 bananas
82 test_expect_equal_file EXPECTED OUTPUT
84 test_begin_subtest "test keyword arguments without value at the end"
85 $TEST_DIRECTORY/arg-test bananas --boolkeyword > OUTPUT
88 positional arg 1 bananas
90 test_expect_equal_file EXPECTED OUTPUT
92 test_begin_subtest "test keyword arguments without value but with = (should be an error)"
93 $TEST_DIRECTORY/arg-test bananas --boolkeyword= > OUTPUT 2>&1
95 Unknown keyword argument "" for option "boolkeyword".
96 Unrecognized option: --boolkeyword=
98 test_expect_equal_file EXPECTED OUTPUT