Help us shape the future of Go! Take the 2026 Go Developer Survey

testsuite

package
v3.24.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package testsuite runs the test cases a configuration keeps beside its rules.

A rule is a small program, and nobody maintains a significant Vale configuration without some way to ask "does this still fire where I think it does?". The cases are YAML, they live next to what they test, and they are run by `vale test`. See #1122.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Find

func Find(paths []string) ([]string, error)

Find resolves what to run.

A file is taken as given, a directory is searched, and no argument at all searches the working directory -- which finds a style's cases wherever the StylesPath happens to be.

func Uncovered added in v3.23.0

func Uncovered(rules []string, results []Result) []string

Uncovered returns the rules that produced no alert in any result.

Types

type Case

type Case struct {
	// Name identifies the case in the report. It is required, and unique
	// within its file.
	Name string `yaml:"name"`

	// About is a note for the reader -- an issue number, or what the case is
	// really pinning down. Never asserted on.
	About string `yaml:"about"`

	// Input is the document to lint.
	Input string `yaml:"input"`

	// Format is the extension Input is read as, with or without the dot.
	// Defaults to `md`.
	Format string `yaml:"format"`

	// View names a View, found under a search path's `config/views`, to
	// read Input through. An isolated case loads nothing from the project's
	// configuration, and that includes the View that gives a rule its scope:
	// a rule scoped to `subject` sees no subject without one. With it, the
	// case runs the way the project's section would run it, and the cases
	// of a View's rules can live beside them.
	View string `yaml:"view"`

	// Rule isolates the case to a single rule, named by a path relative to the
	// test file. Nothing else is loaded -- not the rest of the style, not the
	// project's configuration -- so the case says exactly what the rule does
	// and nothing about what a run would surface.
	//
	// Without it, the case is linted by the configuration a `vale` run in this
	// directory would use, which is what tells you whether the rule reaches
	// real documents at all.
	Rule string `yaml:"rule"`

	// Want is the exact output expected, Contains excerpts of it, and Absent
	// what must not appear. Want is a pointer so that an empty block asserts
	// "no alerts at all" rather than going unset.
	Want     *string `yaml:"want"`
	Contains Strings `yaml:"contains"`
	Absent   Strings `yaml:"absent"`

	// Path is the file this case was read from.
	Path string `yaml:"-"`
}

A Case is one document and what linting it must produce.

func Load

func Load(path string) ([]Case, error)

Load reads the cases in one file.

A `.test.yml` holds a sequence of cases and is validated strictly -- it exists for no other reason. Any other YAML file is considered only if it is a rule carrying its own cases: a mapping with `extends` and a `tests` sequence. Everything else -- workflows, configs, data files -- is silently not ours, so `vale test` can walk a whole repository without tripping on YAML it has no business reading.

func (Case) Ext

func (c Case) Ext() string

Ext is the extension Input is linted as, dot included.

type Line

type Line struct {
	Op   Op
	Text string
}

A Line is one line of a diff.

func Diff

func Diff(want, got string) []Line

Diff compares want against got, line by line.

A failing case is nearly always a line that moved by a column or a message that was reworded, and neither reads as two blocks of text quoted one after the other. Callers render the result: what color a `-` is, and how far it is indented, is a question about where it is being printed.

type Op

type Op byte

An Op is what a diff line did.

const (
	// Same is a line both sides have.
	Same Op = ' '
	// Del is a line only the expected output has.
	Del Op = '-'
	// Add is a line only the actual output has.
	Add Op = '+'
)

type Result

type Result struct {
	Case Case

	// Got is the alert output, one `line:col:check:message` per line. There is
	// no path: the document was a string.
	Got string

	// Reason says what went wrong, and is empty when the case passed. Err is
	// set instead when the case could not be run at all -- a rule that does
	// not compile is not a failing assertion.
	Reason string
	Err    error
}

A Result is what running one Case produced.

func (Result) Failed

func (r Result) Failed() bool

Failed reports whether the case did not pass, for either reason.

type Runner

type Runner struct {

	// Install puts packages into a StylesPath the way `vale sync` does. With
	// it, a package's own `Packages` are installed for its isolated cases, so
	// a rule that extends Std resolves without a synced project.
	Install func(pkgs []string, styles string) error
	// contains filtered or unexported fields
}

A Runner lints the cases in a configuration.

func NewRunner

func NewRunner(flags *core.CLIFlags) *Runner

NewRunner prepares to run cases against the configuration in `flags`.

func (*Runner) Close added in v3.24.0

func (r *Runner) Close()

Close removes the packages installed for the run.

func (*Runner) Rules added in v3.23.0

func (r *Runner) Rules(paths []string) ([]string, error)

Rules names every rule under the given files and directories, the way a project run would name it.

A rule that matches nothing loads, runs, and reports success, so a case that expects nothing from it proves nothing. The rules are listed so that Uncovered can say which never produced an alert in any case.

func (*Runner) Run

func (r *Runner) Run(c Case) Result

Run lints one case and compares what came back.

type Strings added in v3.24.0

type Strings []string

Strings is one string or a list of them, so `contains: T.Rule` and a list of excerpts read the same way.

func (*Strings) UnmarshalYAML added in v3.24.0

func (s *Strings) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML accepts a scalar as a one-item list.

Jump to

Keyboard shortcuts

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