Documentation
¶
Overview ¶
Package test provides some utilities for construct test files. * Debugf provides a simplistic logging for use in test cases. * Case defines test cases stored in JSON files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DebugLevel ¶
func DebugLevel() uint
DebugLevel returns the level set by the -debug flag or 0 for default.
func Debugf ¶
Debugf will only print the specified data if the -debug command flag is set. The level field determines whether the statement will be printed. The -debug flag must be greater than or equal to the specified level for printing.
func Files ¶
Files returns a list of file names found in the 'test' subdirectory of the specified directory. If the directory is not provided (the string is empty) then 'testdata' is used.
func Load ¶
Load reads a test case JSON file and unmarshals it into the provided Case instantiation. The pathname is constructed from the named file in the 'test' subdirectory of the specified directory:
<dir>/test/<file>
If the directory is not provided (the string is empty) then 'testdata' is used.
Types ¶
type BasicCase ¶
type BasicCase struct { BasicName string `json:"Description"` BasicSource string `json:"Source"` // contains filtered or unexported fields }
BasicCase provides the common test definition items and methods. Compose the specific test case struct with this struct to inherit. Normally the BasicName and BasicSource fields would be private, but they can't be because of the JSON unmarshaler. Do not reference them externally.
func (*BasicCase) Source ¶
Source returns the test case source string. If the Source field was empty the data will be loaded from The pathname constructed from the named file in the 'json' subdirectory of the specified directory:
<dir>/json/<file>
where the dir was specified in the preceding Load call and saved to the basic test case struct.
type Case ¶
type Case interface { Name() string Source(t *testing.T) string // contains filtered or unexported methods }
Case defines an interface for test case definitions. The interface provides functions to access common data items. Cases are read from JSON files in 'test' subdirectory of the specified test directory. The JSON files must contain the following common fields:
Description test name Source test source string
If the Source field is empty the test file name is used to read the source data from a JSON file in the 'json' subdirectory of the specified test directory.
type CountWriter ¶
type CountWriter struct {
// contains filtered or unexported fields
}
CountWriter is an io.Writer that throws away all input but counts `Write` calls and the number of bytes that would have been written. This is used during benchmarking.
func (*CountWriter) Bytes ¶
func (cw *CountWriter) Bytes() uint64
Bytes returns the number of bytes that the `CountWriter` ignored.
func (*CountWriter) Write ¶
func (cw *CountWriter) Write(p []byte) (n int, err error)
Write supplies the required io.Writer interface method.
func (*CountWriter) Written ¶
func (cw *CountWriter) Written() uint64
Written returns the number of `Write` calls that the `CountWriter` ignored.