go-mutesting icon indicating copy to clipboard operation
go-mutesting copied to clipboard

Exclude vendor/

Open mcandre opened this issue 8 months ago • 2 comments

This framework interacts poorly with go mod vendor. When asked to scan the first party project code, it makes the mistake of scanning vendor/ as well.

$ go-mutesting ./...

Please clarify how to exclude file/folder patterns in the CLI tool.

And please exclude vendor directories by default, as other Go tools do.

mcandre avatar May 09 '25 19:05 mcandre

@mcandre You can just pass a list of packages to go‑mutesting instead of handing the ./... pattern. In our CI we do something like:

# scripts/mutate.sh
set -euo pipefail

packages=$(
  go list ./internal/partner/builder/... \
    ./internal/app/compliance/service \
    # …add whichever first‑party packages you actually care about…
)

go-mutesting \
  --exec "./scripts/mutation_exec.sh" \
  --debug \
  ${packages}

That keeps the run scoped to the code we actually want to harden.

The --exec hook is also overriding the default behavior. Our scripts/mutation_exec.sh swaps the mutant into place, runs go test with a fixed GOCACHE and targets the mutated package, restores the original file, and returns the exit status. In short:

mv "$MUTATE_ORIGINAL" "$MUTATE_ORIGINAL.tmp"
cp "$MUTATE_CHANGED" "$MUTATE_ORIGINAL"

# run go test for exactly the mutated package so we don't explode the target set
go test -timeout "${MUTATE_TIMEOUT:-60}s" "${MUTATE_PACKAGE}"

# restore the original file on the way out
# (+ cleanup on EXIT, HUP, INT, TERM)
mv "$MUTATE_ORIGINAL.tmp" "$MUTATE_ORIGINAL"

with some boilerplate around trapping signals and pretty reporting.

So even though we don’t have a vendor/ tree to exclude at present, we avoid the same explosion of targets by explicitly listing the packages we intend to mutate and letting the exec wrapper manage the single mutated file.

ignatremizov avatar Nov 05 '25 10:11 ignatremizov

Also just found ExcludeDirs config. You can configure in a yaml file a list of search paths and pass it to go-mutesting, but I have not used this.

ignatremizov avatar Nov 05 '25 11:11 ignatremizov