testutil

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 8 Imported by: 0

README

Testutil

Simple test helper for go

Go Report Card

Synopsis

type Assert struct { T *testing.T }
func NewAssert(t *testing.T) Assert
func (a Assert) Eq(assertionfmt string, value1, value2 interface{}, v ...interface{}) bool
func (a Assert) Err(assertionfmt, errsubstr string, err error, v ...interface{}) bool
func (a Assert) NoErr(assertionfmt string, err error, v ...interface{}) bool
func (a Assert) Ok(assertionfmt string, ok bool, v ...interface{}) bool
func (a Assert) Panic(expectedPanicRegExp string, f func()) bool
func RecoverAsFail(t *testing.T)
func Repr(v interface{}) string

Examples

func TestFoo(t *testing.T) {
  assert := testutil.NewAssert(t)
  assert.Eq("Foo does the expected thing", Foo(), "bar")
}

RecoverAsFail catches a panic and converts it into a test failure

func TestThing(t *testing.T) {
  defer testutil.RecoverAsFail(t)
  somethingThatMayPanic()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecoverAsFail

func RecoverAsFail(t *testing.T)

RecoverAsFail catches a panic and converts it into a test failure. Example:

func TestThing(t *testing.T) {
  defer testutil.RecoverAsFail(t)
  somethingThatMayPanic()
}

func Repr

func Repr(v interface{}) string

Types

type Assert

type Assert struct {
	T *testing.T
}

func NewAssert

func NewAssert(t *testing.T) Assert

func (Assert) Eq

func (a Assert) Eq(assertionfmt string, value1, value2 interface{}, v ...interface{}) bool

Eq checks that value1 and value2 are equal.

Accepts the following types of values: - Anything type that you can compare with "==" in Go (bool, int, float, string, etc.) - Pointer types (e.g. *struct) - []byte

func (Assert) Err

func (a Assert) Err(assertionfmt, errsubstr string, err error, v ...interface{}) bool

func (Assert) NoErr

func (a Assert) NoErr(assertionfmt string, err error, v ...interface{}) bool

func (Assert) Ok

func (a Assert) Ok(assertionfmt string, ok bool, v ...interface{}) bool

func (Assert) Panic

func (a Assert) Panic(expectedPanicRegExp string, f func()) bool

Jump to

Keyboard shortcuts

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