Skip to content

Commit

Permalink
test/system: Avoid conditionals only supported by Bash's built-in 'test'
Browse files Browse the repository at this point in the history
The '[' and 'test' implementations from GNU coreutils don't support '-v'
as a way to check if a shell variable is set [1].  Only Bash's built-in
implementations do.

This is quite confusing and makes it difficult to find out what '-v'
actually does.  eg., 'man --all test' only shows the manual for the GNU
coreutils version, which doesn't list '-v' [1], and, 'man --all [' only
shows the manual for Bash's built-ins, which also doesn't list '-v'.
One has to go to the bash(1) manual to find it [2].

Elsewhere in the code base [3], the same thing is accomplished with '-z'
and parameter substitution, which are more widely supported and, hence,
easier to find documentation for.

[1] https://manpages.debian.org/testing/coreutils/test.1.en.html

[2] https://linux.die.net/man/1/bash

[3] Commit 84ae385
    #1334

#1341
  • Loading branch information
debarshiray committed Jul 13, 2023
1 parent 21299a3 commit 341ae55
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/system/libs/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function _pull_and_cache_distro_image() {
distro="$1"
version="$2"

if ! [ -v IMAGES[$distro] ]; then
if [ -z "${IMAGES[$distro]+x}" ]; then
fail "Requested distro (${distro}) does not have a matching image"
fi

Expand Down Expand Up @@ -302,7 +302,7 @@ function pull_distro_image() {
distro="$1"
version="$2"

if ! [ -v IMAGES[$distro] ]; then
if [ -z "${IMAGES[$distro]+x}" ]; then
fail "Requested distro (${distro}) does not have a matching image"
fi

Expand Down

0 comments on commit 341ae55

Please sign in to comment.