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 ¶
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 ¶
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.
type Line ¶
A Line is one line of a diff.
func Diff ¶
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 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.