tests: add bt_cli util function
[babeltrace.git] / tests / utils / utils.sh
index 69fb84714a72469095f014fb9b988bc88c3dbab5..5691721be67969d966dcd3cfea14db79afed52c6 100644 (file)
@@ -85,14 +85,6 @@ if [ "x${BT_TESTS_BT2_BIN:-}" = "x" ]; then
 fi
 export BT_TESTS_BT2_BIN
 
-if [ "x${BT_TESTS_BT2LOG_BIN:-}" = "x" ]; then
-       BT_TESTS_BT2LOG_BIN="$BT_TESTS_BUILDDIR/../src/cli/babeltrace2-log"
-       if [ "$BT_OS_TYPE" = "mingw" ]; then
-               BT_TESTS_BT2LOG_BIN="${BT_TESTS_BT2LOG_BIN}.exe"
-       fi
-fi
-export BT_TESTS_BT2LOG_BIN
-
 # TODO: Remove when bindings/python/bt2/test_plugin.py is fixed
 BT_PLUGINS_PATH="${BT_TESTS_BUILDDIR}/../src/plugins"
 
@@ -130,7 +122,7 @@ export BT_TESTS_PYTHON_BIN
 if [ "x${BT_TESTS_PYTHON_CONFIG_BIN:-}" = "x" ]; then
        BT_TESTS_PYTHON_CONFIG_BIN="python3-config"
 fi
-export BT_TESTS_PYTHON_BIN
+export BT_TESTS_PYTHON_CONFIG_BIN
 
 if [ "x${BT_TESTS_SED_BIN:-}" = "x" ]; then
        BT_TESTS_SED_BIN="sed"
@@ -142,6 +134,22 @@ export BT_TESTS_SED_BIN
 BT_TESTS_DATADIR="${BT_TESTS_SRCDIR}/data"
 BT_CTF_TRACES_PATH="${BT_TESTS_DATADIR}/ctf-traces"
 
+# Run the Babeltrace CLI, redirecting stdout and stderr to specified files.
+#
+#   $1: file to redirect stdout to
+#   $2: file to redirect stderr to
+#   remaining args: arguments to pass to the CLI
+#
+# Return the exit code of the CLI.
+
+bt_cli() {
+       local stdout_file="$1"
+       local stderr_file="$2"
+       shift 2
+       local args=("$@")
+
+       run_python_bt2 "$BT_TESTS_BT2_BIN" "${args[@]}" 1>"$stdout_file" 2>"$stderr_file"
+}
 
 ### Diff Functions ###
 
@@ -222,7 +230,7 @@ bt_diff_cli() {
        temp_stderr_output_file="$(mktemp -t actual_stderr.XXXXXX)"
 
        # Run the CLI to get a detailed file.
-       run_python_bt2 "$BT_TESTS_BT2_BIN" "${args[@]}" 1>"$temp_stdout_output_file" 2>"$temp_stderr_output_file"
+       bt_cli "$temp_stdout_output_file" "$temp_stderr_output_file" "${args[@]}"
 
        bt_diff "$expected_stdout_file" "$temp_stdout_output_file" "$expected_stderr_file" "$temp_stderr_output_file" "${args[@]}"
        ret=$?
@@ -260,7 +268,7 @@ bt_diff_cli_sorted() {
        temp_stderr_output_file="$(mktemp -t actual_stderr.XXXXXX)"
 
        # Run the CLI to get a detailed file.
-       run_python_bt2 "$BT_TESTS_BT2_BIN" "${args[@]}" 1>"$temp_stdout_output_file" 2>"$temp_stderr_output_file"
+       bt_cli "$temp_stdout_output_file" "$temp_stderr_output_file" "${args[@]}"
 
        # Sort the stdout file, use a subshell to do it in-place
        # shellcheck disable=SC2005
This page took 0.036194 seconds and 4 git commands to generate.