2011-12-07 19:37:13 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
test_description="argument parsing"
|
2017-09-25 22:38:19 +02:00
|
|
|
. $(dirname "$0")/test-lib.sh || exit 1
|
2011-12-07 19:37:13 +01:00
|
|
|
|
2023-04-09 16:26:26 +02:00
|
|
|
if [ -n "${NOTMUCH_TEST_INSTALLED-}" ]; then
|
|
|
|
test_done
|
|
|
|
fi
|
|
|
|
|
2011-12-07 19:37:13 +01:00
|
|
|
test_begin_subtest "sanity check"
|
2021-01-16 02:29:17 +01:00
|
|
|
$TEST_DIRECTORY/arg-test pos1 --keyword=one --boolean --string=foo pos2 --int=7 --flag=one --flag=three > OUTPUT
|
2011-12-07 19:37:13 +01:00
|
|
|
cat <<EOF > EXPECTED
|
2017-10-01 22:53:12 +02:00
|
|
|
boolean 1
|
2011-12-07 19:37:13 +01:00
|
|
|
keyword 1
|
2014-10-31 22:53:56 +01:00
|
|
|
flags 5
|
2011-12-07 19:37:13 +01:00
|
|
|
int 7
|
|
|
|
string foo
|
|
|
|
positional arg 1 pos1
|
2012-12-03 23:54:52 +01:00
|
|
|
positional arg 2 pos2
|
2011-12-07 19:37:13 +01:00
|
|
|
EOF
|
2017-04-05 02:36:29 +02:00
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
2011-12-07 19:37:13 +01:00
|
|
|
|
2017-10-01 22:53:15 +02:00
|
|
|
test_begin_subtest "sanity check zero values"
|
|
|
|
$TEST_DIRECTORY/arg-test --keyword=zero --boolean=false --int=0 > OUTPUT
|
|
|
|
cat <<EOF > EXPECTED
|
|
|
|
boolean 0
|
|
|
|
keyword 0
|
|
|
|
int 0
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
|
|
|
|
|
|
|
test_begin_subtest "space instead of = between parameter name and value"
|
|
|
|
# Note: spaces aren't allowed for booleans. false turns into a positional arg!
|
|
|
|
$TEST_DIRECTORY/arg-test --keyword one --boolean false --string foo --int 7 --flag one --flag three > OUTPUT
|
|
|
|
cat <<EOF > EXPECTED
|
|
|
|
boolean 1
|
|
|
|
keyword 1
|
|
|
|
flags 5
|
|
|
|
int 7
|
|
|
|
string foo
|
|
|
|
positional arg 1 false
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
|
|
|
|
2017-10-14 15:16:08 +02:00
|
|
|
test_begin_subtest "--boolean=true"
|
|
|
|
$TEST_DIRECTORY/arg-test --boolean=true > OUTPUT
|
|
|
|
cat <<EOF > EXPECTED
|
|
|
|
boolean 1
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
|
|
|
|
|
|
|
test_begin_subtest "--boolean=false"
|
|
|
|
$TEST_DIRECTORY/arg-test --boolean=false > OUTPUT
|
|
|
|
cat <<EOF > EXPECTED
|
|
|
|
boolean 0
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
|
|
|
|
|
|
|
test_begin_subtest "--no-boolean"
|
|
|
|
$TEST_DIRECTORY/arg-test --no-boolean > OUTPUT
|
|
|
|
cat <<EOF > EXPECTED
|
|
|
|
boolean 0
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
|
|
|
|
|
|
|
test_begin_subtest "--no-flag"
|
|
|
|
$TEST_DIRECTORY/arg-test --flag=one --flag=three --no-flag=three > OUTPUT
|
|
|
|
cat <<EOF > EXPECTED
|
|
|
|
flags 1
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
|
|
|
|
2017-12-25 19:42:26 +01:00
|
|
|
test_begin_subtest "test keyword arguments without value"
|
|
|
|
$TEST_DIRECTORY/arg-test --boolkeyword bananas > OUTPUT
|
|
|
|
cat <<EOF > EXPECTED
|
|
|
|
boolkeyword 1
|
|
|
|
positional arg 1 bananas
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
|
|
|
|
2018-03-18 03:30:25 +01:00
|
|
|
test_begin_subtest "test keyword arguments with non-default value separated by a space"
|
2017-12-25 19:42:26 +01:00
|
|
|
$TEST_DIRECTORY/arg-test --boolkeyword false bananas > OUTPUT
|
|
|
|
cat <<EOF > EXPECTED
|
|
|
|
boolkeyword 0
|
|
|
|
positional arg 1 bananas
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
|
|
|
|
|
|
|
test_begin_subtest "test keyword arguments without value at the end"
|
|
|
|
$TEST_DIRECTORY/arg-test bananas --boolkeyword > OUTPUT
|
|
|
|
cat <<EOF > EXPECTED
|
|
|
|
boolkeyword 1
|
|
|
|
positional arg 1 bananas
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
|
|
|
|
|
|
|
test_begin_subtest "test keyword arguments without value but with = (should be an error)"
|
|
|
|
$TEST_DIRECTORY/arg-test bananas --boolkeyword= > OUTPUT 2>&1
|
|
|
|
cat <<EOF > EXPECTED
|
|
|
|
Unknown keyword argument "" for option "boolkeyword".
|
|
|
|
Unrecognized option: --boolkeyword=
|
|
|
|
EOF
|
|
|
|
test_expect_equal_file EXPECTED OUTPUT
|
|
|
|
|
2011-12-07 19:37:13 +01:00
|
|
|
test_done
|