diff options
author | Kate Ward <kate.ward@forestent.com> | 2017-10-17 23:41:42 +0200 |
---|---|---|
committer | Kate Ward <kate.ward@forestent.com> | 2017-10-17 23:41:42 +0200 |
commit | 08f81ed4f5bddb72786893246d8959c4b01a070a (patch) | |
tree | 6819bae3d14b677a02acb772c723fe5247ea9665 /shflags_defines_test.sh | |
parent | 0fcacd13accb5cd0e2aac61b6a527e7706842154 (diff) | |
download | shflags-08f81ed4f5bddb72786893246d8959c4b01a070a.tar.gz |
Ran shflags_defines_tests.sh through ShellCheck.
Diffstat (limited to 'shflags_defines_test.sh')
-rwxr-xr-x | shflags_defines_test.sh | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/shflags_defines_test.sh b/shflags_defines_test.sh index 91baf8b..e4582b5 100755 --- a/shflags_defines_test.sh +++ b/shflags_defines_test.sh @@ -2,39 +2,48 @@ # vim:et:ft=sh:sts=2:sw=2 # # shFlags unit test for the flag definition methods +# +# Copyright 2008-2017 Kate Ward. All Rights Reserved. +# Released under the Apache 2.0 license. +# +# Author: kate.ward@forestent.com (Kate Ward) +# https://github.com/kward/shflags +# +### ShellCheck (http://www.shellcheck.net/) +# Disable source following. +# shellcheck disable=SC1090,SC1091 -# load test helpers -. ./shflags_test_helpers +# These variables will be overridden by the test helpers. +stdoutF="${TMPDIR:-/tmp}/STDOUT" +stderrF="${TMPDIR:-/tmp}/STDERR" -#------------------------------------------------------------------------------ -# suite tests -# +# Load test helpers. +. ./shflags_test_helpers -testFlagsDefine() -{ - # no arguments +testFlagsDefine() { + # No arguments. _flags_define >"${stdoutF}" 2>"${stderrF}" assertFalse '_flags_define() with no arguments should have failed.' $? assertErrorMsg '' 'no arguments' - # one argument + # One argument. _flags_define arg1 >"${stdoutF}" 2>"${stderrF}" assertFalse '_flags_define() call with one argument should fail' $? assertErrorMsg '' 'one argument' - # two arguments + # Two arguments. _flags_define arg1 arg2 >"${stdoutF}" 2>"${stderrF}" assertFalse '_flags_define() call with two arguments should fail' $? assertErrorMsg '' 'two arguments' - # three arguments + # Three arguments. _flags_define arg1 arg2 arg3 >"${stdoutF}" 2>"${stderrF}" assertFalse '_flags_define() call with three arguments should fail' $? assertErrorMsg '' 'three arguments' - # multiple definition -- assumes working boolean definition (tested elsewhere) - _flags_define ${__FLAGS_TYPE_BOOLEAN} multiDefBool true 'multi def #1' m - _flags_define ${__FLAGS_TYPE_BOOLEAN} multiDefBool false 'multi def #2' m \ + # Multiple definition. Assumes working boolean definition (tested elsewhere). + _flags_define "${__FLAGS_TYPE_BOOLEAN}" multiDefBool true 'multi def #1' m + _flags_define "${__FLAGS_TYPE_BOOLEAN}" multiDefBool false 'multi def #2' m \ >"${stdoutF}" 2>"${stderrF}" assertFalse '_flags_define() with existing flag name should fail' $? assertTrue \ @@ -42,27 +51,27 @@ testFlagsDefine() "${FLAGS_multiDefBool:-}" assertWarnMsg '' 'existing flag' - # duplicate dashed and underscored definition - _flags_define ${__FLAGS_TYPE_STRING} long-name 'foo' 'dashed name' l - _flags_define ${__FLAGS_TYPE_STRING} long_name 'bar' 'underscored name' l \ + # Duplicate dashed and underscored definition. + _flags_define "${__FLAGS_TYPE_STRING}" long-name 'foo' 'dashed name' l + _flags_define "${__FLAGS_TYPE_STRING}" long_name 'bar' 'underscored name' l \ >"${stdoutF}" 2>"${stderrF}" assertFalse '_flags_define() with existing flag name should fail' $? + # shellcheck disable=SC2154 assertEquals \ '_flags_define() should not overwrite previously defined default.' \ "${FLAGS_long_name}" 'foo' assertWarnMsg '' 'already exists' - # TODO(kward): test requirement of enhanced getopt + # TODO(kward): test requirement of enhanced getopt. - # invalid type + # Invalid type. _flags_define invalid arg2 arg3 arg4 i >"${stdoutF}" 2>"${stderrF}" assertFalse '_flags_define() with "invalid" type should have failed.' $? assertErrorMsg 'unrecognized flag type' 'invalid type' } -testBoolean() -{ - # test true defaults +testBoolean() { + # Test true defaults. for default in 'true' 't' 0; do flags_reset DEFINE_boolean boolVal "${default}" 'my boolean' b @@ -88,28 +97,27 @@ testBoolean() ${rtrn} done - # test invalid default + # Test invalid default. flags_reset DEFINE_boolean boolVal 'invalid' 'my boolean' b >"${stdoutF}" 2>"${stderrF}" assertFalse 'DEFINE_boolean() call with invalid default did not fail.' $? assertErrorMsg } -testFloat() -{ - # test valid defaults +testFloat() { + # Test valid defaults. for default in ${TH_FLOAT_VALID}; do flags_reset - DEFINE_float floatVal ${default} "float: ${default}" f + DEFINE_float floatVal "${default}" "float: ${default}" f rtrn=$? assertSame "DEFINE_float() call with valid default failed." \ - ${default} "${FLAGS_floatVal:-}" + "${default}" "${FLAGS_floatVal:-}" assertTrue \ "DEFINE_float() call with valid default of '${default}' returned failure." \ ${rtrn} done - # test invalid defaults + # Test invalid defaults. flags_reset DEFINE_float floatVal 'invalid' 'invalid float: string' f \ >"${stdoutF}" 2>"${stderrF}" @@ -117,22 +125,21 @@ testFloat() assertErrorMsg } -testInteger() -{ - # test valid defaults +testInteger() { + # Test valid defaults. for default in ${TH_INT_VALID}; do flags_reset - DEFINE_integer intVal ${default} "integer: ${default}" i + DEFINE_integer intVal "${default}" "integer: ${default}" i rtrn=$? assertSame \ "DEFINE_integer() call with valid default failed." \ - ${default} "${FLAGS_intVal:-}" + "${default}" "${FLAGS_intVal:-}" assertTrue \ "DEFINE_integer() call with valid default of '${default}' returned failure." \ ${rtrn} done - # test invalid defaults + # Test invalid defaults. flags_reset DEFINE_integer intVal 1.234 'invalid integer: float' i \ >"${stdoutF}" 2>"${stderrF}" @@ -183,35 +190,28 @@ testString() '' "${FLAGS_str:-}" } -testShortNameLength() -{ - # make sure short names are no longer than a single character +testShortNameLength() { + # Make sure short names are no longer than a single character. : } -testFlagNameIsReserved() -{ +testFlagNameIsReserved() { ( DEFINE_string TRUE '' 'true is a reserved flag name' t \ >"${stdoutF}" 2>"${stderrF}" ) rtrn=$? - assertEquals ${FLAGS_ERROR} ${rtrn} + assertEquals "${FLAGS_ERROR}" "${rtrn}" assertErrorMsg 'flag name (TRUE) is reserved' } -#------------------------------------------------------------------------------ -# suite functions -# - -oneTimeSetUp() -{ +oneTimeSetUp() { th_oneTimeSetUp } -tearDown() -{ +tearDown() { flags_reset } -# load and run shUnit2 +# Load and run shUnit2. +# shellcheck disable=SC2034 [ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 -. ${TH_SHUNIT} +. "${TH_SHUNIT}" |