@@ -15,11 +15,9 @@ function bashunit::runner::restore_workdir() {
1515function bashunit::runner::load_test_files() {
1616 local filter=$1
1717 shift
18- # Bash 3.0 compatible array initialization
19- local files
18+ local -a files=()
2019 [[ $# -gt 0 ]] && files=(" $@ " )
21- # Declare without =() for Bash 3.0 compatibility with set -u
22- local scripts_ids
20+ local -a scripts_ids=()
2321 local scripts_ids_count=0
2422
2523 # Initialize coverage tracking if enabled
@@ -112,8 +110,7 @@ function bashunit::runner::load_test_files() {
112110function bashunit::runner::load_bench_files() {
113111 local filter=$1
114112 shift
115- # Bash 3.0 compatible array initialization
116- local files
113+ local -a files=()
117114 [[ $# -gt 0 ]] && files=(" $@ " )
118115
119116 for bench_file in ${files+" ${files[@]} " } ; do
@@ -207,8 +204,7 @@ function bashunit::runner::parse_data_provider_args() {
207204 local i
208205 local arg
209206 local encoded_arg
210- # Bash 3.0 compatible array initialization
211- local args
207+ local -a args=()
212208 local args_count=0
213209
214210 # Check for shell metacharacters that would break eval or cause globbing
@@ -313,8 +309,7 @@ function bashunit::runner::call_test_functions() {
313309 local filtered_functions
314310 filtered_functions=$( bashunit::helper::get_functions_to_run \
315311 " $prefix " " $filter " " $_BASHUNIT_CACHED_ALL_FUNCTIONS " )
316- # Bash 3.0 compatible array initialization
317- local functions_to_run
312+ local -a functions_to_run=()
318313 local functions_to_run_count=0
319314 local _fn
320315 while IFS= read -r _fn; do
@@ -329,15 +324,18 @@ function bashunit::runner::call_test_functions() {
329324
330325 bashunit::helper::check_duplicate_functions " $script " || true
331326
327+ local -a provider_data=()
328+ local provider_data_count=0
329+ local -a parsed_data=()
330+ local parsed_data_count=0
331+
332332 for fn_name in " ${functions_to_run[@]} " ; do
333333 if bashunit::parallel::is_enabled && bashunit::parallel::must_stop_on_failure; then
334334 break
335335 fi
336336
337- # Bash 3.0 compatible: unset before redeclaring to clear previous iteration's data
338- unset provider_data
339- local provider_data
340- local provider_data_count=0
337+ provider_data=()
338+ provider_data_count=0
341339 while IFS=" " read -r line; do
342340 [[ -z " $line " ]] && continue
343341 provider_data[provider_data_count]=" $line "
@@ -347,24 +345,22 @@ function bashunit::runner::call_test_functions() {
347345 # No data provider found
348346 if [[ " $provider_data_count " -eq 0 ]]; then
349347 bashunit::runner::run_test " $script " " $fn_name "
350- unset fn_name
348+ unset -v fn_name
351349 continue
352350 fi
353351
354352 # Execute the test function for each line of data
355353 for data in " ${provider_data[@]} " ; do
356- # Bash 3.0 compatible: unset before redeclaring to clear previous iteration's data
357- unset parsed_data
358- local parsed_data
359- local parsed_data_count=0
354+ parsed_data=()
355+ parsed_data_count=0
360356 while IFS= read -r line; do
361357 [[ -z " $line " ]] && continue
362358 parsed_data[parsed_data_count]=" $( bashunit::helper::decode_base64 " ${line} " ) "
363359 parsed_data_count=$(( parsed_data_count + 1 ))
364360 done <<< " $(bashunit::runner::parse_data_provider_args " $data " )"
365361 bashunit::runner::run_test " $script " " $fn_name " ${parsed_data+" ${parsed_data[@]} " }
366362 done
367- unset fn_name
363+ unset -v fn_name
368364 done
369365}
370366
@@ -377,8 +373,7 @@ function bashunit::runner::call_bench_functions() {
377373 local filtered_functions
378374 filtered_functions=$( bashunit::helper::get_functions_to_run \
379375 " $prefix " " $filter " " $_BASHUNIT_CACHED_ALL_FUNCTIONS " )
380- # Bash 3.0 compatible array initialization
381- local functions_to_run
376+ local -a functions_to_run=()
382377 local functions_to_run_count=0
383378 local _fn
384379 while IFS= read -r _fn; do
@@ -398,7 +393,7 @@ function bashunit::runner::call_bench_functions() {
398393 for fn_name in " ${functions_to_run[@]} " ; do
399394 read -r revs its max_ms <<< " $(bashunit::benchmark::parse_annotations " $fn_name " " $script " )"
400395 bashunit::benchmark::run_function " $fn_name " " $revs " " $its " " $max_ms "
401- unset fn_name
396+ unset -v fn_name
402397 done
403398
404399 if ! bashunit::env::is_simple_output_enabled; then
@@ -726,8 +721,7 @@ function bashunit::runner::parse_result() {
726721 shift
727722 local execution_result=$1
728723 shift
729- # Bash 3.0 compatible array initialization
730- local args
724+ local -a args=()
731725 [[ $# -gt 0 ]] && args=(" $@ " )
732726
733727 if bashunit::parallel::is_enabled; then
@@ -742,8 +736,7 @@ function bashunit::runner::parse_result_parallel() {
742736 shift
743737 local execution_result=$1
744738 shift
745- # Bash 3.0 compatible array initialization
746- local args
739+ local -a args=()
747740 [[ $# -gt 0 ]] && args=(" $@ " )
748741
749742 local test_suite_dir=" ${TEMP_DIR_PARALLEL_TEST_SUITE} /$( basename " $test_file " .sh) "
0 commit comments