Documentation ¶
Overview ¶
Package reduce implements a reducer core for reducing the size of test failure cases.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunTest ¶
func RunTest( t *testing.T, path string, filter func([]byte) ([]byte, error), interesting func(contains string) InterestingFn, mode Mode, passes []Pass, )
RunTest executes reducer commands. If the optional filter func is not nil, it is invoked on all "reduce" commands before the reduction algorithm is started. In verbose mode, output is written to stderr. Supported commands:
"contains": Sets the substring that must be contained by an error message for a test case to be marked as interesting. This variable is passed to the `interesting` func.
"reduce": Creates an InterestingFn based on the current value of contains and executes the reducer. Outputs the reduced case.
Types ¶
type File ¶
type File string
File contains the contents of a file.
func Reduce ¶
func Reduce( logger io.Writer, originalTestCase File, isInteresting InterestingFn, numGoroutines int, mode Mode, passList ...Pass, ) (File, error)
Reduce executes the test case reduction algorithm. logger, if not nil, will log progress output. numGoroutines is the number of parallel workers, or 0 for runtime.NumCPU().
type InterestingFn ¶
InterestingFn returns true if File triggers the target test failure. It should be context-aware and stop work if the context is canceled.
type Mode ¶
type Mode int
Mode is an enum specifying how to determine if forward progress was made.
const ( // ModeSize instructs Reduce to use filesize as the progress indicator. ModeSize Mode = iota // ModeInteresting instructs Reduce to use the interestingness as the // progress indicator. That is, if any pass generates an interesting // result (even if the file size increases), that is considered // progress. ModeInteresting )
type Pass ¶
type Pass interface { // New creates a new opaque state object for the input File. New(File) State // Transform applies this transformation pass to the input File using // State to determine which occurrence to transform. It returns the // transformed File, a Result indicating whether to proceed or not, and // an error if the transformation could not be performed. Transform(File, State) (File, Result, error) // Advance moves State to the next occurrence of a transformation in // the given input File and returns the new State. Advance(File, State) State // Name returns the name of the Pass. Name() string }
Pass defines a reduce pass.
func MakeIntPass ¶
MakeIntPass returns a Pass with a state that starts at 0 and increments by 1 each Advance. f is a transformation function that takes the input and an index (zero-based) determining which occurrence to transform. It returns the possibly transformed output and a boolean that is false if a transformation could not be done because i was exhausted.
For example, if f is a func that replaces spaces with underscores, invoking that function with an i value of 2 should return the input string with only the 3rd occurrence of a space replaced with an underscore.
This is a convenience wrapper since a large number of Pass implementations just need their state to increment a counter and don't have to keep track of other things like byte offsets.