testdown

package module
v0.0.0-...-251e918 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 13 Imported by: 0

README

testdown

Markdown-based "golden file" test runner for Go.

Documentation

Overview

Package testdown runs "golden file" style tests defined in Markdown documents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assertion

type Assertion struct {
	Name           string
	File           string
	Line           int
	Skip           bool
	InputLanguage  string
	Input          string
	OutputLanguage string
	ExpectedOutput string
}

Assertion is a Test that describes a single assertion within a Document.

func (Assertion) AcceptVisitor

func (t Assertion) AcceptVisitor(v TestVisitor)

AcceptVisitor calls the method on v that corresponds to t's type.

type Document

type Document struct {
	Name       string
	File       string
	Skip       bool
	Assertions []Assertion
	Errors     []error
}

Document describes a Markdown document that (possibly) contains assertions.

func (Document) AcceptVisitor

func (t Document) AcceptVisitor(v TestVisitor)

AcceptVisitor calls the method on v that corresponds to t's type.

type Loader

type Loader struct {
	FS     fs.FS
	Parser parser.Parser
}

Loader loads Test values from (directories containing) Markdown documents.

func (*Loader) Load

func (l *Loader) Load(ctx context.Context, p string) (Test, error)

Load returns tests loaded from the file or directory at the given path.

type NativeRunner

type NativeRunner = Runner[*testing.T]

NativeRunner runs testdown tests within Go's native testing framework.

type Runner

type Runner[T TestingT[T]] struct {
	Output func(Assertion) (string, error)
}

Runner executes testdown tests within any test framework with an interface similar to Go's native testing framework.

func (*Runner[T]) Run

func (r *Runner[T]) Run(t T, test Test)

Run executes performs the assertions within the given Test using t.

type Suite

type Suite struct {
	Name  string
	Dir   string
	Skip  bool
	Tests []Test
}

Suite is a Test that contains other tests loaded from the same directory.

func (Suite) AcceptVisitor

func (t Suite) AcceptVisitor(v TestVisitor)

AcceptVisitor calls the method on v that corresponds to t's type.

type Test

type Test interface {
	AcceptVisitor(TestVisitor)
}

Test is an interface for a test.

type TestVisitor

type TestVisitor interface {
	VisitSuite(Suite)
	VisitDocument(Document)
	VisitAssertion(Assertion)
}

TestVisitor performs an operation based on the concrete type of a Test.

type TestingT

type TestingT[T any] interface {
	Helper()
	Parallel()
	Run(string, func(T)) bool
	Logf(string, ...any)
	Errorf(string, ...any)
	Fatalf(string, ...any)
	SkipNow()
}

TestingT is a constraint for a type that is compatible with testing.T.

Jump to

Keyboard shortcuts

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