bzltestutil

package
v0.47.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const TestWrapperAbnormalExit = 6

TestWrapperAbnormalExit is used by Wrap to indicate the child process exitted without an exit code (for example being killed by a signal). We use 6, in line with Bazel's RUN_FAILURE.

Variables

This section is empty.

Functions

func ConvertCoverToLcov added in v0.32.0

func ConvertCoverToLcov() error

ConvertCoverToLcov converts the go coverprofile file coverage.dat.cover to the expectedLcov format and stores it in coverage.dat, where it is picked up by Bazel. The conversion emits line and branch coverage, but not function coverage.

func NewStreamMerger added in v0.36.0

func NewStreamMerger(w io.Writer) *streamMerger

func ShouldWrap

func ShouldWrap() bool

func Wrap

func Wrap(pkg string) error

Types

type Converter added in v0.28.0

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

A Converter holds the state of a test-to-JSON conversion. It implements io.WriteCloser; the caller writes test output in, and the converter writes JSON output to w.

func NewConverter

func NewConverter(w io.Writer, pkg string, mode Mode) *Converter

NewConverter returns a "test to json" converter. Writes on the returned writer are written as JSON to w, with minimal delay.

The writes to w are whole JSON events ending in \n, so that it is safe to run multiple tests writing to multiple converters writing to a single underlying output stream w. As long as the underlying output w can handle concurrent writes from multiple goroutines, the result will be a JSON stream describing the relative ordering of execution in all the concurrent tests.

The mode flag adjusts the behavior of the converter. Passing ModeTime includes event timestamps and elapsed times.

The pkg string, if present, specifies the import path to report in the JSON stream.

func (*Converter) Close added in v0.28.0

func (c *Converter) Close() error

Close marks the end of the go test output. It flushes any pending input and then output (only partial lines at this point) and then emits the final overall package-level pass/fail event.

func (*Converter) Exited added in v0.28.0

func (c *Converter) Exited(err error)

Exited marks the test process as having exited with the given error.

func (*Converter) Write added in v0.28.0

func (c *Converter) Write(b []byte) (int, error)

Write writes the test input to the converter.

type LcovTestDeps added in v0.32.0

type LcovTestDeps struct {
	testdeps.TestDeps
	OriginalPanicOnExit bool
}

LcovTestDeps is a patched version of testdeps.TestDeps that allows to hook into the SetPanicOnExit0 call happening right before testing.M.Run returns. This trick relies on the testDeps interface defined in this package being identical to the actual testing.testDeps interface, which differs between major versions of Go.

func (LcovTestDeps) SetPanicOnExit0 added in v0.32.0

func (ltd LcovTestDeps) SetPanicOnExit0(panicOnExit bool)

SetPanicOnExit0 is called with true by m.Run() before running all tests, and with false right before returning -- after writing all coverage profiles. https://cs.opensource.google/go/go/+/refs/tags/go1.18.1:src/testing/testing.go;l=1921-1931;drc=refs%2Ftags%2Fgo1.18.1

This gives us a good place to intercept the os.Exit(m.Run()) with coverage data already available.

type Mode

type Mode int

Mode controls details of the conversion.

const (
	Timestamp Mode = 1 << iota // include Time in events
)

Directories

Path Synopsis
Package chdir provides an init function that changes the current working directory to RunDir when the test executable is started by Bazel (when TEST_SRCDIR and TEST_WORKSPACE are set).
Package chdir provides an init function that changes the current working directory to RunDir when the test executable is started by Bazel (when TEST_SRCDIR and TEST_WORKSPACE are set).

Jump to

Keyboard shortcuts

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