Skip to content

make verify fails on stock macOS: "test_flags[@]: unbound variable" in hack/test.sh #1504

Description

@corioliskraft

Description

make verify fails at the test target on a stock macOS machine. hack/test.sh expands an empty array under set -u, which older bash treats as an unbound variable. macOS ships bash 3.2.57 as /bin/bash, and #!/usr/bin/env bash resolves to it unless a newer bash is installed separately.

Steps to reproduce

  1. On macOS with no third-party bash installed (/bin/bash --version reports 3.2.57(1)).
  2. Clone the repository and run make verify in the repository root.

How to reproduce this behavior without the repository:

$ /bin/bash -c 'set -u; a=(); echo "${a[@]}"'
bash: a[@]: unbound variable

Actual behavior

verify-fmt, verify-modules, verify-generate and lint pass, then:

./hack/test.sh ./cmd/... ./pkg/...
> Unit Tests
./hack/test.sh: line 27: test_flags[@]: unbound variable
make: *** [test] Error 1

hack/test.sh sets nounset (line 4). Outside CI the else branch (lines 22-25) is taken, so test_flags stays empty, and line 27 expands it:

go test ${timeout_flag:+"$timeout_flag"} "$@" "${test_flags[@]}"

Prow is unaffected: there CI and ARTIFACTS are set, so the if branch appends two elements and test_flags is never empty.

Expected behavior

make verify runs the unit tests instead of aborting, on any platform where the documented prerequisites are met. Neither CONTRIBUTING.md nor docs/development.md states an OS or a minimum bash version.

Suggested fix: guard the expansion so it disappears when the array is empty:

go test ${timeout_flag:+"$timeout_flag"} "$@" ${test_flags[@]+"${test_flags[@]}"}

Verified on bash 3.2.57.

PR will follow.

Environment

  • Kubernetes version: n/a, fails at build/verify time
  • Version of the cloud-provider-stackit: main at commit 83f9aae

Additional information

  • macOS 15.7.7, arm64
  • /bin/bash 3.2.57(1)-release
  • Contributors with Homebrew or MacPorts bash earlier on PATH get bash 5.x and do not hit this,
    which is likely why it went unnoticed.

/kind bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions