package test2json
import "cmd/internal/test2json"
Package test2json implements conversion of test binary output to JSON. It is used by cmd/test2json and cmd/go.
See the cmd/test2json documentation for details of the JSON encoding.
Index ¶
- type Converter
- func NewConverter(w io.Writer, pkg string, mode Mode) *Converter
- func (c *Converter) Close() error
- func (c *Converter) Exited(err error)
- func (c *Converter) SetFailedBuild(pkgID string)
- func (c *Converter) Write(b []byte) (int, error)
- type Mode
Types ¶
type Converter ¶
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 ¶
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 ¶
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 ¶
Exited marks the test process as having exited with the given error.
func (*Converter) SetFailedBuild ¶
SetFailedBuild sets the package ID that is the root cause of a build failure for this test. This will be reported in the final "fail" event's FailedBuild field.
func (*Converter) Write ¶
Write writes the test input to the converter.
type Mode ¶
type Mode int
Mode controls details of the conversion.
Source Files ¶
- Version
- v1.24.0 (latest)
- Published
- Feb 10, 2025
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 5 minutes ago –
Tools for package owners.