commandscope

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package commandscope answers which packages one test command executes.

Ditto scopes mutants to a change and judges them with a single configured test command, and those are two different questions. A staged change that spans five packages, judged by a command that names one of them, produces mutants in packages the command never builds: nothing it runs can kill them, so they survive, and the score that comes back mixes "your tests missed this" with "your command cannot see this". Measured on the report that produced this package: 43 mutants, 23 killed, 20 survived, and 17 of those survivors in a package the command never executes — a run whose ceiling was 0.605, printed as 0.53 against a bar of 0.80. docs/reports/ditto-mutation-scope.md.

Nothing here parses the command. Ditto asks the toolchain instead, twice:

  • `go test -json` names every package it executes, and that stream is already in hand: the baseline run every release makes once produces it.
  • `go list -deps -test` names every package those compile in, which is the side that decides whether a mutant could be killed at all. A mutant in a dependency of a named package IS killable by that package's tests, so naming the package is too narrow an answer; `-test` is what makes a test-only import count.

A command that emits no such stream — make, gotestsum, a wrapper script — is not guessed at: its scope is unknown, and unknown refuses nothing. A missing accusation costs a number somebody configured an opaque command to get; a wrong one fails a run that was correct, which is the direction this repository does not fail in.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OSRunner

type OSRunner struct{}

OSRunner runs processes with the inherited git addressing removed.

func (OSRunner) Output

func (OSRunner) Output(dir, name string, args ...string) ([]byte, error)

type Runner

type Runner interface {
	Output(dir, name string, args ...string) ([]byte, error)
}

Runner runs one process, so the toolchain call can be pinned in a test.

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope is what one test command compiles, read from the stream it produced.

func New

func New(output, root string, runner Runner) *Scope

New reads the packages a `go test -json` stream named, and answers the toolchain's own question about the rest when it is asked.

root is the directory the command ran in: the mutated tree, not the checkout it came from. Every answer is relative to it.

func (*Scope) Executes

func (s *Scope) Executes(relativePath string) bool

Executes reports whether the command compiles the package that owns a repository-relative source path.

The answer is per package and not per file. A file the package does not compile on this platform — one behind a build tag for another operating system — is inside a package the command executes, and its mutants stay survivors. That is the boundary of this check: it separates "the command never builds this code" from "nothing ran this code", and only the first is a scope mismatch.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL