2010-10-11 00:01:51 +03:00
|
|
|
# By Stephen Gildea, October 2010.
|
|
|
|
|
|
|
|
proc setup {} {
|
|
|
|
save_env
|
|
|
|
}
|
|
|
|
|
|
|
|
proc teardown {} {
|
|
|
|
assert_env_unmodified {
|
|
|
|
/declare -f fn/d
|
2011-11-24 23:26:52 +02:00
|
|
|
/PIPESTATUS=/d
|
2010-10-11 00:01:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setup
|
|
|
|
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' ""; }; _parse_help fn}
|
|
|
|
assert_bash_list "" $cmd "empty"
|
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "no dashes here"; }; _parse_help fn}
|
|
|
|
assert_bash_list "" $cmd "no dashes"
|
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "internal-dash"; }; _parse_help fn}
|
|
|
|
assert_bash_list "" $cmd "internal dash 1"
|
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "no -leading-dashes"; }; _parse_help fn}
|
|
|
|
assert_bash_list "" $cmd "no leading dash"
|
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "-one dash"; }; _parse_help fn}
|
|
|
|
assert_bash_list "-one" $cmd "one dash"
|
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' " -space dash"; }; _parse_help fn}
|
|
|
|
assert_bash_list "-space" $cmd "one dash after space"
|
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "-one -two dashes"; }; _parse_help fn}
|
2011-04-27 15:29:00 +03:00
|
|
|
assert_bash_list "-one" $cmd "two dashes, space-separated"
|
2010-10-11 00:01:51 +03:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "-one,-t dashes"; }; _parse_help fn}
|
2011-04-27 15:29:00 +03:00
|
|
|
assert_bash_list "-one" $cmd "two dashes, comma-separated"
|
2010-10-11 00:01:51 +03:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "-one dash-inside"; }; _parse_help fn}
|
|
|
|
assert_bash_list "-one" $cmd "internal dash 2"
|
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "--long-arg=value"; }; _parse_help fn}
|
2011-05-02 11:41:52 +03:00
|
|
|
assert_bash_list "--long-arg=" $cmd "value stripped"
|
2010-10-11 00:01:51 +03:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "--long-arg=-value"; }; _parse_help fn}
|
2011-05-02 11:41:52 +03:00
|
|
|
assert_bash_list "--long-arg=" $cmd "value not seen as option"
|
2010-10-11 00:01:51 +03:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "--long-arg=-value,--opt2=val"; }; _parse_help fn}
|
2011-05-02 11:41:52 +03:00
|
|
|
assert_bash_list "--long-arg=" $cmd "two options with values"
|
2010-10-11 00:01:51 +03:00
|
|
|
sync_after_int
|
|
|
|
|
2010-10-11 00:39:50 +03:00
|
|
|
set cmd {fn() { printf '%s\n' "-m,--mirror"; }; _parse_help fn}
|
2011-04-27 15:29:00 +03:00
|
|
|
assert_bash_list "--mirror" $cmd "short + long"
|
2010-10-11 00:39:50 +03:00
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "-T/--upload-file"; }; _parse_help fn}
|
2011-04-27 15:29:00 +03:00
|
|
|
assert_bash_list "--upload-file" $cmd "short + long, slash separated"
|
|
|
|
sync_after_int
|
|
|
|
|
2011-04-27 23:22:03 +03:00
|
|
|
set cmd {fn() { printf '%s\n' "-T|--upload-file"; }; _parse_help fn}
|
|
|
|
assert_bash_list "--upload-file" $cmd "pipe separated"
|
|
|
|
sync_after_int
|
|
|
|
|
2011-04-27 15:29:00 +03:00
|
|
|
set cmd {fn() { printf '%s\n' "-f, -F, --foo"; }; _parse_help fn}
|
|
|
|
assert_bash_list "--foo" $cmd "short + short + long"
|
2010-10-11 00:39:50 +03:00
|
|
|
sync_after_int
|
|
|
|
|
2011-04-27 21:44:04 +03:00
|
|
|
set cmd {fn() { printf '%s\n' "--foo[=bar]"; }; _parse_help fn}
|
|
|
|
assert_bash_list "--foo" $cmd "long with value and eq sign in brackets"
|
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "--foo=<bar>"; }; _parse_help fn}
|
2011-05-02 11:41:52 +03:00
|
|
|
assert_bash_list "--foo=" $cmd "long with value in angle brackets"
|
2011-04-27 21:44:04 +03:00
|
|
|
sync_after_int
|
|
|
|
|
2011-04-28 12:47:52 +03:00
|
|
|
set cmd {fn() { printf '%s\n' "--foo={bar,quux}"; }; _parse_help fn}
|
2011-05-02 11:41:52 +03:00
|
|
|
assert_bash_list "--foo=" $cmd "long with value in curly brackets"
|
2011-04-28 12:47:52 +03:00
|
|
|
sync_after_int
|
|
|
|
|
2011-04-29 11:47:48 +03:00
|
|
|
set cmd {fn() { printf '%s\n' "--[no]foo"; }; _parse_help fn}
|
|
|
|
assert_bash_list "--foo\n--nofoo" $cmd "long with \[no\]"
|
|
|
|
sync_after_int
|
|
|
|
|
2011-05-02 13:34:56 +03:00
|
|
|
set cmd {fn() { printf '%s\n' "--[no-]bar[=quux]"; }; _parse_help fn}
|
|
|
|
assert_bash_list "--bar\n--no-bar" $cmd "long with \[no-\] + optional arg"
|
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "--[no-]bar=quux"; }; _parse_help fn}
|
|
|
|
assert_bash_list "--bar=\n--no-bar=" $cmd "long with \[no-\] + required arg"
|
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "--[dont-]foo"; }; _parse_help fn}
|
|
|
|
assert_bash_list "--foo\n--dont-foo" $cmd "long with \[dont-\]"
|
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "-[dont]x, --[dont]yy"; }; _parse_help fn}
|
|
|
|
assert_bash_list "--yy\n--dontyy" $cmd "short and long with \[dont\]"
|
|
|
|
sync_after_int
|
|
|
|
|
2011-04-29 12:05:29 +03:00
|
|
|
set cmd {fn() { printf '%s\n' "----\n---foo\n----- bar"; }; _parse_help fn}
|
|
|
|
assert_bash_list "" $cmd "more than two dashes"
|
|
|
|
sync_after_int
|
|
|
|
|
2011-05-11 19:28:17 +03:00
|
|
|
set cmd {fn() { printf '%s\n' "-f FOO, --foo=FOO"; }; _parse_help fn}
|
|
|
|
assert_bash_list "--foo=" $cmd "-f FOO, --foo=FOO"
|
|
|
|
sync_after_int
|
|
|
|
|
|
|
|
set cmd {fn() { printf '%s\n' "-f [FOO], --foo[=FOO]"; }; _parse_help fn}
|
|
|
|
assert_bash_list "--foo" $cmd "-f \[FOO\], --foo\[=FOO\]"
|
|
|
|
sync_after_int
|
|
|
|
|
2011-06-18 15:44:43 +03:00
|
|
|
set cmd {fn() { printf '%s\n' "--foo."; }; _parse_help fn}
|
|
|
|
assert_bash_list "--foo" $cmd "--foo."
|
|
|
|
sync_after_int
|
|
|
|
|
2011-07-10 15:25:23 +03:00
|
|
|
set cmd {fn() { printf '%s\n' "-f or --foo"; }; _parse_help fn}
|
|
|
|
assert_bash_list "--foo" $cmd "-f or --foo"
|
|
|
|
sync_after_int
|
|
|
|
|
2011-11-24 23:26:52 +02:00
|
|
|
set cmd { printf '%s\n' "-f or --foo" | _parse_help - }
|
|
|
|
assert_bash_list "--foo" $cmd "from stdin"
|
|
|
|
sync_after_int
|
|
|
|
|
2010-10-11 00:01:51 +03:00
|
|
|
|
|
|
|
teardown
|