-
-
Notifications
You must be signed in to change notification settings - Fork 41
Lower bash support from 3.2 to 3.0 #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
087e31d
2fe286f
c9ba457
0ab6f6b
ab46d80
baef9bf
76db26f
1f09ad9
239194e
96ec56f
8dfdc07
6200c66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,10 +51,12 @@ function assert_false() { | |
|
|
||
| function run_command_or_eval() { | ||
| local cmd="$1" | ||
| local eval_pattern='^eval' | ||
| local alias_pattern='^alias' | ||
|
|
||
| if [[ "$cmd" =~ ^eval ]]; then | ||
| if [[ "$cmd" =~ $eval_pattern ]]; then | ||
| eval "${cmd#eval }" &> /dev/null | ||
| elif [[ "$(command -v "$cmd")" =~ ^alias ]]; then | ||
| elif [[ "$(command -v "$cmd")" =~ $alias_pattern ]]; then | ||
| eval "$cmd" &> /dev/null | ||
| else | ||
| "$cmd" &> /dev/null | ||
|
|
@@ -546,7 +548,7 @@ function assert_line_count() { | |
| local actual | ||
| actual=$(echo "$input_str" | wc -l | tr -d '[:blank:]') | ||
| local additional_new_lines | ||
| additional_new_lines=$(grep -o '\\n' <<< "$input_str" | wc -l | tr -d '[:blank:]') | ||
| additional_new_lines=$(echo "$input_str" | grep -o '\\n' | wc -l | tr -d '[:blank:]') | ||
|
Comment on lines
-563
to
+565
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this change try to fix? |
||
| ((actual+=additional_new_lines)) | ||
| fi | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lines 50 and 244: lines 53, 124, 306, and 326: Loop variables |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,8 @@ function runner::load_test_files() { | |
| local filter=$1 | ||
| shift | ||
| local files=("${@}") | ||
| local scripts_ids=() | ||
| local scripts_ids | ||
| scripts_ids=() | ||
|
|
||
| for test_file in "${files[@]}"; do | ||
| if [[ ! -f $test_file ]]; then | ||
|
|
@@ -113,7 +114,8 @@ function runner::parse_data_provider_args() { | |
| local i | ||
| local arg | ||
| local encoded_arg | ||
| local -a args=() | ||
| local args | ||
| args=() | ||
| # Parse args from the input string into an array, respecting quotes and escapes | ||
| for ((i=0; i<${#input}; i++)); do | ||
| local char="${input:$i:1}" | ||
|
|
@@ -188,10 +190,18 @@ function runner::call_test_functions() { | |
| break | ||
| fi | ||
|
|
||
| local provider_data=() | ||
| while IFS=" " read -r line; do | ||
| provider_data+=("$line") | ||
| done <<< "$(helper::get_provider_data "$fn_name" "$script")" | ||
| local provider_data | ||
| provider_data=() | ||
| 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") | ||
|
||
| done << EOF | ||
| $provider_output | ||
| EOF | ||
| fi | ||
|
|
||
| # No data provider found | ||
| if [[ "${#provider_data[@]}" -eq 0 ]]; then | ||
|
|
@@ -202,10 +212,16 @@ function runner::call_test_functions() { | |
|
|
||
| # Execute the test function for each line of data | ||
| for data in "${provider_data[@]}"; do | ||
| local parsed_data=() | ||
| 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 | ||
|
|
@@ -235,7 +251,12 @@ function runner::call_bench_functions() { | |
| fi | ||
|
|
||
| for fn_name in "${functions_to_run[@]}"; do | ||
| read -r revs its max_ms <<< "$(benchmark::parse_annotations "$fn_name" "$script")" | ||
| local annotation_result | ||
| annotation_result="$(benchmark::parse_annotations "$fn_name" "$script")" | ||
| set -- "$annotation_result" | ||
| revs="$1" | ||
| its="$2" | ||
| max_ms="$3" | ||
|
||
| benchmark::run_function "$fn_name" "$revs" "$its" "$max_ms" | ||
| unset fn_name | ||
| done | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many cases of rewriting the regex matching this way, but this can simply be solved by defining a utility function like
function regex_match() { [[ $1 =~ $2 ]]; }. Then, you can write the regular expressions inline asregex_match "$cmd" '^eval'orregex_match "$(command -v "$cmd")" '^alias'. This works in all cases ofbash <= 3.1,bash >= 3.2, andbash >= 3.2withshopt -s compat31.