runner

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package testdeps provides access to dependencies needed by test execution.

This package is imported by the generated main package, which passes TestDeps into testing.Main. This allows tests to use packages at run time without making those packages direct dependencies of package testing. Direct dependencies of package testing are harder to write tests for.

Package testlog provides a back-channel communication path between tests and package os, so that cmd/go can see which environment variables and files a test consults.

Index

Constants

This section is empty.

Variables

View Source
var EnableMatchWorkaround = true
View Source
var ImportPath string

ImportPath is the import path of the testing binary, set by the generated main function.

View Source
var RealStdout *os.File

RealStdout will point to the real stdout

Functions

func Getenv

func Getenv(name string)

Getenv calls Logger().Getenv, if a logger has been set.

func Initialized

func Initialized() bool

Initialized returns true if the instance is initialized.

func MatchTag

func MatchTag(name string) (ok bool, matched bool, actualName string)

MatchTag returns ok = true if the name has a test tag. If the tag is present, then "match" will indicate if the test name matched the tagged pattern. If there is a test tag, the returned name will be the actual test name minus the tag.

If there is no tag the function returns the same given name and ok = false, matched = false.

This should only be used as a workaround until we implement a real test runner.

func NewEventWriter

func NewEventWriter(runner Runner) *eventWriter

func Open

func Open(name string)

Open calls Logger().Open, if a logger has been set.

func PanicOnExit0

func PanicOnExit0() bool

PanicOnExit0 reports whether to panic on a call to os.Exit(0). This is in the testlog package because, like other definitions in package testlog, it is a hook between the testing package and the os package. This is used to ensure that an early call to os.Exit(0) does not cause a test to pass.

func SetLogger

func SetLogger(impl Interface)

SetLogger sets the test logger implementation for the current process. It must be called only once, at process startup.

func SetPanicOnExit0

func SetPanicOnExit0(v bool)

SetPanicOnExit0 sets panicOnExit0 to v.

func Stat

func Stat(name string)

Stat calls Logger().Stat, if a logger has been set.

Types

type EventLogger

type EventLogger interface {
	Log(message string)
}

EventLogger will log test events

type Interface

type Interface interface {
	Getenv(key string)
	Stat(file string)
	Open(file string)
	Chdir(dir string)
}

Interface is the interface required of test loggers. The os package will invoke the interface's methods to indicate that it is inspecting the given environment variables or files. Multiple goroutines may call these methods simultaneously.

func Logger

func Logger() Interface

Logger returns the current test logger implementation. It returns nil if there is no logger.

type Runner

type Runner interface {
	Run()
	AddStatistics(stats *constants.Statistics)
	Statistics() []constants.Statistics
	ClearStatistics()
	Match(pattern string) error
	PrintToStdout(yes bool)
	PrintOutputToEventLog(yes bool)
	SetEventLogger(e EventLogger)
	LogEvent(message string)
	ReportStatistics()
	Passed() bool
	Output() string
}

Interface for the custom test runner (contains Golang's Run() and some other custom methods that we need for recording statistics, etc.)

func Instance

func Instance(m TestRunner) Runner

GetInstance returns the runner instance. Only the first invocation of this method will set the "m". This should not matter because the testing framework currently does not let us safely create our own "m" so only one instance should always exist.

Internally the testdeck package will invoke this method with 'nil' in order to access the runner.

type TestDeps

type TestDeps struct{}

TestDeps is an implementation of the testing.testDeps interface, suitable for passing to testing.MainStart.

func (TestDeps) CheckCorpus added in v1.0.1

func (TestDeps) CheckCorpus(vals []any, types []reflect.Type) error

func (TestDeps) CoordinateFuzzing added in v1.0.1

func (TestDeps) CoordinateFuzzing(time.Duration, int64, time.Duration, int64, int, []corpusEntry, []reflect.Type, string, string) error

func (TestDeps) ImportPath

func (TestDeps) ImportPath() string

func (TestDeps) MatchString

func (TestDeps) MatchString(pat, str string) (result bool, err error)

func (TestDeps) ReadCorpus added in v1.0.1

func (TestDeps) ReadCorpus(dir string, types []reflect.Type) ([]corpusEntry, error)

func (TestDeps) ResetCoverage added in v1.0.1

func (TestDeps) ResetCoverage()

func (TestDeps) RunFuzzWorker added in v1.0.1

func (TestDeps) RunFuzzWorker(func(corpusEntry) error) error

func (TestDeps) SetPanicOnExit0

func (TestDeps) SetPanicOnExit0(v bool)

SetPanicOnExit0 tells the os package whether to panic on os.Exit(0).

func (TestDeps) SnapshotCoverage added in v1.0.1

func (TestDeps) SnapshotCoverage()

func (TestDeps) StartCPUProfile

func (TestDeps) StartCPUProfile(w io.Writer) error

func (TestDeps) StartTestLog

func (TestDeps) StartTestLog(w io.Writer)

func (TestDeps) StopCPUProfile

func (TestDeps) StopCPUProfile()

func (TestDeps) StopTestLog

func (TestDeps) StopTestLog() error

func (TestDeps) WriteProfileTo

func (TestDeps) WriteProfileTo(name string, w io.Writer, debug int) error

type TestRunner

type TestRunner interface {
	Run() int
}

This is a custom version of Golang testing's type M (a test runner struct)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL