Documentation ¶
Index ¶
- Constants
- func AssertCallCount(t *testing.T, got, want int)
- func AssertConfig(t *testing.T, got, want map[string]string)
- func AssertErrorLines(t *testing.T, errs []error, lines []int)
- func AssertErrors(t *testing.T, got, want []error)
- func AssertNoConfig(t *testing.T, got map[string]string)
- func AssertNoErrors(t *testing.T, errs []error)
- func AssertTest(t *testing.T, got Test, want Test)
- func AssertTests(t *testing.T, got []Test, want []Test)
- func AssertTimes(t *testing.T, got, want map[int]time.Duration)
- func AssertVerdicts(t *testing.T, got, want map[int]Verdict)
- func BlankResultPrinter(b *TestingBatch, test Test, id int)
- func ScanConfig(text string) (m map[string]string, errs []error)
- func ScanKeyValuePair(line string) (string, string, error)
- func VerboseResultPrinter(b *TestingBatch, test Test, id int)
- type ConfigurableStopwatcher
- type Executable
- type Inputs
- type InputsError
- type InternalError
- type LinedError
- type PrintResultFunc
- type Processer
- type ProcesserFunc
- type SpyProcesser
- type SpyStopwatcher
- type Stopwatcher
- type Test
- type TestingBatch
- type Verdict
Constants ¶
const ( IOSeparatorMissing = InputsError("IO separator missing") KeyMissing = InputsError("key cannot be empty") ValueMissing = InputsError("value cannot be empty") KVMissing = InputsError("key and value are missing") NotKVPair = InputsError("not a key-value pair") )
A set of errors that may be produced during scanning of the inputs file. These replace sentinel errors making the errors be comparable with equals operator.
const ( IODelim = "---" TestDelim = "===" )
The set of delimeters used when partitioning inputs file.
Variables ¶
This section is empty.
Functions ¶
func AssertCallCount ¶
AssertCallCount checks that the received and expected number of calls are equal.
func AssertConfig ¶
AssertConfig checks whether received and expected config key-value sets are equal.
func AssertErrorLines ¶
AssertErrorLines checks that each error in the received array of errors is wrapping a LinedError error. At the same time, it checks that the line numbers are equal to the expected ones.
func AssertErrors ¶
AssertErrors compared received array of errors with the expected one.
func AssertNoConfig ¶
AssertNoConfig checks that the received key-value set is empty. If it's not, the test is failed and the its contents are printed.
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 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 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 BlankResultPrinter ¶
func BlankResultPrinter(b *TestingBatch, test Test, id int)
BlankResultPrinter is the standard PrintResultFunc that outputs nothing.
func ScanConfig ¶
ScanConfig tries to parse a stream of key-value pairs. It expects each pair to be located on a dedicated line. Duplicate keys are allowed, the later version is preferred.
func ScanKeyValuePair ¶
ScanKeyValuePair parses the key-value pair definition of form key=value. It returns error if no equality signs are present, or if any side is empty. The space around key and value is trimmed.
func VerboseResultPrinter ¶
func VerboseResultPrinter(b *TestingBatch, test Test, id int)
Types ¶
type ConfigurableStopwatcher ¶
type ConfigurableStopwatcher struct {
// contains filtered or unexported fields
}
ConfigurableStopwatcher is an implementation of the Stopwatcher that uses real time.
func NewConfigurableStopwatcher ¶
func NewConfigurableStopwatcher(TL time.Duration) *ConfigurableStopwatcher
NewConfigurableStopwatcher will return an initialized ConfigurableStopwatcher with the desired time limit. If time limit specified is zero or negative, the time limit will never fire.
func (*ConfigurableStopwatcher) Elapsed ¶
func (s *ConfigurableStopwatcher) Elapsed() time.Duration
Elapsed returns the true number of seconds since the initialization of the ConfigurableStopwatcher.
func (*ConfigurableStopwatcher) TimeLimit ¶
func (s *ConfigurableStopwatcher) TimeLimit() <-chan time.Duration
TimeLimit returns a channel that will send back the number of seconds passed since beginning until the time limit was fired. The returned value may not equal to the time limit ConfigurableStopwatcher was initialized with.
type Executable ¶
type Executable struct {
Path string
}
type Inputs ¶
Inputs contains all information located in the inputs file. It contains all of the tests listed there and the set of key-value pairs, if were provided.
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. If the true first test could not be parsed without errors, it is interpreted as a configuration and parsed again. The empty tests are skipped (those that don't contain input, output and the separator). If test case could not be parsed, parsing continues to the next test case, but the errors are accumulated and returned together.
type InputsError ¶
type InputsError string
InputsError represents an error produced while scanning inputs file.
func (InputsError) Error ¶
func (e InputsError) Error() string
type InternalError ¶
type InternalError bool
InternalError represents an error that occured due to internal failure in TestingBatch.
func (InternalError) Error ¶
func (e InternalError) Error() string
type LinedError ¶
LinedError appends line information to the error message. It is mainly used to test that errors are produced for correct lines.
func (*LinedError) Error ¶
func (e *LinedError) Error() string
func (*LinedError) Unwrap ¶
func (e *LinedError) Unwrap() error
type PrintResultFunc ¶
type PrintResultFunc func(*TestingBatch, Test, int)
PrintResultFunc is type representing a function to print statistics and information about the finished test case.
type ProcesserFunc ¶
ProcesserFunc represents an implementation of Processer that instead of a real OS-level process executes Go code.
type SpyProcesser ¶
SpyProcesser is a test double that proxies another processer. It additionally stores the number of calls made to the Run function.
type SpyStopwatcher ¶
type SpyStopwatcher struct { TLAtCall int // contains filtered or unexported fields }
SpyStopwatcher implements Stopwatcher but instead of real time substitutes index sequence numbers. If time limit equals zero, then the time limit will never fire.
func (*SpyStopwatcher) Elapsed ¶
func (s *SpyStopwatcher) Elapsed() time.Duration
Elapsed will return the number of seconds that equals to the number of calls made to the TimeLimit method.
func (*SpyStopwatcher) TimeLimit ¶
func (s *SpyStopwatcher) TimeLimit() <-chan time.Duration
TimeLimit returns a channel that sends the TLAtCall number of seconds back at the TLAtCall-th call to the TimeLimit method.
type Stopwatcher ¶
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 TestingBatch ¶
type TestingBatch struct { Stat map[int]Verdict Times map[int]time.Duration Proc Processer Swatch Stopwatcher ResultPrinter PrintResultFunc // 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 utilizer 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) *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.