-# By default, it will not source tap.sh. If you to tap output directly from
-# the test script, define the 'SH_TAP' variable to '1' before sourcing this
-# script.
-if [ "x${SH_TAP:-}" = x1 ]; then
- . "${BT_TESTS_SRCDIR}/utils/tap/tap.sh"
-fi
+# Sets and exports, if not set:
+#
+# • `BT_TESTS_SRCDIR` to the base source directory of tests.
+# • `BT_TESTS_BUILDDIR` to the base build directory of tests.
+_set_vars_srcdir_builddir() {
+ # If `readlink -f` is available, then get a resolved absolute path
+ # to the tests source directory. Otherwise, make do with a relative
+ # path.
+ local -r scriptdir=$(dirname "${BASH_SOURCE[0]}")
+ local testsdir
+
+ if readlink -f . &> /dev/null; then
+ testsdir=$(readlink -f "$scriptdir/..")
+ else
+ testsdir=$scriptdir/..
+ fi
+
+ # Base source directory of tests
+ _bt_tests_set_var_def BT_TESTS_SRCDIR "$testsdir"
+
+ # Base build directory of tests
+ _bt_tests_set_var_def BT_TESTS_BUILDDIR "$testsdir"
+}
+
+_set_vars_srcdir_builddir
+unset -f _set_vars_srcdir_builddir
+
+# Sources the generated environment file (`env.sh`) if it exists.
+_source_env_sh() {
+ local -r env_sh_path=$BT_TESTS_BUILDDIR/utils/env.sh
+
+ if [[ -f $env_sh_path ]]; then
+ # shellcheck disable=SC1090,SC1091
+ . "$env_sh_path"
+ fi
+}
+
+_source_env_sh
+unset -f _source_env_sh