summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2020-04-30 14:35:12 +1000
committerMartin Schwenke <martins@samba.org>2020-07-22 07:53:36 +0000
commita369bedf8c5eee75748cdbd6a1a900ca9ac4da9e (patch)
tree8dd311fa91eda6ad483bdec1616df456ecd74698
parentbe3065ea958b27ec297078008c2ce33b4a419820 (diff)
downloadsamba-a369bedf8c5eee75748cdbd6a1a900ca9ac4da9e.tar.gz
ctdb-tests: Make unit.sh pass shellcheck
Mostly avoidance of quoting warnings. Silencing warnings about unquoted $CTDB_TEST_CAT_RESULTS_OPTS is handled by passing '-' to cat when that variable's value is empty. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
-rwxr-xr-xctdb/tests/UNIT/shellcheck/tests.sh3
-rw-r--r--ctdb/tests/scripts/unit.sh15
2 files changed, 12 insertions, 6 deletions
diff --git a/ctdb/tests/UNIT/shellcheck/tests.sh b/ctdb/tests/UNIT/shellcheck/tests.sh
index 71544204606..f01ece7d456 100755
--- a/ctdb/tests/UNIT/shellcheck/tests.sh
+++ b/ctdb/tests/UNIT/shellcheck/tests.sh
@@ -21,7 +21,8 @@ shellcheck_test \
# Includes
shellcheck_test -s sh \
"${TEST_SCRIPTS_DIR}/common.sh" \
- "${TEST_SCRIPTS_DIR}/script_install_paths.sh"
+ "${TEST_SCRIPTS_DIR}/script_install_paths.sh" \
+ "${TEST_SCRIPTS_DIR}/unit.sh"
shellcheck_test -s bash \
"${TEST_SCRIPTS_DIR}/cluster.bash" \
diff --git a/ctdb/tests/scripts/unit.sh b/ctdb/tests/scripts/unit.sh
index 00f7fe9cb48..8affe702aaf 100644
--- a/ctdb/tests/scripts/unit.sh
+++ b/ctdb/tests/scripts/unit.sh
@@ -32,9 +32,9 @@ required_result ()
required_error ()
{
- rc=$(errcode $1)
+ rc=$(errcode "$1")
shift
- required_result $rc "$@"
+ required_result "$rc" "$@"
}
ok ()
@@ -83,7 +83,9 @@ Output (Exit status: ${_rc}):
--------------------------------------------------
EOF
# Avoid echo, which might expand unintentional escapes
- printf '%s\n' "$_out" | result_filter | cat $CTDB_TEST_CAT_RESULTS_OPTS
+ printf '%s\n' "$_out" | \
+ result_filter | \
+ cat "${CTDB_TEST_CAT_RESULTS_OPTS:--}"
fi
if ! $_passed ; then
@@ -93,7 +95,8 @@ Required output (Exit status: ${required_rc}):
--------------------------------------------------
EOF
# Avoid echo, which might expand unintentional escapes
- printf '%s\n' "$required_output" | cat $CTDB_TEST_CAT_RESULTS_OPTS
+ printf '%s\n' "$required_output" | \
+ cat "${CTDB_TEST_CAT_RESULTS_OPTS:--}"
if $CTDB_TEST_DIFF_RESULTS ; then
_outr=$(mktemp)
@@ -142,6 +145,8 @@ result_filter_default ()
_date_time_pid='[0-9/][0-9/]*\ [0-9:\.][0-9:\.]*\ \[[\ 0-9][\ 0-9]*\]'
sed -e "s@^${_date_time_pid}:@DATE\ TIME\ \[PID\]:@"
}
+# Used in testcases
+# shellcheck disable=SC2034
TEST_DATE_STAMP=""
# Override this function to customise output filtering.
@@ -157,7 +162,7 @@ result_check ()
# Avoid echo, which might expand unintentional escapes
_fout=$(printf '%s\n' "$_out" | result_filter)
- if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
+ if [ "$_fout" = "$required_output" ] && [ "$_rc" = "$required_rc" ] ; then
_passed=true
else
_passed=false