testsuite

package
v3.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 8 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.

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"`

	// 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 an excerpt 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 string   `yaml:"contains"`
	Absent   []string `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 {
	// 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) Run

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

Run lints one case and compares what came back.

Jump to

Keyboard shortcuts

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