]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tests: Make unit.sh pass shellcheck
authorMartin Schwenke <martin@meltin.net>
Thu, 30 Apr 2020 04:35:12 +0000 (14:35 +1000)
committerMartin Schwenke <martins@samba.org>
Wed, 22 Jul 2020 07:53:36 +0000 (07:53 +0000)
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>
ctdb/tests/UNIT/shellcheck/tests.sh
ctdb/tests/scripts/unit.sh

index 715442046066c858bc44ba150f9e70c9ea4ad258..f01ece7d456de5e41eb627eccc69a25350c096e1 100755 (executable)
@@ -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" \
index 00f7fe9cb48985dc9ca3d12f02dc680431e7ca73..8affe702aaf309359173d44a5bbbcac85c4d2500 100644 (file)
@@ -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