gotest

package
v2.0.0-...-e9c7f1d Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package gotest is a standard Go test output parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetBenchmarkData

func SetBenchmarkData(t *gtr.Test, b Benchmark)

SetBenchmarkData is a helper function that writes the benchmark b to the data field of the given gtr.Test t.

Types

type Benchmark

type Benchmark struct {
	Iterations  int64
	NsPerOp     float64
	MBPerSec    float64
	BytesPerOp  int64
	AllocsPerOp int64
}

Benchmark contains benchmark results and is intended to be used as extra data in a gtr.Test.

func GetBenchmarkData

func GetBenchmarkData(t gtr.Test) (b Benchmark, ok bool)

GetBenchmarkData is a helper function that returns the benchmark contained in the data field of the given gtr.Test t. If no (valid) benchmark is present, ok will be set to false.

func (Benchmark) ApproximateDuration

func (b Benchmark) ApproximateDuration() time.Duration

ApproximateDuration returns the duration calculated by multiplying the iterations and average time per iteration (NsPerOp).

type Event

type Event struct {
	Type string `json:"type"`

	Name     string        `json:"name,omitempty"`
	Package  string        `json:"pkg,omitempty"`
	Result   string        `json:"result,omitempty"`
	Duration time.Duration `json:"duration,omitempty"`
	Data     string        `json:"data,omitempty"`
	Indent   int           `json:"indent,omitempty"`

	// Code coverage
	CovPct      float64  `json:"coverage_percentage,omitempty"`
	CovPackages []string `json:"coverage_packages,omitempty"`

	// Benchmarks
	Iterations  int64   `json:"benchmark_iterations,omitempty"`
	NsPerOp     float64 `json:"benchmark_ns_per_op,omitempty"`
	MBPerSec    float64 `json:"benchmark_mb_per_sec,omitempty"`
	BytesPerOp  int64   `json:"benchmark_bytes_per_op,omitempty"`
	AllocsPerOp int64   `json:"benchmark_allocs_per_op,omitempty"`
}

Event is a single event in a Go test or benchmark.

type JSONParser

type JSONParser struct {
	// contains filtered or unexported fields
}

JSONParser is a `go test -json` output Parser.

func NewJSONParser

func NewJSONParser(options ...Option) *JSONParser

NewJSONParser returns a new Go test json output parser.

func (*JSONParser) Events

func (p *JSONParser) Events() []Event

Events returns the events created by the parser.

func (*JSONParser) Parse

func (p *JSONParser) Parse(r io.Reader) (gtr.Report, error)

Parse parses Go test json output from the given io.Reader r and returns gtr.Report.

type Option

type Option func(*Parser)

Option defines options that can be passed to gotest.New.

func PackageName

func PackageName(name string) Option

PackageName is an Option that sets the default package name to use when it cannot be determined from the test output.

func SetSubtestMode

func SetSubtestMode(mode SubtestMode) Option

SetSubtestMode is an Option to change how the parser handles tests with subtests. See the documentation for the individual SubtestModes for more information.

func TimestampFunc

func TimestampFunc(f func() time.Time) Option

TimestampFunc is an Option that sets the timestamp function that is used to determine the current time when creating the Report. This can be used to override the default behaviour of using time.Now().

func WithEventHandler

func WithEventHandler(handleFunc func(e Event) error) Option

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser is a Go test output Parser.

func NewParser

func NewParser(options ...Option) *Parser

NewParser returns a new Go test output parser.

func (*Parser) Events

func (p *Parser) Events() []Event

Events returns the events created by the parser.

func (*Parser) Parse

func (p *Parser) Parse(r io.Reader) (gtr.Report, error)

Parse parses Go test output from the given io.Reader r and returns gtr.Report.

type SubtestMode

type SubtestMode string

SubtestMode configures how Go subtests should be handled by the parser.

const (
	// SubtestModeDefault is the default subtest mode. It treats tests with
	// subtests as any other tests.
	SubtestModeDefault SubtestMode = ""

	// IgnoreParentResults ignores test results for tests with subtests. Use
	// this mode if you use subtest parents for common setup/teardown, but are
	// not interested in counting them as failed tests. Ignoring their results
	// still preserves these tests and their captured output in the report.
	IgnoreParentResults SubtestMode = "ignore-parent-results"

	// ExcludeParents excludes tests that contain subtests from the report.
	// Note that the subtests themselves are not removed. Use this mode if you
	// use subtest parents for common setup/teardown, but are not actually
	// interested in their presence in the created report. If output was
	// captured for tests that are removed, the output is preserved in the
	// global report output.
	ExcludeParents SubtestMode = "exclude-parents"
)

func ParseSubtestMode

func ParseSubtestMode(in string) (SubtestMode, error)

ParseSubtestMode returns a SubtestMode for the given string.

Directories

Path Synopsis
internal
collector
Package collector collects output lines grouped by id and provides ways to retrieve and merge output ordered by the time each line was added.
Package collector collects output lines grouped by id and provides ways to retrieve and merge output ordered by the time each line was added.

Jump to

Keyboard shortcuts

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