tests/utils/utils.sh: bt_grep_ok(): only define if `SH_TAP` is `1`
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 10 Nov 2023 04:28:28 +0000 (23:28 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 7 Feb 2024 21:25:56 +0000 (16:25 -0500)
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 <eeppeliteloop@gmail.com>
Change-Id: Ia59ceadc9b74b2a2c5201def51d340d9050d944e

tests/utils/utils.sh

index 49750128f677651722093609907fb449cef1bc14..3b2ee8886877f55f0429ad20dc541311da074166 100644 (file)
@@ -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() {
This page took 0.024966 seconds and 4 git commands to generate.