mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 13:40:07 +00:00
Test collect.sh. Use --run-time instead of --interval for collect loop. Fix and require per-test test names in util/test-bash-functions. Fix OPT_ERR in parse_options.sh.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
TESTS=24
|
||||
TESTS=25
|
||||
|
||||
TMPFILE="$TEST_TMPDIR/parse-opts-output"
|
||||
|
||||
@@ -14,17 +14,15 @@ source "$LIB_DIR/parse_options.sh"
|
||||
TMPDIR="$TEST_TMPDIR"
|
||||
parse_options "$T_LIB_DIR/samples/bash/po001.sh" "" 2>$TMPFILE
|
||||
|
||||
TEST_NAME="No warnings or errors"
|
||||
is "`cat $TMPFILE`" ""
|
||||
is "`cat $TMPFILE`" "" "No warnings or errors"
|
||||
|
||||
TEST_NAME="Default opts"
|
||||
is "$OPT_STRING_OPT" ""
|
||||
is "$OPT_STRING_OPT2" "foo"
|
||||
is "$OPT_TYPELESS_OPTION" ""
|
||||
is "$OPT_NOPTION" "yes"
|
||||
is "$OPT_INT_OPT" ""
|
||||
is "$OPT_INT_OPT2" "42"
|
||||
is "$OPT_VERSION" ""
|
||||
is "$OPT_STRING_OPT" "" "Default string option"
|
||||
is "$OPT_STRING_OPT2" "foo" "Default string option with default"
|
||||
is "$OPT_TYPELESS_OPTION" "" "Default typeless option"
|
||||
is "$OPT_NOPTION" "yes" "Defailt neg option"
|
||||
is "$OPT_INT_OPT" "" "Default int option"
|
||||
is "$OPT_INT_OPT2" "42" "Default int option with default"
|
||||
is "$OPT_VERSION" "" "--version"
|
||||
|
||||
# ############################################################################
|
||||
# Specify some opts, but use default values for the rest.
|
||||
@@ -32,14 +30,13 @@ is "$OPT_VERSION" ""
|
||||
|
||||
parse_options "$T_LIB_DIR/samples/bash/po001.sh" --int-opt 50 --typeless-option --string-opt bar
|
||||
|
||||
TEST_NAME="User-specified opts with defaults"
|
||||
is "$OPT_STRING_OPT" "bar" # specified
|
||||
is "$OPT_STRING_OPT2" "foo"
|
||||
is "$OPT_TYPELESS_OPTION" "yes" # specified
|
||||
is "$OPT_NOPTION" "yes"
|
||||
is "$OPT_INT_OPT" "50" # specified
|
||||
is "$OPT_INT_OPT2" "42"
|
||||
is "$OPT_VERSION" ""
|
||||
is "$OPT_STRING_OPT" "bar" "Specified string option (spec)"
|
||||
is "$OPT_STRING_OPT2" "foo" "Default string option with default (spec)"
|
||||
is "$OPT_TYPELESS_OPTION" "yes" "Specified typeless option (spec)"
|
||||
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)"
|
||||
|
||||
# ############################################################################
|
||||
# Negate an option like --no-option.
|
||||
@@ -47,23 +44,20 @@ is "$OPT_VERSION" ""
|
||||
|
||||
parse_options "$T_LIB_DIR/samples/bash/po001.sh" --no-noption
|
||||
|
||||
TEST_NAME="Negated option"
|
||||
is "$OPT_STRING_OPT" ""
|
||||
is "$OPT_STRING_OPT2" "foo"
|
||||
is "$OPT_TYPELESS_OPTION" ""
|
||||
is "$OPT_NOPTION" "no" # negated
|
||||
is "$OPT_INT_OPT" ""
|
||||
is "$OPT_INT_OPT2" "42"
|
||||
is "$OPT_VERSION" ""
|
||||
is "$OPT_STRING_OPT" "" "Default string option (neg)"
|
||||
is "$OPT_STRING_OPT2" "foo" "Default string option with default (net)"
|
||||
is "$OPT_TYPELESS_OPTION" "" "Default typeless option (neg)"
|
||||
is "$OPT_NOPTION" "no" "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)"
|
||||
|
||||
# ############################################################################
|
||||
# Short form.
|
||||
# ############################################################################
|
||||
|
||||
parse_options "$T_LIB_DIR/samples/bash/po001.sh" -v
|
||||
|
||||
TEST_NAME="Short form"
|
||||
is "$OPT_VERSION" "yes"
|
||||
is "$OPT_VERSION" "yes" "Short form"
|
||||
|
||||
# ############################################################################
|
||||
# An unknown option should produce an error.
|
||||
@@ -74,13 +68,9 @@ is "$OPT_VERSION" "yes"
|
||||
parse_options "$T_LIB_DIR/samples/bash/po001.sh" --foo >$TMPFILE 2>&1
|
||||
)
|
||||
local err=$?
|
||||
TEST_NAME="Non-zero exit on unknown option"
|
||||
is "$err" "1"
|
||||
|
||||
TEST_NAME="Error on unknown option"
|
||||
cmd_ok "grep -q 'Unknown option: foo' $TMPFILE"
|
||||
is "$err" "1" "Non-zero exit on unknown option"
|
||||
cmd_ok "grep -q 'Unknown option: foo' $TMPFILE" "Error on unknown option"
|
||||
|
||||
# ############################################################################
|
||||
# Done
|
||||
# ############################################################################
|
||||
exit
|
||||
|
Reference in New Issue
Block a user