Skip to content
2 changes: 1 addition & 1 deletion bashunit
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function _check_bash_version() {
fi

local major
IFS=. read -r major _ _ <<< "$current_version"
major=$(echo "$current_version" | cut -d. -f1)

if (( major < 3 )); then
printf 'Bashunit requires Bash >= %s. Current version: %s\n' "$BASHUNIT_MIN_BASH_VERSION" "$current_version" >&2
Expand Down
13 changes: 10 additions & 3 deletions src/helpers.sh

Choose a reason for hiding this comment

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

lines 50 and 244: local name=(...) creates a scalar variable local name="(...)" in Bash 3.0. It doesn't create an array.

lines 53, 124, 306, and 326: Loop variables i, fn, and line are leaked.

Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,16 @@ function helper::find_total_tests() {
for fn_name in "${functions_to_run[@]}"; do
local provider_data
provider_data=()
while IFS=" " read -r line; do
provider_data+=("$line")
done <<< "$(helper::get_provider_data "$fn_name" "$file")"
local provider_output
provider_output="$(helper::get_provider_data "$fn_name" "$file")"
if [[ -n "$provider_output" ]]; then
local line
while IFS=" " read -r line; do
provider_data+=("$line")
done << EOF
$provider_output
EOF
fi

if [[ "${#provider_data[@]}" -eq 0 ]]; then
count=$((count + 1))
Expand Down
20 changes: 16 additions & 4 deletions src/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,16 @@ function runner::call_test_functions() {

local provider_data
provider_data=()
while IFS=" " read -r line; do
provider_data+=("$line")
done <<< "$(helper::get_provider_data "$fn_name" "$script")"
local provider_output
provider_output="$(helper::get_provider_data "$fn_name" "$script")"
if [[ -n "$provider_output" ]]; then
local line
while IFS=" " read -r line; do
provider_data+=("$line")

Choose a reason for hiding this comment

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

Variable assignments of the form var+=rhs and arr+=(...) don't exist in Bash 3.0. It was introduced in Bash 3.1.

done << EOF
$provider_output
EOF
fi

# No data provider found
if [[ "${#provider_data[@]}" -eq 0 ]]; then
Expand All @@ -207,9 +214,14 @@ function runner::call_test_functions() {
for data in "${provider_data[@]}"; do
local parsed_data
parsed_data=()
local args_output
args_output="$(runner::parse_data_provider_args "$data")"
local line
while IFS= read -r line; do
parsed_data+=( "$(helper::decode_base64 "${line}")" )
done <<< "$(runner::parse_data_provider_args "$data")"
done << EOF
$args_output
EOF
runner::run_test "$script" "$fn_name" "${parsed_data[@]}"
done
unset fn_name
Expand Down