@@ -358,22 +358,27 @@ function bashunit::coverage::is_executable_line() {
358358 [[ -z " ${line// / } " ]] && return 1
359359
360360 # Skip comment-only lines (including shebang)
361- bashunit::regex_match " $line " ' ^[[:space:]]*#' && return 1
361+ local _re=' ^[[:space:]]*#'
362+ [[ " $line " =~ $_re ]] && return 1
362363
363364 # Skip function declaration lines (but not single-line functions with body)
364- bashunit::regex_match " $line " " $_BASHUNIT_COVERAGE_FUNC_PATTERN " && return 1
365+ [[ " $line " =~ $_BASHUNIT_COVERAGE_FUNC_PATTERN ]] && return 1
365366
366367 # Skip lines with only braces
367- bashunit::regex_match " $line " ' ^[[:space:]]*[\{\}][[:space:]]*$' && return 1
368+ _re=' ^[[:space:]]*[\{\}][[:space:]]*$'
369+ [[ " $line " =~ $_re ]] && return 1
368370
369371 # Skip control flow keywords (then, else, fi, do, done, esac, in, ;;, ;&, ;;&)
370- bashunit::regex_match " $line " ' ^[[:space:]]*(then|else|fi|do|done|esac|in|;;|;;&|;&)[[:space:]]*(#.*)?$' && return 1
372+ _re=' ^[[:space:]]*(then|else|fi|do|done|esac|in|;;|;;&|;&)[[:space:]]*(#.*)?$'
373+ [[ " $line " =~ $_re ]] && return 1
371374
372375 # Skip case patterns like "--option)" or "*)"
373- bashunit::regex_match " $line " ' ^[[:space:]]*[^\)]+\)[[:space:]]*$' && return 1
376+ _re=' ^[[:space:]]*[^\)]+\)[[:space:]]*$'
377+ [[ " $line " =~ $_re ]] && return 1
374378
375379 # Skip standalone ) for arrays/subshells
376- bashunit::regex_match " $line " ' ^[[:space:]]*\)[[:space:]]*(#.*)?$' && return 1
380+ _re=' ^[[:space:]]*\)[[:space:]]*(#.*)?$'
381+ [[ " $line " =~ $_re ]] && return 1
377382
378383 return 0
379384}
@@ -494,10 +499,14 @@ function bashunit::coverage::extract_functions() {
494499 local fn_name=" "
495500
496501 # Match: function name() or function name {
497- if bashunit::regex_match " $line " ' ^[[:space:]]*(function[[:space:]]+)?([a-zA-Z_][a-zA-Z0-9_:]*)[[:space:]]*\(\)[[:space:]]*\{?[[:space:]]*(#.*)?$' ; then
498- fn_name=" ${BASH_REMATCH[2]} "
499- elif bashunit::regex_match " $line " ' ^[[:space:]]*(function[[:space:]]+)([a-zA-Z_][a-zA-Z0-9_:]*)[[:space:]]*\{[[:space:]]*(#.*)?$' ; then
502+ local _re=' ^[[:space:]]*(function[[:space:]]+)?([a-zA-Z_][a-zA-Z0-9_:]*)[[:space:]]*\(\)[[:space:]]*\{?[[:space:]]*(#.*)?$'
503+ if [[ " $line " =~ $_re ]]; then
500504 fn_name=" ${BASH_REMATCH[2]} "
505+ else
506+ _re=' ^[[:space:]]*(function[[:space:]]+)([a-zA-Z_][a-zA-Z0-9_:]*)[[:space:]]*\{[[:space:]]*(#.*)?$'
507+ if [[ " $line " =~ $_re ]]; then
508+ fn_name=" ${BASH_REMATCH[2]} "
509+ fi
501510 fi
502511
503512 if [[ -n " $fn_name " ]]; then
@@ -512,7 +521,8 @@ function bashunit::coverage::extract_functions() {
512521 brace_count=$(( brace_count + ${# open_braces} - ${# close_braces} ))
513522
514523 # Single-line function
515- if [[ $brace_count -eq 0 ]] && bashunit::regex_match " $line " ' \{' && bashunit::regex_match " $line " ' \}' ; then
524+ local _re_ob=' \{' _re_cb=' \}'
525+ if [[ $brace_count -eq 0 ]] && [[ " $line " =~ $_re_ob ]] && [[ " $line " =~ $_re_cb ]]; then
516526 echo " ${current_fn} :${fn_start} :${lineno} "
517527 in_function=0
518528 current_fn=" "
0 commit comments