-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spell incantation for Go toolchain "test" command (#30)
To run the `go test` command of the Go toolchain, the new `spell.Incantation` [1] has been implemented in the new test [2] package that can be used through a Go toolchain caster [3]. The spell incantation is customizable through the following functions: - `WithBlockProfileOutputFileName(blockProfileOutputFileName string) test.Option` - sets the file name for the Goroutine blocking profile file. - `WithCoverageProfileOutputFileName(coverageProfileOutputFileName string) test.Option` - sets the file name for the test coverage profile file. - `WithCPUProfileOutputFileName(cpuProfileOutputFileName string) test.Option` - sets the file name for the CPU profile file. - `WithBlockProfile(withBlockProfile bool) test.Option` - indicates if the tests should be run with a Goroutine blocking profiling. - `WithCoverageProfile(withCoverageProfile bool) test.Option` - indicates if the tests should be run with coverage profiling. - `WithCPUProfile(withCPUProfile bool) test.Option` - indicates if the tests should be run with CPU profiling. - `WithFlags(flags ...string) test.Option` - sets additional flags that are passed to the Go "test" command along with the shared Go flags. - `WithGoOptions(goOpts ...spellGo.Option) test.Option` - sets shared Go toolchain command options. - `WithMemProfile(withMemProfile bool) test.Option` - indicates if the tests should be run with memory profiling. - `WithMemoryProfileOutputFileName(memoryProfileOutputFileName string) test.Option` - sets the file name for the memory profile file. - `WithMutexProfile(withMutexProfile bool) test.Option` - indicates if the tests should be run with mutex profiling. - `WithMutexProfileOutputFileName(mutexProfileOutputFileName string) test.Option` - sets the file name for the mutex profile file. - `WithOutputDir(outputDir string) test.Option` - sets the output directory, relative to the project root, for reports like coverage or benchmark profiles. - `WithoutCache(withoutCache bool) test.Option` - indicates if the tests should be run without test caching that is enabled by Go by default. - `WithPkgs(pkgs ...string) test.Option` - sets the list of packages to test. - `WithTraceProfile(withTraceProfile bool) test.Option` - indicates if the tests should be run with trace profiling. - `WithTraceProfileOutputFileName(traceProfileOutputFileName string) test.Option` - sets the file name for the execution trace profile file. - `WithVerboseOutput(withVerboseOutput bool) test.Option` - indicates if the test output should be verbose. [1]: https://pkg.go.dev/github.com/svengreb/wand/pkg/spell#Incantation [2]: https://pkg.go.dev/github.com/svengreb/wand/pkg/spell/golang/test [3]: https://pkg.go.dev/github.com/svengreb/wand/pkg/cast/golang#Caster Closes GH-29
- Loading branch information
Showing
3 changed files
with
441 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,313 @@ | ||
// Copyright (c) 2019-present Sven Greb <development@svengreb.de> | ||
// This source code is licensed under the MIT license found in the LICENSE file. | ||
|
||
package test | ||
|
||
import ( | ||
spellGo "github.com/svengreb/wand/pkg/spell/golang" | ||
) | ||
|
||
const ( | ||
// DefaultIntegrationTestTag is the default name of tag for integration tests. | ||
DefaultIntegrationTestTag = "integration" | ||
|
||
// DefaultBlockProfileOutputFileName is the default file name for the Goroutine blocking profile file. | ||
DefaultBlockProfileOutputFileName = "block_profile.out" | ||
|
||
// DefaultCoverageOutputFileName is the default file name for the test coverage profile file. | ||
DefaultCoverageOutputFileName = "cover_profile.out" | ||
|
||
// DefaultCPUProfileOutputFileName is the default file name for the CPU profile file. | ||
DefaultCPUProfileOutputFileName = "cpu_profile.out" | ||
|
||
// DefaultMemoryProfileOutputFileName is the default file name for the memory profile file. | ||
DefaultMemoryProfileOutputFileName = "mem_profile.out" | ||
|
||
// DefaultMutexProfileOutputFileName is the default file name for the mutex profile file. | ||
DefaultMutexProfileOutputFileName = "mutex_profile.out" | ||
|
||
// DefaultOutputDirName is the default output directory name for test artifacts like profiles and reports. | ||
DefaultOutputDirName = "test" | ||
|
||
// DefaultTraceProfileOutputFileName is the default file name for the execution trace profile file. | ||
DefaultTraceProfileOutputFileName = "trace_profile.out" | ||
) | ||
|
||
// Options are spell incantation options for the Go toolchain "test" command. | ||
type Options struct { | ||
*spellGo.Options | ||
|
||
// BlockProfileOutputFileName is the file name for the Goroutine blocking profile file. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
BlockProfileOutputFileName string | ||
|
||
// CoverageProfileOutputFileName is the file name for the test coverage profile file. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
CoverageProfileOutputFileName string | ||
|
||
// CPUProfileOutputFileName is the file name for the CPU profile file. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
CPUProfileOutputFileName string | ||
|
||
// DisableCache indicates if the tests should be run without test caching that is enabled by Go by default. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
DisableCache bool | ||
|
||
// EnableBlockProfile indicates if the tests should be run with a Goroutine blocking profiling. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
EnableBlockProfile bool | ||
|
||
// EnableCoverageProfile indicates if the tests should be run with coverage profiling. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
EnableCoverageProfile bool | ||
|
||
// EnableCPUProfile indicates if the tests should be run with CPU profiling. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
EnableCPUProfile bool | ||
|
||
// EnableMemProfile indicates if the tests should be run with memory profiling. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
EnableMemProfile bool | ||
|
||
// EnableMutexProfile indicates if the tests should be run with mutex profiling. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
EnableMutexProfile bool | ||
|
||
// EnableTraceProfile indicates if the tests should be run with trace profiling. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
EnableTraceProfile bool | ||
|
||
// EnableVerboseOutput indicates if the test output should be verbose. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
EnableVerboseOutput bool | ||
|
||
// Flags are additional flags that are passed to the Go `test` command along with the base Go flags. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
// - https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies | ||
Flags []string | ||
|
||
// MemoryProfileOutputFileName is the file name for the memory profile file. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
MemoryProfileOutputFileName string | ||
|
||
// MutexProfileOutputFileName is the file name for the mutex profile file. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
MutexProfileOutputFileName string | ||
|
||
// OutputDir is the output directory, relative to the project root, for reports like | ||
// coverage or benchmark profiles. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
OutputDir string | ||
|
||
// Pkgs is a list of packages to test. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
Pkgs []string | ||
|
||
// spellGoOpts are shared Go toolchain command options. | ||
spellGoOpts []spellGo.Option | ||
|
||
// TraceProfileOutputFileName is the file name for the execution trace profile file. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
TraceProfileOutputFileName string | ||
} | ||
|
||
// Option is a spell incantation option for the Go toolchain "test" command. | ||
type Option func(*Options) | ||
|
||
// WithBlockProfileOutputFileName sets the file name for the Goroutine blocking profile file. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithBlockProfileOutputFileName(blockProfileOutputFileName string) Option { | ||
return func(o *Options) { | ||
o.BlockProfileOutputFileName = blockProfileOutputFileName | ||
} | ||
} | ||
|
||
// WithCoverageProfileOutputFileName sets the file name for the test coverage profile file. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithCoverageProfileOutputFileName(coverageProfileOutputFileName string) Option { | ||
return func(o *Options) { | ||
o.CoverageProfileOutputFileName = coverageProfileOutputFileName | ||
} | ||
} | ||
|
||
// WithCPUProfileOutputFileName sets the file name for the CPU profile file. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithCPUProfileOutputFileName(cpuProfileOutputFileName string) Option { | ||
return func(o *Options) { | ||
o.CPUProfileOutputFileName = cpuProfileOutputFileName | ||
} | ||
} | ||
|
||
// WithBlockProfile indicates if the tests should be run with a Goroutine blocking profiling. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithBlockProfile(withBlockProfile bool) Option { | ||
return func(o *Options) { | ||
o.EnableBlockProfile = withBlockProfile | ||
} | ||
} | ||
|
||
// WithCoverageProfile indicates if the tests should be run with coverage profiling. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithCoverageProfile(withCoverageProfile bool) Option { | ||
return func(o *Options) { | ||
o.EnableCoverageProfile = withCoverageProfile | ||
} | ||
} | ||
|
||
// WithCPUProfile indicates if the tests should be run with CPU profiling. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithCPUProfile(withCPUProfile bool) Option { | ||
return func(o *Options) { | ||
o.EnableCPUProfile = withCPUProfile | ||
} | ||
} | ||
|
||
// WithFlags sets additional flags that are passed to the Go "test" command along with the shared Go flags. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
// - https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies | ||
func WithFlags(flags ...string) Option { | ||
return func(o *Options) { | ||
o.Flags = append(o.Flags, flags...) | ||
} | ||
} | ||
|
||
// WithGoOptions sets shared Go toolchain command options. | ||
func WithGoOptions(goOpts ...spellGo.Option) Option { | ||
return func(o *Options) { | ||
o.spellGoOpts = append(o.spellGoOpts, goOpts...) | ||
} | ||
} | ||
|
||
// WithMemProfile indicates if the tests should be run with memory profiling. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithMemProfile(withMemProfile bool) Option { | ||
return func(o *Options) { | ||
o.EnableMemProfile = withMemProfile | ||
} | ||
} | ||
|
||
// WithMemoryProfileOutputFileName sets the file name for the memory profile file. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithMemoryProfileOutputFileName(memoryProfileOutputFileName string) Option { | ||
return func(o *Options) { | ||
o.MemoryProfileOutputFileName = memoryProfileOutputFileName | ||
} | ||
} | ||
|
||
// WithMutexProfile indicates if the tests should be run with mutex profiling. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithMutexProfile(withMutexProfile bool) Option { | ||
return func(o *Options) { | ||
o.EnableMutexProfile = withMutexProfile | ||
} | ||
} | ||
|
||
// WithMutexProfileOutputFileName sets the file name for the mutex profile file. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithMutexProfileOutputFileName(mutexProfileOutputFileName string) Option { | ||
return func(o *Options) { | ||
o.MutexProfileOutputFileName = mutexProfileOutputFileName | ||
} | ||
} | ||
|
||
// WithOutputDir sets the output directory, relative to the project root, for reports like coverage or benchmark | ||
// profiles. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithOutputDir(outputDir string) Option { | ||
return func(o *Options) { | ||
o.OutputDir = outputDir | ||
} | ||
} | ||
|
||
// WithoutCache indicates if the tests should be run without test caching that is enabled by Go by default. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithoutCache(withoutCache bool) Option { | ||
return func(o *Options) { | ||
o.DisableCache = withoutCache | ||
} | ||
} | ||
|
||
// WithPkgs sets the list of packages to test. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithPkgs(pkgs ...string) Option { | ||
return func(o *Options) { | ||
o.Pkgs = append(o.Pkgs, pkgs...) | ||
} | ||
} | ||
|
||
// WithTraceProfile indicates if the tests should be run with trace profiling. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithTraceProfile(withTraceProfile bool) Option { | ||
return func(o *Options) { | ||
o.EnableTraceProfile = withTraceProfile | ||
} | ||
} | ||
|
||
// WithTraceProfileOutputFileName sets the file name for the execution trace profile file. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithTraceProfileOutputFileName(traceProfileOutputFileName string) Option { | ||
return func(o *Options) { | ||
o.TraceProfileOutputFileName = traceProfileOutputFileName | ||
} | ||
} | ||
|
||
// WithVerboseOutput indicates if the test output should be verbose. | ||
// See `go help test` and the `go` command documentations for more details: | ||
// - https://golang.org/cmd/go/#hdr-Testing_flags | ||
func WithVerboseOutput(withVerboseOutput bool) Option { | ||
return func(o *Options) { | ||
o.EnableVerboseOutput = withVerboseOutput | ||
} | ||
} | ||
|
||
// newOptions creates new spell incantation options for the Go toolchain "test" command. | ||
func newOptions(opts ...Option) *Options { | ||
opt := &Options{ | ||
BlockProfileOutputFileName: DefaultBlockProfileOutputFileName, | ||
CoverageProfileOutputFileName: DefaultCoverageOutputFileName, | ||
CPUProfileOutputFileName: DefaultCPUProfileOutputFileName, | ||
MemoryProfileOutputFileName: DefaultMemoryProfileOutputFileName, | ||
MutexProfileOutputFileName: DefaultMutexProfileOutputFileName, | ||
TraceProfileOutputFileName: DefaultTraceProfileOutputFileName, | ||
} | ||
for _, o := range opts { | ||
o(opt) | ||
} | ||
|
||
opt.Options = spellGo.NewOptions(opt.spellGoOpts...) | ||
|
||
return opt | ||
} |
Oops, something went wrong.