utils.sh: expand `${extra_details_args[@]}` conditionally
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 21 Sep 2019 16:07:58 +0000 (12:07 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 25 Sep 2019 02:37:35 +0000 (22:37 -0400)
When you call bt_diff_details_ctf_single() or
bt_diff_details_ctf_gen_single(), it is possible that you don't provide
any extra `sink.text.details` arguments. This makes
`${extra_details_args[@]}` empty.

`utils.sh` does

    set -u

to make Bash throw an error when a variable is undefined/unbound.

Starting from Bash 4.4 [1]:

> Using ${a[@]} or ${a[*]} with an array without any assigned elements
> when the nounset option is enabled no longer throws an unbound
> variable error.

In bt_diff_details_ctf_single() and bt_diff_details_ctf_gen_single(), we
use `"${extra_details_args[@]}"` directly: Bash < 4.4 throws an error if
the array is empty.

We don't get this error on CI nodes having Bash < 4.4 currently because
all the usages of bt_diff_details_ctf_single() and
bt_diff_details_ctf_gen_single() pass extra `sink.text.details`
arguments. However it is my understanding that they are optional.

This patch replaces

    "${extra_details_args[@]}"

with

    ${extra_details_args[@]+"${extra_details_args[@]}"}

so that `"${extra_details_args[@]}"` is only used when
`${extra_details_args[@]}` is defined. This works with any Bash version.

[1]: https://git.savannah.gnu.org/cgit/bash.git/tree/CHANGES?id=3ba697465bc74fab513a26dea700cc82e9f4724e#n878

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ic74117607ac616f3e27968a6f8fb09d07fe7eb12
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2080
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
tests/utils/utils.sh

index 04b45203a69b411047fef6af868c40144da8623b..36c75fe05a350cf5f172a1ecde769ee14f878c02 100644 (file)
@@ -241,7 +241,8 @@ bt_diff_details_ctf_single() {
        expected_stderr_file="/dev/null"
 
        # Compare using the CLI with `sink.text.details`
-       bt_diff_cli "$expected_stdout_file" "$expected_stderr_file" "$trace_dir" "-c" "sink.text.details" "${extra_details_args[@]}"
+       bt_diff_cli "$expected_stdout_file" "$expected_stderr_file" "$trace_dir" \
+               "-c" "sink.text.details" "${extra_details_args[@]+${extra_details_args[@]}}"
 }
 
 # Calls bt_diff_details_ctf_single(), except that "$1" is the path to a
@@ -267,7 +268,8 @@ bt_diff_details_ctf_gen_single() {
        fi
 
        # Compare using the CLI with `sink.text.details`
-       bt_diff_details_ctf_single "$expected_stdout_file" "$temp_trace_dir" "${extra_details_args[@]}"
+       bt_diff_details_ctf_single "$expected_stdout_file" "$temp_trace_dir" \
+               "${extra_details_args[@]+${extra_details_args[@]}}"
        ret=$?
        rm -rf "$temp_trace_dir"
        return $ret
This page took 0.025172 seconds and 4 git commands to generate.