tests/utils/env.sh.in: make it portable for Bash and Zsh
[babeltrace.git] / tests / utils / run-in-py-env.sh
index 2168f87b6e9591562934d81d762f6b3b45514f07..c5266542cf4bdfe27feec3989f8579e8fae50789 100755 (executable)
@@ -2,50 +2,45 @@
 #
 # SPDX-License-Identifier: GPL-2.0-only
 #
-# Copyright (C) 2017 Philippe Proulx <pproulx@efficios.com>
+# Copyright (C) 2017-2023 Philippe Proulx <pproulx@efficios.com>
 # Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
-#
-
-# Execute a shell command in the appropriate environment to have access to the
-# bt2 Python bindings. For example, one could use it to run a specific Python
-# binding test case with:
-#
-#   $ tests/utils/run-in-py-utils-bt2-env.sh python3 ./tests/utils/python/testrunner.py \
-#     -t test_value.MapValueTestCase.test_deepcopy \
-#     ./tests/bindings/python/bt2
 
-if [ -n "${BT_TESTS_SRCDIR:-}" ]; then
-       UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
+if [[ -n ${BT_TESTS_SRCDIR:-} ]]; then
+       utils_sh=$BT_TESTS_SRCDIR/utils/utils.sh
 else
-       UTILSSH="$(dirname "$0")/../utils/utils.sh"
+       utils_sh=$(dirname "$0")/../utils/utils.sh
 fi
 
 # shellcheck source=../utils/utils.sh
-source "$UTILSSH"
+source "$utils_sh"
 
 usage() {
-       echo "Usage: run-in-py-utils-bt2-env.sh [PYTHON_BIN] ..."
+       echo "Usage: run-in-py-utils-bt2-env.sh COMMAND [ARGS]..."
        echo ""
-       echo "Run a binary with the python environment set to use the 'bt2' module"
-       echo "from the build system prior to installation."
+       echo "Runs the command \`COMMAND\` with the arguments \`ARGS\` within an environment"
+       echo "which can import the testing Python modules (in \`tests/utils/python\`) and the"
+       echo "built \`bt2\` Python package."
        echo ""
-       echo "When building out of tree export the BT_TESTS_BUILDDIR variable with"
-       echo "the path to the built 'tests' directory."
+       echo "NOTE: If you build out of tree, export and set the \`BT_TESTS_BUILDDIR\`"
+       echo "environment variable to the built \`tests\` directory."
 }
 
-if [ -z "$*" ]; then
+if (($# == 0)); then
        usage
        exit 1
 fi
 
-# Sanity check that the BT_TESTS_BUILDDIR value makes sense.
-if [ ! -f "$BT_TESTS_BUILDDIR/Makefile" ]; then
-       fold -w 80 -s <<- END
-       $0: BT_TESTS_BUILDDIR does not point to a valid directory (\`$BT_TESTS_BUILDDIR/Makefile\` does not exist).
+# Make sure the value of `BT_TESTS_BUILDDIR` makes sense
+if [[ ! -f $BT_TESTS_BUILDDIR/Makefile ]]; then
+       {
+               echo "ERROR: Invalid \`BT_TESTS_BUILDDIR\` variable (\`\$BT_TESTS_BUILDDIR/Makefile\`"
+               echo "doesn't exist)."
+               echo ""
+               echo "If you build out of tree, export and set the \`BT_TESTS_BUILDDIR\` environment"
+               echo "variable to the built \`tests\` directory."
+       } >&2
 
-       If building out-of-tree, set BT_TESTS_BUILDDIR to point to the \`tests\` directory in the build tree.
-       END
        exit 1
 fi
 
-bt_run_in_py_env "${@}"
+bt_run_in_py_env "$@"
This page took 0.027942 seconds and 4 git commands to generate.