From: Philippe Proulx Date: Sat, 21 Sep 2019 16:07:58 +0000 (-0400) Subject: utils.sh: expand `${extra_details_args[@]}` conditionally X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=8b729209b7c727b0ec475db36f998c16f2c3236c utils.sh: expand `${extra_details_args[@]}` conditionally 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 Change-Id: Ic74117607ac616f3e27968a6f8fb09d07fe7eb12 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2080 Reviewed-by: Simon Marchi CI-Build: Simon Marchi Tested-by: jenkins --- diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 04b45203..36c75fe0 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -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