Documentation
¶
Index ¶
- func ForceColors() func(Options) Options
- func Gated() func(Options) Options
- func IgnoreSourceFiles(patterns ...string) func(Options) Options
- func Parallel() func(Options) Options
- func Release(t *testing.T, options ...Option)
- func WithChangedRanges(ranges map[string][]Range) func(Options) Options
- func WithMinimumThreshold(minimumThreshold float32) func(Options) Options
- func WithRepositoryRoot(repositoryRoot string) func(Options) Options
- func WithTestCommand(testCommand string) func(Options) Options
- func WithViruses(virus viruses.Virus, rest ...viruses.Virus) func(Options) Options
- type Option
- type Options
- type Range
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ForceColors ¶
ForceColors forces the use of colors in the output. This is useful when running the mutation tests in a CI environment, for example.
func Gated ¶ added in v0.3.0
Gated runs a file's mutants from one compilation instead of one each.
Ditto normally starts the test command once per mutant, and that start costs 750-950 ms whatever the suite does — the dominant cost of a run. With this, the mutants a file can express as one instrumented source are compiled together and selected at run time. Anything that cannot be expressed that way keeps the path it always had, so no mutant is lost by turning it on.
It builds with `go test -c`, so it applies to a Go package and it replaces WithTestCommand for the mutants it takes.
func IgnoreSourceFiles ¶
IgnoreSourceFiles configures regular expressions representing source files to be filtered out and not suffer any mutations.
func Parallel ¶
Parallel indicates whether to run the tests on the mutants in parallel. Given Ditto is executed via Go's testing framework, the level of parallelism can be configured when running the mutation tests. For example, with WithTestCommand(`go test -v -tags=mutation -parallel 3`).
func Release ¶
Release releases the ditto! It infects all source files with viruses that mutate the source code DNA and perform tests to determine whether the mutants survive.
This is the entry point to configure and run mutation tests. You may want to configure it with some options. Here is the available options and their defaults:
- WithRepositoryRoot: `.`
- WithTestCommand: `go test -count=1 ./...`
- WithMinimumThreshold: `1.0`
- Parallel: `false`
- IgnoreSourceFiles: `nil`
- WithViruses: all available (see viruses.Virus' implementations)
The results are then presented in the console. If the mutation score is equal to or above the configured threshold (WithMinimumThreshold), the execution is considered successful. Failed otherwise. Regardless of the execution result, any surviving mutant (no tests failed after applying the source code mutation) will also be presented in the console for analysis.
func WithChangedRanges ¶ added in v0.2.0
WithChangedRanges restricts the release to the given byte ranges of the given files, keyed by repository-relative path with forward slashes.
This is what makes ditto cheap enough to run while you are still writing the code. Every mutant costs a full run of the test command, so mutating a line the change never touched buys nothing and is charged at the same rate as one that matters.
A file with no entry is not mutated at all. A file with an empty range list is mutated whole.
The ranges are kept per file on purpose, and callers should keep them that way too. A byte offset only means something against the file it was measured in, because each file is parsed on its own and every file's positions start from the same base. Ranges from several files merged into one set make every file answer to all of them: mutants appear in code no diff touched, and the number of them grows as the square of the number of files rather than in proportion to it.
func WithMinimumThreshold ¶
WithMinimumThreshold represents the minimum mutation test score to consider the execution successful. A float between `0.0` and `1.0`.
func WithRepositoryRoot ¶
WithRepositoryRoot configures which directory is the repository root. This is usually required when your mutation test file lives some other place that is not root itself.
func WithTestCommand ¶
WithTestCommand configures the test command to run, as string. You may configure it as you wish, as a `makefile` phony target, for example. Or simply run the standard `go test` command with extra flags, such as `timeout` and `tags`.
Types ¶
type Options ¶
type Options struct {
Repository ditto.Repository
TestRunner laboratory.TestRunner
TemporaryDir laboratory.TemporaryDirectory
MinimumThreshold float32
Parallel bool
IgnoreSourceFilesPatterns []*regexp.Regexp
Viruses []viruses.Virus
ChangedRanges map[string][]Range
Gated bool
}
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
gatedlaboratory
Package gatedlaboratory runs a file's mutants from one compilation.
|
Package gatedlaboratory runs a file's mutants from one compilation. |
|
gatedreporter
Package gatedreporter says how much of a run came from one compilation.
|
Package gatedreporter says how much of a run came from one compilation. |
|
gobuildrunner
Package gobuildrunner runs a package's tests from a binary it builds itself, once, instead of invoking `go test` for every mutant.
|
Package gobuildrunner runs a package's tests from a binary it builds itself, once, instead of invoking `go test` for every mutant. |
|
perfbench
Package perfbench holds ditto's performance contract.
|
Package perfbench holds ditto's performance contract. |
|
schemata
Package schemata turns per-mutant source files into one instrumented file that selects a mutant at run time, so a release compiles once instead of once per mutant.
|
Package schemata turns per-mutant source files into one instrumented file that selects a mutant at run time, so a release compiles once instead of once per mutant. |
