Documentation ¶
Index ¶
- Constants
- Variables
- func AssertCallCount(t *testing.T, funcName string, got, want int)
- func AssertDefaultConfig(t *testing.T, got InputsConfig)
- func AssertDiffFailure(t *testing.T, ok bool)
- func AssertDiffSuccess(t *testing.T, ok bool)
- func AssertEnrichedLexSequence(t *testing.T, got, want []RichText)
- func AssertErrors(t *testing.T, got, want []error)
- func AssertLexemes(t *testing.T, got, want []string)
- func AssertListenerNotified(t *testing.T, listener *SpyPrinter, wantTests []Test)
- func AssertNoErrors(t *testing.T, errs []error)
- func AssertResultIDInvariant(t *testing.T, b *TestingBatch)
- func AssertRichText(t *testing.T, got, want RichText)
- func AssertRichTextMask(t *testing.T, got, want []bool)
- func AssertTest(t *testing.T, got Test, want Test)
- func AssertTests(t *testing.T, got []Test, want []Test)
- func AssertText(t *testing.T, got, want string)
- func AssertThreadCount(t *testing.T, pool *SpyThreadPool, want int)
- func AssertTimes(t *testing.T, got map[int]*TestResult, want map[int]time.Duration)
- func AssertVerdicts(t *testing.T, got map[int]*TestResult, want map[int]Verdict)
- func DumpLexemes(xms []RichText, color aurora.Color) string
- func IsFloatLexeme(xm string) bool
- func IsIntLexeme(xm string) bool
- func ScanConfig(text string) (config map[string]string, key2line map[string]NumberedLine, errs []error)
- func ScanKeyValuePair(line string) (string, string, error)
- func ScanLexemes(data []byte, atEOF bool) (advance int, token []byte, err error)
- func SplitByInlinedPrefixN(text, delim string, n int) (parts []string)
- func StringMapUnmarshal(kvm map[string]string, data interface{}, transformers ...func(string) string) error
- type ConfigurableStopwatcher
- type ExecutionResult
- type FieldError
- type Inputs
- type InputsConfig
- type Lexer
- func (l *Lexer) Compare(target, source []string) (rts []RichText, ok bool)
- func (l *Lexer) GenMaskForFloat(target, source string) (mask []bool)
- func (l *Lexer) GenMaskForInt(target, source string) (mask []bool)
- func (l *Lexer) GenMaskForString(target, source string) (mask []bool)
- func (l *Lexer) GenerateMask(target, source string) []bool
- func (l *Lexer) Scan(text string) (xms []string)
- type LineRangeError
- type NotTextUnmarshalableTypeError
- type NotValueOfTypeError
- type NumberedLine
- type PositiveDuration
- type Processer
- type ProcesserFunc
- type RichText
- type Runnable
- type RunnableFunc
- type SpyPrinter
- type SpyProcesser
- type SpyThreadPool
- type Stopwatcher
- type StringError
- type StringWarning
- type StubTestingEventListener
- type Test
- type TestError
- type TestExecutionResult
- type TestFinishedCallback
- type TestResult
- type TestingBatch
- type TestingEventListener
- type ThreadPool
- type Verdict
- type WorkerPool
Constants ¶
const ( STRXM lexemeType = iota FLOATXM INTXM FINALXM )
Available lexeme types. The following invariant holds: each type is a specialization of all types whose numerical value is less than that of self. For example, 42 is a float and is an int, but 42.2 is a float but not an int. Hence, int is a specialization of float. A type T is a specialization of a type U if any value of type T is of type U also.
The consequence is that between any two types T and U from the list there's always a specialization relationship, but in gerenal, this is not the case. For example: imagine a lexeme type 'hash' that classifies strings of form 2400f9b. The float is not a specialization of hash, because 42.2 is not a hash, and likewise the hash is not a specialization of float, because 2400f9b is not a float.
const ( IOSeparatorMissing = StringError("IO separator missing") KeyMissing = StringError("key cannot be empty") )
A set of errors that may be produced during scanning of the inputs file.
const ( IODelim = "---" TestDelim = "===" )
The set of delimeters used when partitioning inputs file.
const ( // ErrNotAStructLike is issued when a destination type doesn't behave like // a struct. struct and *struct types have the same syntax for manipulating // them, so they are considered struct-like. ErrNotAStructLike = StringError("not a struct-like") // ErrUnknownField is issued when the deserialization destination cannot be // found in a struct-like via reflection. ErrUnknownField = StringWarning("unknown field") // ErrNegativePositiveDuration is issued when PositiveDuration is attempted // to be initialized with negative value. ErrNegativePositiveDuration = StringError("PositiveDuration accepts only positive durations") // ErrDurationWithoutSuffix is issued when PositiveDuration is unmarshalled // with a value that doesn't have a unit suffix. ErrDurationWithoutSuffix = StringWarning("durations without a unit suffix like \"s\" or \"us\" are deprecated and discouraged. Please, specify the unit explicitly, like \"10.0s\" for 10 seconds") // ErrDurationBadSyntax is issued when PositiveDuration is unmarshalled // with a value that cannot be interpreted as a duration. ErrDurationBadSyntax = StringError("bad syntax. Correct values could be \"1s\" or \"12.3ms\"") )
const AltLineFeed = "\\n"
AltLineFeed is the representation of LF in textual form, that replaces LF when it's colorized.
Variables ¶
var Au aurora.Aurora
Au is used to colorize output of several functions. A user of the library can change its value to disable colored output. Refer to the aurora readme for that.
var MaskGenerators = []func(*Lexer, string, string) []bool{ (*Lexer).GenMaskForString, (*Lexer).GenMaskForFloat, (*Lexer).GenMaskForInt, }
MaskGenerators lists all of the mask generating functions (MGF). MGFs are defined only for arguments of the same type. I.e., there's no MGF for float and int, only for float/float, and int/int. If differnt types must be assessed, the MGF of their common type_ must be called. The common type between two types T and U exists if specialization relationship between them exists and is the least specialized type. The index of MGF in this array corresponds to the numerical value of the type of which MGF's arguments are.
var TypeCheckers = []func(string) bool{ IsFloatLexeme, IsIntLexeme, }
TypeCheckers defines a list type checking functions (TCF). The type checker for string is omitted because it always returns true. Hence, the index of TCF corresponds to a type of numerical value `index+1`.
var ValidIntMaxLen = 10
ValidIntMaxLen is maximum number of digits a lexeme may have to be considered an int
Functions ¶
func AssertCallCount ¶
AssertCallCount checks that the received and expected number of calls are equal.
func AssertDefaultConfig ¶
func AssertDefaultConfig(t *testing.T, got InputsConfig)
AssertDefaultConfig checks that the received key-value set is empty. If it's not, the test is failed and the its contents are printed.
func AssertDiffFailure ¶
AssertDiffFailure chacks if lexeme comparison returned ok = false.
func AssertDiffSuccess ¶
AssertDiffSuccess chacks if lexeme comparison returned ok = true.
func AssertEnrichedLexSequence ¶
AssertEnrichedLexSequence checks that both lexeme sequences render to the same string.
func AssertErrors ¶
AssertErrors compared received array of errors with the expected one.
func AssertLexemes ¶
AssertLexemes compares if the two LexSequences are equal.
func AssertListenerNotified ¶
func AssertListenerNotified(t *testing.T, listener *SpyPrinter, wantTests []Test)
func AssertNoErrors ¶
AssertNoErrors will check if the array of errors is empty. If it's not empty, the test will be failed and the errors will be reported.
func AssertResultIDInvariant ¶
func AssertResultIDInvariant(t *testing.T, b *TestingBatch)
AssertResultIDInvariant checks that each key in TestingBatch.Results equals to the its value`s ID field.
func AssertRichText ¶
AssertRichText checks that the contents and the bitmasks of both RichTexts are equal.
func AssertRichTextMask ¶
AssertRichTextMask checks that both bitmasks to be used in RichText are equal.
func AssertTest ¶
AssertTest compare the inputs and outputs with respective expected ones for equivalence.
func AssertTests ¶
AssertTests will compare received array of tests with the expected one.
func AssertText ¶
AssertText checks two strings for equality, but escapes all newlines.
func AssertThreadCount ¶
func AssertThreadCount(t *testing.T, pool *SpyThreadPool, want int)
AssertThreadCount thread-safely checks that the pool has the specified number of threads created during its lifetime.
func AssertTimes ¶
AssertTimes check whether the received and expected timestampts for the test cases both exist and are equal.
func AssertVerdicts ¶
AssertVerdicts checks that received and expected verdict maps contain the same keys, and then checks that the values for these keys equal.
func DumpLexemes ¶
DumpLexemes is used to transform array of possibly colorized lexemes into a human readable format. The lexemes are separated by spaces. There are no trailing spaces. Colorized newlines are replaced by printable AltLineFeed string + a newline.
func IsFloatLexeme ¶
IsFloatLexeme returns true if the string represents a floating-point value. Although, there can be no floating-point inside of it. A floating-point value is of form int_part['.' ('0'-'9')*]
func IsIntLexeme ¶
IsIntLexeme returns true if the string represents a signed integer. Additionally, it should contain not more than VALID_INT_MAX_LEN digits.
func ScanConfig ¶
func ScanConfig(text string) (config map[string]string, key2line map[string]NumberedLine, errs []error)
ScanConfig tries to parse a stream of key-value pairs. Key-value pair is defined as `<string> "=" <string>`. Both strings are space trimmed. The key must be non-empty. Otherwise, a LineRangeError is issued. Duplicate keys are allowed, the later occurrence is preferred.
The function returns two maps: the first is a key-value map as defined in the supplied text, and the second maps keys to the relevant lines inside the config. The first one will contain only correctly defined keys. The second one is mainly used to correlate errors from StringMapUnmarshal to the inputs.txt lines and produce error messages.
func ScanKeyValuePair ¶
ScanKeyValuePair parses the key-value pair of form 'key=value'. Strings without assignment are treated as keys with empty value. Strings with assignment but with empty key are erroneous. The space around key and value respectively is trimmed.
func ScanLexemes ¶
ScanLexemes is a split function for bufio.Scanner. It is same as bufio.ScanWords, except that it treats \n character in a special way. \n cannot be in any lexeme, except for "\n" itself. Hence, several \n\n are parsed as separate lexemes ("\n", "\n"). It will never return an empty lexeme. The definition of other spaces is set by unicode.IsSpace.
func SplitByInlinedPrefixN ¶
SplitByInlinedPrefixN works in the same way as strings.SplitN. However, it does one additional thing. It matches the *prefixes of the lines* for equality with the delimeter. Upon match the entire line is discarded.
If text doesn't contain the delimeter, only one part is returned. User can specify the number of parts they want at most via the third argument.
func StringMapUnmarshal ¶
func StringMapUnmarshal(kvm map[string]string, data interface{}, transformers ...func(string) string) error
StringMapUnmarshal accepts a string map and for each key-value pair tries to find an identically named field in the provided object, parse the string value according to the field's type and assign the parsed value to it.
The field's type should be: int (any flavor), uint (any flavor), string, bool, any struct or a pointer to a struct. The structs should implement encoding.TextUnmarshaler standard interface to be parsed by this function, otherwise NotUnmarshalableTypeError is issued.
If the destination object is not struct or a pointer to a struct, ErrNotAStructLike is issued.
If a map's key cannot be mapped to a field within the destination object, FieldError wrapping ErrUnknownField is issued.
If a map's value cannot be parsed to the destination type, a FieldError wrapping a NotValueOfTypeError is issued.
StringMapUnmarshal makes sure that if any error occurs during unmarshaling of a field, the field's previous value is retained.
This function will accumulate all produced errors and return an instance of *multierror.Error type.
Since a key must match the field's name perfectly, and this function operates only on exported fields, this would mean that only capitalized keys would be accepted. This may not be desired. An array of transformers can be supplied to change the field matching behavior. Each map's key will be fed to one transformer at a time in the order they were passed to this function, until a match is found. The transformer's job, then, is to convert an arbitrary string to a possible exported field's name in the destination object. If a transformer succeeds, the successive transformers are not applied. If the field still could not be found, a FieldError wrapping ErrUnknownField is issued.
Types ¶
type ConfigurableStopwatcher ¶
ConfigurableStopwatcher implements Stopwatcher and allows its user to fully customize it with no make function required.
func (*ConfigurableStopwatcher) Elapsed ¶
func (s *ConfigurableStopwatcher) Elapsed(since time.Time) time.Duration
Elapsed will return the duration since the `since` time, or zero if `since` is in the future.
func (*ConfigurableStopwatcher) Now ¶
func (s *ConfigurableStopwatcher) Now() time.Time
Now will return time point since internal's clock epoch.
func (*ConfigurableStopwatcher) TimeLimit ¶
func (s *ConfigurableStopwatcher) TimeLimit(since time.Time) <-chan time.Time
TimeLimit for a given `since` time point returns a channel that will return at `since` + TL time point the very same time point. I.e., it works just just like time.After, but you can specify the *time* after which you want to be notified.
type ExecutionResult ¶
ExecutionResult contains the text printed to stdout and stderr by the process and the exit code returned upon termination.
type FieldError ¶
FieldError is a generic error that can be produced while unmarshaling string maps. It enriches error Err with the name of the field relevant to it.
func (*FieldError) Error ¶
func (e *FieldError) Error() string
Error renders the underlying error preceeded with the field's name.
func (*FieldError) Unwrap ¶
func (e *FieldError) Unwrap() error
Unwrap makes FieldError usable with built-in errors package.
type Inputs ¶
type Inputs struct { Tests []Test Config InputsConfig }
Inputs contains all information located in the inputs file: tests and a valid configuration that were provided. Inputs is supposed to be copied around.
func ScanInputs ¶
ScanInputs is the main routine for parsing inputs file. It splits the input by test case separator, and tries to parse each individual test case one by one. At the very beginning of the input file a configuration map can be specified (refer to ScanConfig for syntax), granted that it is not part of a meaninful test case. The empty tests are skipped (those that composed of non-printable characters and that don't contain IO separator). If a test case could not be parsed, parsing continues to the next test case, but the errors are accumulated and returned together.
type InputsConfig ¶
type InputsConfig struct { Prec uint8 Tl PositiveDuration }
InputsConfig defines a schema for available configuration options that can be listed inside a config.
var DefaultInputsConfig InputsConfig
DefaultInputsConfig is used to define default values for the InputsConfig inside Inputs. It is a starting ground. It may be altered further by customization points inside the inputs.txt file.
type Lexer ¶
type Lexer struct {
Precision uint
}
Lexer is a set of settings that control lexeme scanning and comparison. And the methods for scanning and comparison are conviniently methods of Lexer.
func (*Lexer) Compare ¶
Compare compares target against source and generates colored target's lexems highlighting mismatches between them. Additionally, actual comparison takes place between two non-LF lexems, and the spurious LFs are marked red and skipped. The function is intended to be called twice for the two permutations of the arguments to get error highlighting for both strings.
func (*Lexer) GenMaskForFloat ¶
GenMaskForFloat uses the same logic as GenMaskForInt to highlight the whole part. If at least one digit in the fractional part (part after the dot) is different and its index (zero-based) is less than lexer's precision, this digit is highlighted.
func (*Lexer) GenMaskForInt ¶
GenMaskForInt will highlight the whole number if at least one digit is different. Independently, the sign will be highlighted if it's different also.
func (*Lexer) GenMaskForString ¶
GenMaskForString will highlight mismatching characters.
func (*Lexer) GenerateMask ¶
GenerateMask is a wrapper function that finds the common type of the two lexems and generates a color mask for the target based on source.
type LineRangeError ¶
LineRangeError is used to amend information about the location of the error within the source code. The source code lines in question are stored in Lines (for printing purposes).
func (*LineRangeError) CodeSnippet ¶
func (e *LineRangeError) CodeSnippet() string
CodeSnippet is responsible for producing pretty printed source code lines with corresponding line numbers to the left of them.
func (*LineRangeError) Error ¶
func (e *LineRangeError) Error() string
Error renders contents of Err.Error() preceeded by a line number (or a line range), followed by the line numbered code snippet (if provided) on a new line. The error string is terminated with '\n', unless Lines is not nil. It uses Reason and CodeSnippet under the hood.
func (*LineRangeError) Reason ¶
func (e *LineRangeError) Reason() string
Reason is a stripped down version of Error in sense that it returns only the underlying error's message and a line information, with no '\n' at the end.
func (*LineRangeError) Unwrap ¶
func (e *LineRangeError) Unwrap() error
Unwrap makes LineRangeError usable with built-in errors package.
type NotTextUnmarshalableTypeError ¶
NotTextUnmarshalableTypeError is a panic error. Value of this type is passed to panic(), mainly during unmarshaling of string maps.
func (*NotTextUnmarshalableTypeError) Equal ¶
func (e *NotTextUnmarshalableTypeError) Equal(other *NotTextUnmarshalableTypeError) bool
Equal is used to define equality on NotTextUnmarshalableTypeError pointers. Used by go-testdeep.
func (*NotTextUnmarshalableTypeError) Error ¶
func (e *NotTextUnmarshalableTypeError) Error() string
Error renders a helpful message addressed to the developer, describing possible reasons as to why type could not be unmarshaled.
type NotValueOfTypeError ¶
NotValueOfTypeError is a generic basic error type that describes a value and a type that don't match. This error is produced mainly during unmarshaling string maps.
func (*NotValueOfTypeError) Equal ¶
func (e *NotValueOfTypeError) Equal(other *NotValueOfTypeError) bool
Equal is used to define equality on the pointers of NotValueOfTypeError. Used by go-testdeep.
func (*NotValueOfTypeError) Error ¶
func (e *NotValueOfTypeError) Error() string
Error prints a human-readable message describing what value doesn't match what type.
func (*NotValueOfTypeError) Unwrap ¶ added in v0.7.0
func (e *NotValueOfTypeError) Unwrap() error
Unwrap returns the reason for the error, if available.
type NumberedLine ¶
NumberedLine is used to assign line number information to a string. It is used to map string map keys produced during config parsing to the relevant lines for error reporting.
type PositiveDuration ¶
PositiveDuration is a wrapper around time.Duration that allows StringMapsUnmarshal to parse it from a string and that forbids negative durations. Implements encoding.TextUnmarshaler.
func NewPositiveDuration ¶
func NewPositiveDuration(dur time.Duration) PositiveDuration
NewPositiveDuration returns a PositiveDuration with the specified value. Panics if value is negative.
func (*PositiveDuration) UnmarshalText ¶
func (d *PositiveDuration) UnmarshalText(b []byte) error
UnmarshalText will delegate parsing to built-in time.ParseDuration and, hence, accept the same format as time.ParseDuration. It will also reject negative durations.
type ProcesserFunc ¶
ProcesserFunc represents an implementation of Processer that instead of a real OS-level process executes Go code.
func (ProcesserFunc) Run ¶
func (p ProcesserFunc) Run(ctx context.Context, r io.Reader) (ExecutionResult, error)
Run will call the underlying Go function to compute the result.
type RichText ¶
RichText represents a text data with additional color metadata in a form of a bitmask. The characters may be either colored or uncolored. The _color_ might represent a literal color or a formatting style like bold or italics.
type Runnable ¶
type Runnable interface {
Run()
}
Runnable represents a callable object. It allows representing the closure of a function as well-defined struct fields with the function in question having no closure (the Run() method).
type RunnableFunc ¶
type RunnableFunc func()
RunnableFunc adapts basic golang functions for the Runnable interface.
type SpyPrinter ¶
SpyPrinter implements TestingEventListener and is only concerned with storing the information received from the callbacks, so that its correctness can be assessed later.
func (*SpyPrinter) SuiteFinished ¶
func (l *SpyPrinter) SuiteFinished(*TestingBatch)
SutieFinished turn Finished true.
func (*SpyPrinter) TestFinished ¶
func (l *SpyPrinter) TestFinished(test *Test, result *TestResult)
TestFinished amends the test and the ID of the test to FinishedTests and FinishedIDs respectively.
func (*SpyPrinter) TestStarted ¶
func (l *SpyPrinter) TestStarted(id int)
TestStarted amends the ID of the test to StartedIDs
type SpyProcesser ¶
type SpyProcesser struct { Proc Processer // contains filtered or unexported fields }
SpyProcesser is a test double that proxies another processer. It additionally stores the number of calls made to the Run function.
func (*SpyProcesser) CallCount ¶
func (p *SpyProcesser) CallCount() int
CallCount will return the number of times Run was called. Can be called concurrently.
func (*SpyProcesser) Run ¶
func (p *SpyProcesser) Run(ctx context.Context, r io.Reader) (ExecutionResult, error)
Run will execute the Run function of the inner processer, but will also increase the call count by one.
type SpyThreadPool ¶
type SpyThreadPool struct { DirtyThreads map[int]struct{} // contains filtered or unexported fields }
SpyThreadPool implements the same functionality as ThreadPool, but also tracks the goids of the threads involved in task execution. This is used to assert that an exact number of threads was invoked.
func NewSpyThreadPool ¶
func NewSpyThreadPool(threadCount int) *SpyThreadPool
NewSpyThreadPool creates a thread pool with the specified number of preallocated threads in the pool.
func (*SpyThreadPool) Execute ¶
func (p *SpyThreadPool) Execute(task Runnable) error
Execute tries to find a worker to assign the task to. If it doesn't find one, it may or may NOT give an error. When error is returned is unspecified, but it shouldn't happen within general usage.
func (*SpyThreadPool) WorkerCount ¶
func (p *SpyThreadPool) WorkerCount() int
WorkerCount returns the number of currently allocated threads. These may or may not have any tasks assigned to them.
type Stopwatcher ¶
type Stopwatcher interface { Now() time.Time Elapsed(since time.Time) time.Duration TimeLimit(since time.Time) <-chan time.Time }
Stopwatcher abstracts away the concept of the stopwatch. At any time, one can look up the elapsed time. Additionally, one can be notified when the time is up.
type StringError ¶
type StringError string
StringError is an error type whose values can be constant and compared against deterministically with == operator. An error type that solves the problems of sentinel errors.
const TLError StringError = "Time limit exceeded"
TLError is an error that can occur during Processer execution that indicates that it was prematurely killed by TestingBatch, because it exceeded the time limit.
func (StringError) Error ¶
func (e StringError) Error() string
Error makes StringError satisfy error interface.
type StringWarning ¶ added in v0.7.0
type StringWarning string
StringWarning is same as StringError except it allows users to differentiate warnings using errors.As
func (StringWarning) Error ¶ added in v0.7.0
func (w StringWarning) Error() string
Error prints the warning message.
type StubTestingEventListener ¶
type StubTestingEventListener struct{}
StubTestingEventListener implements TestingEventsListener, but does nothing. It is used when constructing TestingBatch.
func (*StubTestingEventListener) SuiteFinished ¶
func (*StubTestingEventListener) SuiteFinished(*TestingBatch)
SuiteFinished is a stub that does nothing.
func (*StubTestingEventListener) TestFinished ¶
func (*StubTestingEventListener) TestFinished(*Test, *TestResult)
TestFinished is a stub that does nothing.
func (*StubTestingEventListener) TestStarted ¶
func (*StubTestingEventListener) TestStarted(int)
TestStarted is a stub that does nothing.
type TestError ¶
TestError is a scold centric error type that maps a test's index inside inputs.txt to a particular error Err.
type TestExecutionResult ¶
type TestExecutionResult struct { ID int Err error Out ExecutionResult }
TestExecutionResult carries an output of the process together with the corresponding test ID and a TestingBatch related error if any (panics, etc.).
type TestFinishedCallback ¶
type TestFinishedCallback func(*Test, *TestResult)
TestFinishedCallback allows to use a simple function in places where TestingEventLister is needed, to handle the TestFinished event.
func (TestFinishedCallback) SuiteFinished ¶
func (cb TestFinishedCallback) SuiteFinished(*TestingBatch)
SuiteFinished is a stub that does nothing
func (TestFinishedCallback) TestFinished ¶
func (cb TestFinishedCallback) TestFinished(test *Test, result *TestResult)
TestFinished will call the underlying function with its arguments.
func (TestFinishedCallback) TestStarted ¶
func (cb TestFinishedCallback) TestStarted(int)
TestStarted is a stub that does nothing.
type TestResult ¶
type TestResult struct { RichOut []RichText RichAnswer []RichText Verdict Verdict Time time.Duration TestExecutionResult }
TestResult encapsulates all the information TestingBatch produced for a particular test.
type TestingBatch ¶
type TestingBatch struct { Results map[int]*TestResult Lx *Lexer Proc Processer ThreadPool WorkerPool Swatch Stopwatcher Listener TestingEventListener // contains filtered or unexported fields }
TestingBatch is responsible for running tests and evaluating the verdicts for tests. For each test case, the verdict and execution time are stored. It utilizes an instance of Processer to run tests, and an instance of Stopwatcher to track time limit. Optionally, user can set ResultPrinter to a custom function to output useful statistics about test case's result.
func NewTestingBatch ¶
func NewTestingBatch(inputs Inputs, proc Processer, swatch Stopwatcher, pool WorkerPool) *TestingBatch
NewTestingBatch will initialize channels and maps inside TestingBatch and will assign respective dependency injections.
func (*TestingBatch) Run ¶
func (b *TestingBatch) Run()
Run will lauch test cases in parallel and then will wait for each test to finish or for the time to timelimit. When a test is finished the verdict and the time it took to execute are remembered. Additionally, ResultPrinter is called on the test case's statistics. When a time limit is reached, each not-yet-judged test is assigned TL verdict and the ResultPrinter is also called on each test.
type TestingEventListener ¶
type TestingEventListener interface { // TestStarted will be called upon test case lounch. TestStarted(id int) // TestFinished is called when a test case finishes execution. Usually, // one would like to print the test case result information. // // It accepts a pointer to the contents of the Test and a pointer to the // test case result that contains id of the test, its verdict, time, and // other useful information related to the executable's execution. TestFinished(*Test, *TestResult) // SuiteFinished is called when all test cases have finished. // Accessing testingBatch at this point is safe, and no events will // be sent to TestingEventListener after this event. SuiteFinished(*TestingBatch) }
TestingEventListener provides a way for users of scold to subscribe to the events produced by TestingBatch and to operate in a reactive fashion. The functions will stall the TestingBatch event loop, and thus could be not thread-safe.
type ThreadPool ¶
type ThreadPool struct {
// contains filtered or unexported fields
}
ThreadPool is a generic implementation of WorkerPool.
func NewThreadPool ¶
func NewThreadPool(count int) *ThreadPool
NewThreadPool creates a thread pool with a definite limit to the number of concurrent operations permitted.
func (*ThreadPool) Execute ¶
func (p *ThreadPool) Execute(task Runnable) error
Execute tries to find a free worker and assign task to it. If no worker is available, returns ErrNoWorkerAvailable.
func (*ThreadPool) WorkerCount ¶
func (p *ThreadPool) WorkerCount() int
WorkerCount returns the number of threads in a pool. These threads may may not have a task assigned to them.
type WorkerPool ¶
WorkerPool abstracts the notion of a thread pool. It allows for interoperation with different thread pool libraries.