Skip to content

Support Bash 3.0#584

Open
Chemaclass wants to merge 10 commits intomainfrom
feat/support-bash-3.0
Open

Support Bash 3.0#584
Chemaclass wants to merge 10 commits intomainfrom
feat/support-bash-3.0

Conversation

@Chemaclass
Copy link
Member

@Chemaclass Chemaclass commented Feb 4, 2026

Summary

Closes: #468 by @akinomyoga

Lower the minimum Bash version requirement from 3.2 to 3.0.

Changes

  • Replace Bash 3.1+ features with 3.0 compatible alternatives
  • Fix assert_contains_ignore_case to use tr instead of shopt nocasematch
  • Handle empty strings in printf '%q' and data providers
  • Separate array declaration from assignment for Bash 3.0 compatibility
  • Skip release_test.sh on Bash 3.0 (release.sh requires 3.1+)
  • Add CI workflow to test all modes on Bash 3.0 in parallel

  - Replace printf -v with command substitution (Bash 3.1 feature)
  - Replace += operators with explicit concatenation (Bash 3.1 feature)
  - Store regex patterns in variables for [[ =~ ]] compatibility
  - Fix empty array access with set -u by using conditional initialization
  - Update version check, tests, and documentation
- Replace shopt nocasematch (Bash 3.1+) with tr for case conversion
- Skip release_test.sh on Bash 3.0 (release.sh uses += array syntax)
- Fix shellcheck warnings with proper directive placement
- Build Docker image once and share via artifact
- Run 4 test modes in parallel: sequential, parallel, simple, simple+parallel
- Use matrix strategy for parallel job execution
- Add git to Docker image for tests that need it
@Chemaclass Chemaclass changed the title feat: support Bash 3.0 Support Bash 3.0 Feb 4, 2026
@Chemaclass Chemaclass self-assigned this Feb 4, 2026
@Chemaclass Chemaclass added the enhancement New feature or request label Feb 4, 2026
@Chemaclass Chemaclass mentioned this pull request Feb 4, 2026
2 tasks
src/coverage.sh Outdated
Comment on lines 769 to 770
local file_data
local file_data_count=0
Copy link

@akinomyoga akinomyoga Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern is used multiple times in this PR, but this isn't safe. When no elements are added, "${file_data[@]}" still generates a single empty string in Bash 3.0. One needs to explicitly initialize an empty array as

Suggested change
local file_data
local file_data_count=0
local -a file_data=()
local file_data_count=0

Note that -a is required here. local file_data=() (without -a) results in a scalar variable local file_data='()' containing '()' as a string. It should also be noted that local -a arr=(...) causes problems with custom IFS in Bash 3.0 in the general case, but an empty case local -a arr=() is the only exception that we can safely use in Bash 3.0.

Or if you decided not to use local -a arr=(...) at all even if ... is empty, you can do

Suggested change
local file_data
local file_data_count=0
local file_data
file_data=()
local file_data_count=0

The same applies to other occurrences of this pattern. Although whether the resulting array is empty is checked in some branches, I think one should maintain the safe style.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use now local -a file_data=(), thanks

src/runner.sh Outdated

local provider_data=()
# Bash 3.0 compatible: unset before redeclaring to clear previous iteration's data
unset provider_data

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One should declare provider_data before the loop. Otherwise, this may remove user's global variable provider_data or a shell function provider_data if any.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, to selectively remove the shell variable rather than a shell function, it is generally recommended to always specify the type of the unset (-v or -f).

Suggested change
unset provider_data
unset -v provider_data

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to local -a provider_data=() so no need to have unset at all

@@ -253,7 +253,7 @@ function bashunit::state::calculate_total_assertions() {
numbers=$(echo "$input" | grep -oE '##ASSERTIONS_\w+=[0-9]+' | grep -oE '[0-9]+')

for number in $numbers; do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't an issue with this PR, but the variable number leaks here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! I added local number

@Chemaclass
Copy link
Member Author

@akinomyoga thank you for the review! I addressed all your feedback, please let me know if you find anything else

@akinomyoga
Copy link

I haven't actually gone through the PR. I can later check it in detail.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Bash 3.0

2 participants