Documentation
¶
Overview ¶
Package formatters provides output formatting functionality for MindTrial results. It supports multiple output formats including HTML, CSV, and text logs.
Index ¶
- Constants
- Variables
- func CountByKind(resultsByKind map[runners.ResultKind][]runners.RunResult, ...) int
- func DiffHTML(expected string, actual string) string
- func DiffText(expected string, actual string) string
- 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 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 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 = errors.New("failed to print formatted results")
ErrPrintResults indicates that result formatting failed.
Functions ¶
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 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 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 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.