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 ToErrorCategory(details runners.ErrorDetails) string
- func ToJSONStringArray(values []string) string
- func ToStatus(kind runners.ResultKind) string
- func TotalDuration(resultsByKind map[runners.ResultKind][]runners.RunResult, ...) (total time.Duration)
- func UniqueCategories(results runners.Results) []string
- func UniqueDifficulties(results runners.Results) []string
- func UniqueRuns(results runners.Results) []string
- func UniqueSuites(results runners.Results) []string
- func UniqueTags(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" // Transient identifies an error category: the error appears temporary/external and a // retry may succeed. See ToErrorCategory. Transient = "Transient" // Permanent identifies an error category: the error appears permanent and a retry is // unlikely to succeed. See ToErrorCategory. Permanent = "Permanent" )
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 ToErrorCategory ¶ added in v0.20.0
func ToErrorCategory(details runners.ErrorDetails) string
ToErrorCategory returns a short, human-readable error category label for the given error details: Permanent when Transient is false, Transient when true, and "" (no category) when transience is unknown (nil). Takes the whole ErrorDetails, rather than just its Transient field, so future categorization can draw on other attributes (e.g. Title) without changing the function's signature again. Modeled as a small, named set of constants (like ToStatus) so additional error categories can be introduced later without changing callers' string literals.
func ToJSONStringArray ¶ added in v0.20.0
ToJSONStringArray renders values as a JSON array string, defaulting to "[]" for a nil or empty slice, or if marshaling fails. Used to safely embed free-form strings (e.g. a task's tags, which may themselves contain any character, including a comma or space) into contexts - such as an HTML attribute - where a plain delimiter-joined string could collide with the content itself.
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 UniqueCategories ¶ added in v0.20.0
UniqueCategories returns a sorted slice of unique, non-empty task category labels from the results.
func UniqueDifficulties ¶ added in v0.20.0
UniqueDifficulties returns a sorted slice of unique, non-empty task difficulty labels from the results.
func UniqueRuns ¶ added in v0.6.0
UniqueRuns returns a sorted slice of unique run names from the results.
func UniqueSuites ¶ added in v0.20.0
UniqueSuites returns a sorted slice of unique, non-empty task suite labels from the results.
func UniqueTags ¶ added in v0.20.0
UniqueTags returns a sorted slice of unique, non-empty task tags from the results. A task's Tags is a slice, so all tags across all results are flattened before deduplication.
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.