Skip to content

refactor: extract config/output packages and return errors from Run#31

Merged
fchimpan merged 2 commits into
mainfrom
refactor/output-package-and-errors
May 10, 2026
Merged

refactor: extract config/output packages and return errors from Run#31
fchimpan merged 2 commits into
mainfrom
refactor/output-package-and-errors

Conversation

@fchimpan

Copy link
Copy Markdown
Owner

Summary

  • Split cmd/mutest into focused packages: config/ (Config struct + Validate) and output/ (text + JSON formatters, RelPathCache, Reporter for mode dispatch).
  • Add output.Reporter that encapsulates text vs JSON and verbose vs not, so run() reads as a linear pipeline instead of branching on cfg.JSON / cfg.DryRun at every step.
  • Replace init() with a lazy resolveVersion() that only runs on -version.
  • Convert Run / run return type from int exit code to error. Expose sentinels (ErrTestsFailed, ErrInvalidConfig, ErrDiscovery, ErrDiff, ErrInstrumentation, ErrBuild) so tests and callers can identify which pipeline stage failed via errors.Is. main.go simply prints the error and exits 1.

Test plan

  • go test ./... -race passes
  • go vet ./... passes
  • mutest -dry-run still lists discovered points (text + -json)
  • mutest -workers 0 still prints mutest: invalid config: ... and exits 1
  • mutest -threshold 90 exits 1 when kill rate is below threshold
  • mutest -version still prints commit/build info from debug.ReadBuildInfo for go install builds

fchimpan added 2 commits May 10, 2026 11:33
Splits cmd/mutest into focused packages and replaces the int exit code
return with idiomatic error returns.

- Move output formatting + JSON helpers to output/ package
- Move CLI config struct + Validate to config/ package
- Add output.Reporter that encapsulates JSON/text and verbose dispatch
  so run() reads as a linear pipeline
- Replace init() with lazy resolveVersion() (only called on -version)
- Run/run return error; expose sentinels (ErrTestsFailed, ErrInvalidConfig,
  ErrDiscovery, ErrDiff, ErrInstrumentation, ErrBuild) so callers and tests
  can identify which stage failed via errors.Is
- main.go prints err to stderr and exits 1 on any non-nil err
mutest's CI runs mutation testing per-package, so reporter mutants were
not killed by the cmd/mutest integration tests. Add same-package coverage
for each branch in Reporter.

Also drop the redundant JSON+empty early return in DryRun: DryRunJSON
encodes an empty slice as "[]" too, so the early return produced no
observable difference and left a permanently-surviving mutant.
@fchimpan fchimpan self-assigned this May 10, 2026
@fchimpan fchimpan merged commit d1a7ca7 into main May 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant