Skip to content

feat: add --list and --dry-run flags to gomu run - #91

Merged
sivchari merged 3 commits into
sivchari:mainfrom
xen0l:mutators-list-dry-run
Jul 10, 2026
Merged

sivchari merged 3 commits into
sivchari:mainfrom
xen0l:mutators-list-dry-run

Conversation

@xen0l

@xen0l xen0l commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds two discovery-only flags to gomu run, implementing #90. Both stop short of the execution phase, so they are fast and side-effect-free.

-l, --list

Prints the catalog of supported mutators with one-line descriptions and exits — no path, no AST walk, no mutation.

$ gomu run --list
Supported mutators (17):
  arithmetic          Replace arithmetic operators (+, -, *, /, %)
  conditional         Replace comparison operators (==, !=, <, <=, >, >=)
  ...

--dry-run

Runs the real file-selection and mutant-generation pipeline and prints which mutations would run per file, but executes nothing (no overlay build, no go test, no report, no CI gate). It honors --incremental, so it reflects exactly what a real run would process; --incremental=false previews every file.

$ gomu run --dry-run ./...
Dry run: analyzing 2 file(s) (no mutations will be executed)

pkg/foo/foo.go (3 mutants)
  L12:7  arithmetic_binary  Replace + with -
  ...

Total: 3 mutant(s) across 1 file(s)

Implementation

Respects the existing cmd/gomu → pkg/gomu → internal/mutation layering.

  • internal/mutation: adds Description() to the Mutator interface (implemented by every mutator) and an exported SupportedMutators() that returns the registry without constructing an analyzer. No new mutator structs, so registry.go and its generator are untouched (go generate is a no-op).
  • pkg/gomu: adds public MutatorInfo + SupportedMutators(); adds a DryRun option; Run() branches to an io.Writer-based dry-run formatter right after file discovery, before any execution or reporting.
  • cmd/gomu: registers --list/-l and --dry-run on the run command; --list is handled first via listMutators using text/tabwriter for alignment.

Tests

  • every mutator reports a unique, non-empty Name() / Description()
  • dry-run formatter output, the SupportedMutators() mapping, and an end-to-end Run(DryRun) test asserting no report or history file is produced
  • listMutators output

Verification

go build ./..., go vet ./..., go test ./... pass; go generate ./internal/mutation leaves registry.go unchanged.

xen0l added 2 commits June 19, 2026 21:36
Add a -l/--list flag to the run command that prints the catalog of
supported mutators with one-line descriptions and exits, without
discovering files or running any mutation.

To back the catalog, the Mutator interface gains a Description() method
(implemented by every mutator) and an exported SupportedMutators()
accessor that returns the registry without constructing an analyzer.
pkg/gomu re-exports this as MutatorInfo/SupportedMutators so the CLI
depends only on the public API.
Add a --dry-run flag to the run command that runs the real file-selection
and mutant-generation pipeline and prints which mutations would run per
file, but executes nothing: no overlay build, no go test, no report, and
no CI gate.

Dry run reuses the existing incremental file selection, so it reflects
exactly what a real run would process; pass --incremental=false to
dry-run every file.
Comment thread pkg/gomu/engine.go

// writeDryRunFile renders a file's discovered mutants as an aligned table.
func writeDryRunFile(w io.Writer, file string, mutants []mutation.Mutant) {
fmt.Fprintf(w, "\n%s (%d mutants)\n", file, len(mutants))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to print relative path, not absolute path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose working-directory relative paths. The issue fixed in e8a660c

Discovered files are absolute (derived from the resolved target path);
display them relative to the working directory via
analysis.GetRelativePath, addressing PR review feedback.
@sivchari
sivchari merged commit cb0ba6e into sivchari:main Jul 10, 2026
5 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 10, 2026
sivchari added a commit that referenced this pull request Jul 10, 2026
Propagate the tabwriter Flush error in writeDryRunFile instead of
suppressing it with nolint, hint that --dry-run's empty result may be
due to the incremental filter, and warn on stderr when --list is
combined with flags that it silently ignores.
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.

2 participants