From 53be3c125109c38ed1acb7d94798d2314237e4c7 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 9 Nov 2023 23:28:28 -0500 Subject: [PATCH] tests/utils/utils.sh: bt_grep_ok(): only define if `SH_TAP` is `1` This function uses ok() which comes from `tap.sh` which `utils.sh` only sources if `SH_TAP` is `1`. Therefore it makes no sense to run or even define this function if the intention of whatever sources `utils.sh` isn't to output TAP directly. Signed-off-by: Philippe Proulx Change-Id: Ia59ceadc9b74b2a2c5201def51d340d9050d944e --- tests/utils/utils.sh | 45 +++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 49750128..3b2ee888 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -347,28 +347,31 @@ bt_grep() { "$BT_TESTS_GREP_BIN" "$@" } -# ok() with the test name `$3` on the result of bt_grep() matching the -# pattern `$1` within the file `$2`. -bt_grep_ok() { - local -r pattern=$1 - local -r file=$2 - local -r test_name=$3 - - bt_grep --silent "$pattern" "$file" - - local -r ret=$? - - if ! ok $ret "$test_name"; then - { - echo "Pattern \`$pattern\` doesn't match the contents of \`$file\`:" - echo '--- 8< ---' - cat "$file" - echo '--- >8 ---' - } >&2 - fi +# Only if `tap.sh` is sourced because bt_grep_ok() uses ok() +if [[ ${SH_TAP:-} == 1 ]]; then + # ok() with the test name `$3` on the result of bt_grep() matching + # the pattern `$1` within the file `$2`. + bt_grep_ok() { + local -r pattern=$1 + local -r file=$2 + local -r test_name=$3 + + bt_grep --silent "$pattern" "$file" + + local -r ret=$? + + if ! ok $ret "$test_name"; then + { + echo "Pattern \`$pattern\` doesn't match the contents of \`$file\`:" + echo '--- 8< ---' + cat "$file" + echo '--- >8 ---' + } >&2 + fi - return $ret -} + return $ret + } +fi # Forwards the arguments to `coverage run`. check_coverage() { -- 2.34.1