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)
commit8b729209b7c727b0ec475db36f998c16f2c3236c
tree61b49f7a65c1f78660ca2476a3ecb16fb6e20e50
parentcc413248eefb5938459338ea1c543d0e03a339fc
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 <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
This page took 0.025161 seconds and 4 git commands to generate.