ez

package module
v0.0.0-...-2953b31 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2019 License: BSD-3-Clause Imports: 9 Imported by: 0

README

ez

A Go Package for Easy, Powerful Tests and Benchmarks, written by Alvaro J. Genial.

Build Status GoDoc

Synopsis

The purpose of this library is to facilitate the testing and benchmarking of Go code. It accomplishes this goal by...

  • Reducing the amount of boilerplate needed to a mininum.
  • Eliminating most of the manual, error-prone parts of testing.
  • Allowing testing code to be automatically reused for benchmarking.
  • Providing a series of useful, contextual information automatically.
  • Focusing on what is being tested rather than how it is done.

...while remaining compatible with the standard testing package (used by the go test tool) as well as preserving its lightweight approach.

Status

This library is still very experimental and thus may change greatly in both interface and implementation. Please refrain from using it a production setting unless breaking changes can be tolerated.

Dependencies

The only requirement is Go 1.0 or later.

License

This library is distributed under a BSD-style LICENSE.

Documentation

Overview

Package ez provides an easy, powerful way to define tests & benchmarks that are compatible with package `testing`.

Index

Constants

This section is empty.

Variables

View Source
var Any struct{}

Any is a placeholder that can be used with Out and Panic, and it means any value is acceptable.

View Source
var Colorize = true

Colorize determines whether to attempt to use terminal colors.

View Source
var Diff = gitDiff

Diff is a function that should produce a string representing the difference between two strings. By default it attempts to use the git command to produce an inline diff, which can be colorized.

View Source
var Error struct{}

Error is a placeholder that can be used with Out and Panic, and it means any error is acceptable.

View Source
var Zero struct{}

Zero is a placeholder that can be used with Out and Panic, and it means only the zero value is acceptable.

Functions

func In

func In(xs ...interface{}) *in

In returns xs as inputs that can be used in a Case or CaseMap.

func Out

func Out(xs ...interface{}) out

Out returns xs as outputs that can be used in a Case or CaseMap.

func Panic

func Panic() out

Panic returns a requirement to panic with any value, and can be used in a Case or CaseMap; it is equivalent to PanicWith(Any).

func PanicWith

func PanicWith(x interface{}) out

PanicWith returns a requirement to panic with x, and can be used in a Case or CaseMap.

Types

type Case

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

A Case represents a function and its required input and output values.

type CaseMap

type CaseMap map[*in]out

A CaseMap is a mapping from inputs to outputs.

type Step

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

A Step holds arbitrary code to execute during a specific part of a test.

type Unit

type Unit struct {
	T *testing.T
	B *testing.B
	// contains filtered or unexported fields
}

A Unit is a specification that can be used for testing and/or benchmarking.

func Benchmark

func Benchmark(fn interface{}, b *testing.B) *Unit

Benchmark returns a Unit for benchmarking fn using b.

func New

func New() *Unit

New returns a blank Unit.

func Seq

func Seq() *Unit

Seq is a synonym for New until Sequential is split out from Parallel test types.

func Test

func Test(fn interface{}, t *testing.T) *Unit

Test returns a Unit for testing fn using t.

func (*Unit) Call

func (u *Unit) Call(fn interface{}) *Unit

Call is a synonym for Func until Sequential is split out from Parallel test types.

func (*Unit) Case

func (u *Unit) Case(in in, out out) *Unit

Case adds in & out (plus the current function) as a Case to the Unit.

func (*Unit) Cases

func (u *Unit) Cases(cs CaseMap) *Unit

Cases adds every in/out pair in the CaseMap (plus the current function) as a Case to the Unit.

func (*Unit) Do

func (u *Unit) Do(fn func()) *Unit

Do is a synonym for Step until Sequential is split out from Parallel test types.

func (*Unit) Equal

func (u *Unit) Equal(x interface{}, y interface{}) *Unit

TODO: Split into Is(xs ...interface{}) + EqualTo(xs ...interface{})

func (*Unit) Func

func (u *Unit) Func(fn interface{}) *Unit

Func sets fn as the Unit's current function; it can be called more than once.

func (*Unit) In

func (u *Unit) In(xs ...interface{}) *half

In begins a Case with xs as inputs.

func (*Unit) Run

func (u *Unit) Run()

Run runs the Unit as a test and/or benchmark, depending on whether T and/or B are set.

func (*Unit) RunBenchmark

func (u *Unit) RunBenchmark(b *testing.B)

RunBenchmark runs the Unit as a benchmark using b.

func (*Unit) RunTest

func (u *Unit) RunTest(t *testing.T)

RunTest runs the Unit as a test using t.

func (*Unit) Step

func (u *Unit) Step(fn func()) *Unit

Step adds fn to the Unit as a Step.

func (*Unit) Thru

func (u *Unit) Thru(fn func(*Unit)) *Unit

Thru applies fn to the Unit, which is useful to combine or repeat common Unit components.

Jump to

Keyboard shortcuts

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