mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-18 09:43:09 +00:00
Handle values with spaces. Still needs work; one test is failing.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
TESTS=37
|
||||
TESTS=44
|
||||
|
||||
TMPFILE="$TEST_TMPDIR/parse-opts-output"
|
||||
TOOL="pt-stalk"
|
||||
@@ -13,7 +13,7 @@ source "$LIB_DIR/parse_options.sh"
|
||||
# Parse options from POD using all default values.
|
||||
# ############################################################################
|
||||
|
||||
parse_options "$T_LIB_DIR/samples/bash/po001.sh" "" 2>$TMPFILE
|
||||
parse_options "$T_LIB_DIR/samples/bash/po001.sh" 2>$TMPFILE
|
||||
|
||||
is "`cat $TMPFILE`" "" "No warnings or errors"
|
||||
|
||||
@@ -38,6 +38,8 @@ is "$OPT_NOPTION" "yes" "Default neg option (spec)"
|
||||
is "$OPT_INT_OPT" "50" "Specified int option (spec)"
|
||||
is "$OPT_INT_OPT2" "42" "Default int option with default (spec)"
|
||||
is "$OPT_VERSION" "" "--version (spec)"
|
||||
is "$ARGV" "" "ARGV"
|
||||
is "$EXT_ARGV" "" "External ARGV"
|
||||
|
||||
# ############################################################################
|
||||
# --option=value should work like --option value.
|
||||
@@ -56,7 +58,7 @@ parse_options "$T_LIB_DIR/samples/bash/po001.sh" --no-noption
|
||||
is "$OPT_STRING_OPT" "" "Default string option (neg)"
|
||||
is "$OPT_STRING_OPT2" "foo" "Default string option with default (neg)"
|
||||
is "$OPT_TYPELESS_OPTION" "" "Default typeless option (neg)"
|
||||
is "$OPT_NOPTION" "no" "Negated option (neg)"
|
||||
is "$OPT_NOPTION" "" "Negated option (neg)"
|
||||
is "$OPT_INT_OPT" "" "Default int option (neg)"
|
||||
is "$OPT_INT_OPT2" "42" "Default int option with default (neg)"
|
||||
is "$OPT_VERSION" "" "--version (neg)"
|
||||
@@ -103,7 +105,7 @@ cmd_ok \
|
||||
TOOL="pt-test"
|
||||
cp "$T_LIB_DIR/samples/bash/config001.conf" "$HOME/.$TOOL.conf"
|
||||
|
||||
parse_options "$T_LIB_DIR/samples/bash/po001.sh" ""
|
||||
parse_options "$T_LIB_DIR/samples/bash/po001.sh"
|
||||
|
||||
is "$OPT_STRING_OPT" "abc" "Default string option (conf)"
|
||||
is "$OPT_STRING_OPT2" "foo" "Default string option with default (conf)"
|
||||
@@ -112,16 +114,32 @@ is "$OPT_NOPTION" "yes" "Default neg option (conf)"
|
||||
is "$OPT_INT_OPT" "" "Default int option (conf)"
|
||||
is "$OPT_INT_OPT2" "42" "Default int option with default (conf)"
|
||||
is "$OPT_VERSION" "" "--version (conf)"
|
||||
is "$EXT_ARGV" "--host 127.1 --user daniel" "External ARGV (conf)"
|
||||
is "$ARGV" "" "ARGV (conf)"
|
||||
is "$EXT_ARGV" "--host=127.1 --user=daniel" "External ARGV (conf)"
|
||||
|
||||
# Command line should override config file.
|
||||
parse_options "$T_LIB_DIR/samples/bash/po001.sh" --string-opt zzz
|
||||
|
||||
is "$OPT_STRING_OPT" "zzz" "Command line overrides config file"
|
||||
|
||||
# ############################################################################
|
||||
# Option values with spaces.
|
||||
# ############################################################################
|
||||
|
||||
# Config file
|
||||
cp "$T_LIB_DIR/samples/bash/config002.conf" "$HOME/.$TOOL.conf"
|
||||
parse_options "$T_LIB_DIR/samples/bash/po001.sh" ""
|
||||
is "$OPT_STRING_OPT" "hello world" "Option value with space (conf)"
|
||||
|
||||
rm "$HOME/.$TOOL.conf"
|
||||
TOOL="pt-stalk"
|
||||
|
||||
# Command line
|
||||
parse_options "$T_LIB_DIR/samples/bash/po001.sh" --string-opt "hello world"
|
||||
is "$OPT_STRING_OPT" "hello world" "Option value with space (cmd line)"
|
||||
is "$ARGV" "" "ARGV (cmd line)"
|
||||
is "$EXT_ARGV" "" "External ARGV (cmd line)"
|
||||
|
||||
# ############################################################################
|
||||
# Done
|
||||
# ############################################################################
|
||||
|
Reference in New Issue
Block a user