Skip to content

Unknown options are silently ignored: a typo'd flag runs a different suite and exits 0 #871

Description

@Chemaclass

🤔 Background

bashunit::main::cmd_test ends its option case with a catch-all that treats any unmatched argument as a test path (src/main.sh:332):

*)
  raw_args[raw_args_count]="$1"
  raw_args_count=$((raw_args_count + 1))
  ;;

Nothing checks whether the argument looks like an option, so a mistyped flag is swallowed and the run continues with different behaviour than the user asked for — and exits 0.

Observed

Input Result
bashunit --parralel No tests found, exit 1
bashunit --parralel tests/unit/math_test.sh exit 0, runs sequentially, no warning
bashunit --filterr nonexistent tests/unit/math_test.sh exit 0, flag and its value swallowed, whole suite runs
$ ./bashunit --parralel --definitely-not-a-flag --xyz tests/unit/math_test.sh
bashunit - 0.43.0 | Tests: 12
...
 All tests passed
$ echo $?
0

No warning on stdout or stderr.

Why it matters

  • --parralel, --strictt, --fail-on-riskyy all degrade silently to the weaker behaviour while still reporting success. In CI that is a green build that never ran the check it was configured to run.
  • The --filter case is the worst: a typo turns "run one test" into "run everything", exit 0 either way. The docs specifically tell agents to loop on --filter, so nothing surfaces the mistake.

Suggested fix

In the catch-all, reject an argument that begins with - as an unknown option (clear message on stderr, non-zero exit) instead of filing it under test paths. The assert subcommand parses its own arguments and is unaffected.

Found while cross-checking documented flags against the parser.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions