Skip to content

Conversation

@Ixecd
Copy link

@Ixecd Ixecd commented Jan 14, 2026

Fix: Handle empty RUN_ARG array in test.sh to prevent "unbound variable" error

Fixes #21124

Problem

When running make test or make test-unit without setting the TESTCASE environment variable, the script fails with:

./scripts/test.sh: line 130: RUN_ARG[@]: unbound variable
make: *** [test-unit] Error 1

This occurs because:

  1. The RUN_ARG array is initialized as empty when TESTCASE is not set: RUN_ARG=()
  2. The script uses set -o nounset (line 55) for strict error checking
  3. In bash 3.2+ (especially on macOS), expanding an empty array "${RUN_ARG[@]}" under set -o nounset triggers an "unbound variable" error

Solution

Changed RUN_ARG from an array to a string. This is the simplest and most elegant solution:

  • Changed RUN_ARG=() to RUN_ARG=""
  • Changed RUN_ARG=("-run=${TESTCASE}") to RUN_ARG="-run=${TESTCASE}"
  • Changed "${RUN_ARG[@]}" to $RUN_ARG in all function calls

When RUN_ARG is an empty string, $RUN_ARG expands to nothing (no error), and when it has a value, it expands correctly. This ensures compatibility with bash 3.2+ while maintaining strict error checking with set -o nounset.

Changes

Changed RUN_ARG from array to string in scripts/test.sh:

  • Line 114: Changed RUN_ARG=() to RUN_ARG=""
  • Line 116: Changed RUN_ARG=("-run=${TESTCASE}") to RUN_ARG="-run=${TESTCASE}"
  • Updated 9 functions to use $RUN_ARG instead of "${RUN_ARG[@]}":
    • unit_pass
    • integration_extra
    • integration_pass (2 call sites)
    • e2e_pass (2 call sites)
    • robustness_pass
    • grpcproxy_integration_pass
    • grpcproxy_e2e_pass

Testing

Tested with:

  • make test-unit (without TESTCASE) - now works
  • make test-unit TESTCASE="TestName" - still works as expected
  • ✅ Bash syntax validation: bash -n scripts/test.sh - passes

Compatibility

  • ✅ Compatible with bash 3.2+ (including macOS default bash)
  • ✅ Maintains set -o nounset strict error checking
  • ✅ No functional changes - TESTCASE remains optional
  • ✅ All existing test functionality preserved

Related

  • Fixes the issue where make test fails on macOS/bash 3.2
  • Ensures that developers can run tests without needing to set TESTCASE, which was the intended behavior based on the script's documentation
  • Maintains backward compatibility with all bash versions (3.2+)

When TESTCASE environment variable is not set, RUN_ARG array remains
empty. Under set -o nounset, expanding an empty array "${RUN_ARG[@]}"
causes an "unbound variable" error in bash 3.2+ (especially on macOS).

This fix changes RUN_ARG from an array to a string. When RUN_ARG is
an empty string, $RUN_ARG expands to nothing (no error), and when it
has a value, it expands correctly. This is simpler than adding
conditional checks and maintains strict error checking.

Fixes the issue where `make test` and `make test-unit` fail when
TESTCASE is not set.

Fixes etcd-io#21124

Tested:
- make test-unit (without TESTCASE) - now works
- make test-unit TESTCASE="TestName" - still works
- bash -n scripts/test.sh - syntax validation passes

Signed-off-by: Ixecd <2192629378@qq.com>
@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ixecd
Once this PR has been reviewed and has the lgtm label, please assign ivanvc for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link

Hi @Ixecd. Thanks for your PR.

I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@serathius
Copy link
Member

Note: Don't write a essay on something that can be explained in a single sentence. AI here works against you.

I guess this is nothing related to what is described in the issue, but to shell difference. Would be good to trace which shells this works or doesn't and whether we want to support them.

cc @ivanvc

@Ixecd
Copy link
Author

Ixecd commented Jan 14, 2026

Note: Don't write a essay on something that can be explained in a single sentence. AI here works against you.

I guess this is nothing related to what is described in the issue, but to shell difference. Would be good to trace which shells this works or doesn't and whether we want to support them.

cc @ivanvc

Got it, I’ll be careful and get straight to the point whenever I can.

You're right, this is indeed a shell version difference issue. The shebang #!/usr/bin/env bash forces the .sh to be executed exclusively by the bash, use the string RUN_ARG=”” to be compatible with all versions, and here only a single value is stored, no array is needed.

@serathius
Copy link
Member

serathius commented Jan 14, 2026

Hmm, not sure I understood, could you please respond using rhyme. That would make it more understandable for me. :P

@Ixecd
Copy link
Author

Ixecd commented Jan 14, 2026

Hmm, not sure I understood, could you please respond using rhyme. That would make it more understandable for me. :P

Okay, that’s unexpected -- but alright :)

The shebang env with bash so fine,
Locks us to Bash, no other line.
No sh, no fish, no zsh in sight,
Just Bash alone will run it right.

For empty vars, don’t use array,
Old macOS Bash gets quite contrary.
A simple string, empty and clean,
Works everywhere, smooth and serene.😜

@ivanvc
Copy link
Member

ivanvc commented Jan 14, 2026

Hi, @Ixecd. In short, we don't expect compatibility with Bash 3.2. Our scripts use Bash Arrays, and we need at least 4+. If you're using macOS, we recommend installing a newer Bash version with Homebrew.

@k8s-ci-robot
Copy link

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

make test fails with "unbound variable" error on bash 3.2

4 participants