Documentation
¶
Overview ¶
Package formatters provides output formatting functionality for MindTrial results. It supports multiple output formats including HTML, CSV, JSON, and text logs. The JSON format implements the Codec interface, enabling bidirectional serialization for result persistence and merging across separate runs.
Index ¶
- Constants
- Variables
- func AccuracyRate(resultsByKind map[runners.ResultKind][]runners.RunResult) float64
- func CountByKind(resultsByKind map[runners.ResultKind][]runners.RunResult, ...) int
- func DiffHTML(expected string, actual string) string
- func DiffText(expected string, actual string) string
- func ErrorRate(resultsByKind map[runners.ResultKind][]runners.RunResult) float64
- func ForEachOrdered[K cmp.Ordered, V any](m map[K]V, fn func(key K, value V) error) error
- func FormatAnswer(result runners.RunResult, useHTML bool) (answers []string)
- func GroupParagraphs(lines []string) [][]string
- func PassRate(resultsByKind map[runners.ResultKind][]runners.RunResult) float64
- func Percent(rate float64) float64
- func ReadResultsFromFile(path string) (runners.Results, error)
- func RoundToMS(value time.Duration) time.Duration
- func Timestamp() string
- func ToStatus(kind runners.ResultKind) string
- func TotalDuration(resultsByKind map[runners.ResultKind][]runners.RunResult, ...) (total time.Duration)
- func UniqueRuns(results runners.Results) []string
- type Codec
- type Formatter
- type VersionData
Constants ¶
const ( // Unknown represents an unknown status. Unknown = "Unknown" // Passed indicates that the task finished successfully with a correct result. Passed = "Passed" // Failed indicates that the task finished successfully but with an incorrect result. Failed = "Failed" // Error indicates that the task failed to produce a result. Error = "Error" // Skipped indicates that the task was skipped by the provider. Skipped = "Skipped" )
Variables ¶
var ( // ErrPrintResults indicates that result formatting failed. ErrPrintResults = errors.New("failed to print formatted results") // ErrReadResults indicates that result reading failed. ErrReadResults = errors.New("failed to read results") // ErrUnsupportedInputFormat indicates an unsupported file format. ErrUnsupportedInputFormat = errors.New("unsupported input format") )
Functions ¶
func AccuracyRate ¶ added in v0.13.3
func AccuracyRate(resultsByKind map[runners.ResultKind][]runners.RunResult) float64
AccuracyRate returns the fraction of correct results (passed) among completed tasks (passed or failed). Errors and skipped tasks are excluded.
func CountByKind ¶
func CountByKind(resultsByKind map[runners.ResultKind][]runners.RunResult, kind runners.ResultKind) int
CountByKind returns the number of run results of a given kind.
func DiffHTML ¶
DiffHTML computes an HTML representation of differences between the two given strings.
func DiffText ¶
DiffText computes a plain-text representation of differences between the two given strings.
func ErrorRate ¶ added in v0.13.3
func ErrorRate(resultsByKind map[runners.ResultKind][]runners.RunResult) float64
ErrorRate returns the fraction of tasks that errored among attempted tasks (passed, failed, error). Skipped tasks are excluded.
func ForEachOrdered ¶
ForEachOrdered iterates over map elements in key order. For each key-value pair, it calls fn. If fn returns an error, iteration stops and returns that error.
func FormatAnswer ¶
FormatAnswer formats the result of a runner based on its kind and the specified output format. For failures, it generates a diff between expected and actual outputs. The useHTML parameter controls whether diffs are formatted as HTML or plain text.
func GroupParagraphs ¶ added in v0.6.0
GroupParagraphs splits a slice of lines into paragraphs separated by blank lines. Consecutive non-empty lines are grouped; empty/whitespace-only lines act as paragraph breaks.
func PassRate ¶ added in v0.13.3
func PassRate(resultsByKind map[runners.ResultKind][]runners.RunResult) float64
PassRate returns the fraction of tasks that passed out of all attempted tasks (passed, failed, error). Skipped tasks are excluded.
func Percent ¶ added in v0.13.3
Percent converts a fraction (0..1) to a percentage (0..100) rounded to 2 decimals.
func ReadResultsFromFile ¶ added in v0.19.0
ReadResultsFromFile reads results from a file, selecting the appropriate codec based on file extension.
func ToStatus ¶
func ToStatus(kind runners.ResultKind) string
ToStatus converts a runners.ResultKind value to its corresponding human-readable status string. Returns "Unknown" for unrecognized result kinds.
func TotalDuration ¶
func TotalDuration(resultsByKind map[runners.ResultKind][]runners.RunResult, include ...runners.ResultKind) (total time.Duration)
TotalDuration computes the total duration of the runs of given kinds.
func UniqueRuns ¶ added in v0.6.0
UniqueRuns returns a sorted slice of unique run names from the results.
Types ¶
type Codec ¶ added in v0.19.0
type Codec interface {
Formatter
// Read parses results from the reader.
Read(in io.Reader) (runners.Results, error)
}
Codec extends the Formatter interface with the ability to read results back.
func NewJSONCodec ¶ added in v0.19.0
func NewJSONCodec() Codec
NewJSONCodec creates a new codec that reads and writes results in JSON format.
type Formatter ¶
type Formatter interface {
// FileExt returns the formatter's file extension.
FileExt() string
// Write outputs formatted results to the writer.
Write(results runners.Results, out io.Writer) error
}
Formatter handles converting results into specific output formats.
func NewCSVFormatter ¶
func NewCSVFormatter() Formatter
NewCSVFormatter creates a new formatter that outputs results in CSV format.
func NewHTMLFormatter ¶
func NewHTMLFormatter() Formatter
NewHTMLFormatter creates a new formatter that outputs results as an HTML document.
func NewLogFormatter ¶
func NewLogFormatter() Formatter
NewLogFormatter creates a new formatter that outputs detailed results as an ASCII table.
func NewSummaryLogFormatter ¶
func NewSummaryLogFormatter() Formatter
NewSummaryLogFormatter creates a new formatter that outputs results as an ASCII table summary.
type VersionData ¶
type VersionData struct {
// Name is the application name.
Name string
// Version is the application version string.
Version string
// Source is the application source code URL.
Source string
}
VersionData contains version information included in formatted output.