formatters

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package formatters provides output formatting functionality for MindTrial results. It supports multiple output formats including HTML, CSV, and text logs.

Index

Constants

View Source
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

View Source
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

func DiffHTML(expected string, actual string) string

DiffHTML computes an HTML representation of differences between the two given strings.

func DiffText

func DiffText(expected string, actual string) string

DiffText computes a plain-text representation of differences between the two given strings.

func ForEachOrdered

func ForEachOrdered[K cmp.Ordered, V any](m map[K]V, fn func(key K, value V) error) error

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

func FormatAnswer(result runners.RunResult, useHTML bool) (answers []string)

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

func GroupParagraphs(lines []string) [][]string

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 RoundToMS

func RoundToMS(value time.Duration) time.Duration

RoundToMS rounds a duration to the nearest millisecond.

func Timestamp

func Timestamp() string

Timestamp returns the current time in RFC1123Z format.

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

func UniqueRuns(results runners.Results) []string

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.

Jump to

Keyboard shortcuts

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