tests: replace xargs workaround with bash array expansion
[babeltrace.git] / tests / utils / utils.sh
index 4add2afa354f340f8a73802b5074c466152f2798..84c3c52bdcb62d3f60f0bfa3b091b14131431f4d 100644 (file)
@@ -45,11 +45,17 @@ fi
 # Allow overriding the babeltrace2 executables
 if [ "x${BT_TESTS_BT2_BIN:-}" = "x" ]; then
        BT_TESTS_BT2_BIN="$BT_TESTS_BUILDDIR/../src/cli/babeltrace2"
+       if [ "x${MSYSTEM:-}" != "x" ]; then
+               BT_TESTS_BT2_BIN="${BT_TESTS_BT2_BIN}.exe"
+       fi
 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 [ "x${MSYSTEM:-}" != "x" ]; then
+               BT_TESTS_BT2LOG_BIN="${BT_TESTS_BT2LOG_BIN}.exe"
+       fi
 fi
 export BT_TESTS_BT2LOG_BIN
 
@@ -97,17 +103,17 @@ BT_DEBUG_INFO_PATH="${BT_TESTS_DATADIR}/debug-info"
 
 ### Diff Functions ###
 
-# Checks the difference between:
-#
-# 1. What the CLI outputs when given the arguments "$1" (passed to
-#    `xargs`, so they can include quoted arguments).
-# 2. The file with path "$2".
+# Checks the difference between the content of the file with path "$1"
+# and the output of the CLI when called with the rest of arguments
+# to this function.
 #
 # Returns 0 if there's no difference, and 1 if there is, also printing
 # said difference to the standard error.
 bt_diff_cli() {
-       local args="$1"
-       local expected_file="$2"
+       local expected_file="$1"
+       shift 1
+       local args=("$@")
+
        local temp_output_file
        local temp_diff
        local ret=0
@@ -118,11 +124,11 @@ bt_diff_cli() {
        # Run the CLI to get a detailed file. Strip any \r present due to
        # Windows (\n -> \r\n). "diff --string-trailing-cr" is not used since it
        # is not present on Solaris.
-       echo "$args" | xargs "$BT_TESTS_BT2_BIN" 2>/dev/null | tr -d "\r" > "$temp_output_file"
+       "$BT_TESTS_BT2_BIN" "${args[@]}" | tr -d "\r" > "$temp_output_file"
 
        # Compare output with expected output
        if ! diff -u "$temp_output_file" "$expected_file" 2>/dev/null >"$temp_diff"; then
-               echo "ERROR: for '$args': actual and expected outputs differ:" >&2
+               echo "ERROR: for '${args[*]}': actual and expected outputs differ:" >&2
                cat "$temp_diff" >&2
                ret=1
        fi
@@ -132,25 +138,21 @@ bt_diff_cli() {
        return $ret
 }
 
-# Checks the difference between:
-#
-# 1. What the CLI outputs when given the arguments:
-#
-#        "$1" -c sink.text.details $3
-#
-# 2. The file with path "$2".
-#
-# Parameter 3 is optional.
+# Checks the difference between the content of the file with path "$1"
+# and the output of the CLI when called on the directory path "$2" with
+# the arguments '-c sink.text.details' and the rest of the arguments to
+# this function.
 #
 # Returns 0 if there's no difference, and 1 if there is, also printing
 # said difference to the standard error.
 bt_diff_details_ctf_single() {
-       local trace_dir="$1"
-       local expected_file="$2"
-       local extra_details_args="${3:-}"
+       local expected_file="$1"
+       local trace_dir="$2"
+       shift 2
+       local extra_details_args=("$@")
 
        # Compare using the CLI with `sink.text.details`
-       bt_diff_cli "\"$trace_dir\" -c sink.text.details $extra_details_args" "$expected_file"
+       bt_diff_cli "$expected_file" "$trace_dir" "-c" "sink.text.details" "${extra_details_args[@]}"
 }
 
 # Calls bt_diff_details_ctf_single(), except that "$1" is the path to a
@@ -160,7 +162,8 @@ bt_diff_details_ctf_single() {
 bt_diff_details_ctf_gen_single() {
        local ctf_gen_prog_path="$1"
        local expected_file="$2"
-       local extra_details_args="${3:-}"
+       shift 2
+       local extra_details_args=("$@")
 
        local temp_trace_dir
        local ret
@@ -175,7 +178,7 @@ bt_diff_details_ctf_gen_single() {
        fi
 
        # Compare using the CLI with `sink.text.details`
-       bt_diff_details_ctf_single "$temp_trace_dir" "$expected_file" "$extra_details_args"
+       bt_diff_details_ctf_single "$expected_file" "$temp_trace_dir" "${extra_details_args[@]}"
        ret=$?
        rm -rf "$temp_trace_dir"
        return $ret
@@ -222,7 +225,7 @@ run_python_bt2() {
 # $2 : The pattern to match python test script names (optional)
 run_python_bt2_test() {
        local test_dir="$1"
-       local test_pattern="${2:-}" # optional
+       local test_pattern="${2:-'*'}" # optional, if none default to "*"
 
        local ret
        local test_runner_args=()
@@ -241,7 +244,9 @@ run_python_bt2_test() {
        run_python_bt2 \
                "${python_exec}" \
                "${BT_TESTS_SRCDIR}/utils/python/testrunner.py" \
-               "${test_runner_args[@]}"
+               --pattern "$test_pattern" \
+               "$test_dir" \
+
        ret=$?
 
        if test "x${BT_TESTS_COVERAGE_REPORT:-}" = "x1"; then
This page took 0.025156 seconds and 4 git commands to generate.