utesting

package
v0.0.0-...-4c3619c Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package utesting provides a standalone replacement for package testing.

This package exists because package testing cannot easily be embedded into a standalone go program. It provides an API that mirrors the standard library testing API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountFailures

func CountFailures(rr []Result) int

CountFailures returns the number of failed tests in the result slice.

func Run

func Run(test Test) (bool, string)

Run executes a single test.

Types

type Result

type Result struct {
	Name     string
	Failed   bool
	Output   string
	Duration time.Duration
}

Result is the result of a test execution.

func RunTAP

func RunTAP(tests []Test, report io.Writer) []Result

RunTAP runs the given tests and writes Test Anything Protocol output to the report writer.

func RunTests

func RunTests(tests []Test, report io.Writer) []Result

RunTests executes all given tests in order and returns their results. If the report writer is non-nil, a test report is written to it in real time.

type T

type T struct {
	// contains filtered or unexported fields
}

T is the value given to the test function. The test can signal failures and log output by calling methods on this object.

func (*T) Error

func (t *T) Error(vs ...interface{})

Error is equivalent to Log followed by Fail.

func (*T) Errorf

func (t *T) Errorf(format string, vs ...interface{})

Errorf is equivalent to Logf followed by Fail.

func (*T) Fail

func (t *T) Fail()

Fail marks the test as having failed but continues execution.

func (*T) FailNow

func (t *T) FailNow()

FailNow marks the test as having failed and stops its execution by calling runtime.Goexit (which then runs all deferred calls in the current goroutine).

func (*T) Failed

func (t *T) Failed() bool

Failed reports whether the test has failed.

func (*T) Fatal

func (t *T) Fatal(vs ...interface{})

Fatal is equivalent to Log followed by FailNow.

func (*T) Fatalf

func (t *T) Fatalf(format string, vs ...interface{})

Fatalf is equivalent to Logf followed by FailNow.

func (*T) Helper

func (t *T) Helper()

Helper exists for compatibility with testing.T.

func (*T) Log

func (t *T) Log(vs ...interface{})

Log formats its arguments using default formatting, analogous to Println, and records the text in the error log.

func (*T) Logf

func (t *T) Logf(format string, vs ...interface{})

Logf formats its arguments according to the format, analogous to Printf, and records the text in the error log. A final newline is added if not provided.

type Test

type Test struct {
	Name string
	Fn   func(*T)
}

Test represents a single test.

func MatchTests

func MatchTests(tests []Test, expr string) []Test

MatchTests returns the tests whose name matches a regular expression.

Jump to

Keyboard shortcuts

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