tests/utils/utils.sh: use a function to source `env.sh`
[babeltrace.git] / tests / utils / utils.sh
index ada568b8dd5d0d31dfbdc5e2cacda548a45a1512..dc4dbdc74e0b9c464173ad8b3f0cf3061792184d 100644 (file)
@@ -95,11 +95,18 @@ _set_vars_srcdir_builddir() {
 _set_vars_srcdir_builddir
 unset -f _set_vars_srcdir_builddir
 
-# Source the generated environment file if it's present
-if [ -f "${BT_TESTS_BUILDDIR}/utils/env.sh" ]; then
-       # shellcheck disable=SC1091
-       . "${BT_TESTS_BUILDDIR}/utils/env.sh"
-fi
+# 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
 
 # Path to the `babeltrace2` command, if not set
 if [ -z "${BT_TESTS_BT2_BIN:-}" ]; then
@@ -156,7 +163,7 @@ export BT_TESTS_PYTHON_BIN
 #
 # This doesn't need to be exported, but it needs to remain set for
 # run_python() to use it.
-BT_TESTS_PYTHON_VERSION=$($BT_TESTS_PYTHON_BIN -c 'import sys; print("{}.{}".format(sys.version_info.major, sys.version_info.minor))')
+BT_TESTS_PYTHON_VERSION=$("$BT_TESTS_PYTHON_BIN" -c 'import sys; print("{}.{}".format(sys.version_info.major, sys.version_info.minor))')
 
 # Name of the `python3-config` command to use when testing, if not set
 if [ -z "${BT_TESTS_PYTHON_CONFIG_BIN:-}" ]; then
@@ -428,7 +435,7 @@ run_python_bt2() {
        if [ "$BT_TESTS_OS_TYPE" = "mingw" ]; then
                local -x PYTHONHOME
 
-               PYTHONHOME=$($BT_TESTS_PYTHON_CONFIG_BIN --prefix)
+               PYTHONHOME=$("$BT_TESTS_PYTHON_CONFIG_BIN" --prefix)
        fi
 
        # If AddressSanitizer is used, we must preload `libasan.so` so that
@@ -440,8 +447,8 @@ run_python_bt2() {
        # Append it to existing `ASAN_OPTIONS` variable, such that we
        # override the user's value if it contains `detect_leaks=1`.
        if [ "${BT_TESTS_ENABLE_ASAN:-}" = "1" ]; then
-               if ${BT_TESTS_CC_BIN} --version | head -n 1 | bt_grep -q '^gcc'; then
-                       lib_asan="$(${BT_TESTS_CC_BIN} -print-file-name=libasan.so)"
+               if "${BT_TESTS_CC_BIN}" --version | head -n 1 | bt_grep -q '^gcc'; then
+                       lib_asan="$("${BT_TESTS_CC_BIN}" -print-file-name=libasan.so)"
                        local -x LD_PRELOAD="${lib_asan}${LD_PRELOAD:+:}${LD_PRELOAD:-}"
                fi
 
This page took 0.13202 seconds and 4 git commands to generate.