Skip to content

perf(runner): collapse detect_runtime_error error scan #668

@Chemaclass

Description

@Chemaclass

Context

bashunit::runner::detect_runtime_error (src/runner.sh:93-114) loops over 23 error strings, running case on each iteration. For test outputs without errors (the common case) it walks the full list.

Proposal

Collapse to a single case with glob alternation, short-circuit early:

function bashunit::runner::detect_runtime_error() {
  local runtime_output=\$1
  case \"\$runtime_output\" in
    *\"command not found\"* | *\"unbound variable\"* | *\"permission denied\"* | \\
    *\"no such file or directory\"* | *\"syntax error\"* | *\"bad substitution\"* | \\
    *\"division by 0\"* | *\"cannot allocate memory\"* | *\"bad file descriptor\"* | \\
    *\"segmentation fault\"* | *\"illegal option\"* | *\"argument list too long\"* | \\
    *\"readonly variable\"* | *\"missing keyword\"* | *killed* | \\
    *\"cannot execute binary file\"* | *\"invalid arithmetic operator\"* | \\
    *\"ambiguous redirect\"* | *\"integer expression expected\"* | \\
    *\"too many arguments\"* | *\"value too great\"* | \\
    *\"not a valid identifier\"* | *\"unexpected EOF\"*)
      local runtime_error=\"\${runtime_output#*: }\"
      printf '%s' \"\${runtime_error//\$'\\n'/}\"
      return 0
      ;;
  esac
  printf ''
}

Single pattern match, no Bash loop, no per-iteration case setup.

Acceptance

  • Single case matches all error strings
  • Existing tests covering runtime error detection green
  • No behavioral change in error string extraction
  • Bash 3.0+ compat preserved
  • Benchmark on error-free output paths reported in PR

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestrefactoringRefactoring or cleaning related

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions