tests/utils/utils.sh: use a function to source `env.sh`
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 10 Nov 2023 04:03:26 +0000 (23:03 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 7 Feb 2024 21:25:56 +0000 (16:25 -0500)
By using a function to do this, we can use a local variable to hold the
`env.sh` path and therefore remove redundancy.

Disabling SC1090 because it's a non-constant source now, but it's
useless to add `source=` here because SC1091 is already disabled.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ie449fd8f0cd04074b87b967d8b0ec719094f378c

tests/utils/utils.sh

index 4e033b79d989a0c3a1b4e3ca16a3440fa728f635..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
This page took 0.024537 seconds and 4 git commands to generate.