assert

package module
v0.0.0-...-023511b Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2018 License: MIT Imports: 5 Imported by: 0

README

assert

A simple lightweight assert extension for use with testing.T

Example usage

func TestSimpleTransitions(t *testing.T) {
	tr := fsm.NewTransitions()
	assert.NotNil(t, tr, "Transitions should have been created")

    assert.Equal(t, 12,12, "Should match")
    assert.NotEqual(t, "expected", "actual", "Should not match")

	tr.Add(Red, RedAmber, nil, nil, "")

	ok, g, a := tr.Get(Red, Green)
	assert.False(t, ok, "Red, Green not expected")
	assert.Nil(t, g)
	assert.Nil(t, a)

	ok, g, a = tr.Get(Red, RedAmber)
	assert.True(t, ok, "Expected Red, RedAmber")
	assert.Nil(t, g)
	assert.Nil(t, a)
}

Currently there are the following comparison functions

  • Equal | NotEqual
  • Len
  • Nil | NotNil
  • True | False
  • Error | NotError

Generally each methods is supplied with:

  1. a *testing.T as the first parameter.
  2. An expected then actual value (e.g. for Equal & Len) or just an actual value
  3. Optional Messages that will be output on a failure

If you construct a test that asserts in a descendant function, then the line reported in the assert failure will be the line in that descendant function. You can alter this so the line in the calling function is identified by adding a call to CallStackAdjust(1) at the start of the descendant and CallStackReset() at the end.

The parameter to CallStackAdjust is the number of stack levels UP to report, usually 1 will suffice, but if you have several levels of nesting before the assert then this can be adjusted as necessary.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallStackAdjust

func CallStackAdjust(l int)

func CallStackReset

func CallStackReset()

func Equal

func Equal(t *testing.T, expected, actual interface{}, message ...string)

Equal tries to establish if the two values are compareEquality via reflection and if that fails then via conversion to string

func Error

func Error(t *testing.T, actual error, message ...string)

Error checks that the actual error is not nil (compiler will check it supports the error interface)

func False

func False(t *testing.T, actual bool, message ...string)

False checks that the actual value is false

func Len

func Len(t *testing.T, expected int, actual interface{}, message ...string)

Checks that the lengths of the supplied Slice | Map | String are the same

func Nil

func Nil(t *testing.T, actual interface{}, message ...string)

Nil checks that the actual value is nil

func NotEqual

func NotEqual(t *testing.T, expected, actual interface{}, message ...string)

NotEqual utilises the same method as Equal but returns the complement

func NotError

func NotError(t *testing.T, actual error, message ...string)

Error checks that the actual error is nil (compiler will check it supports the error interface)

func NotNil

func NotNil(t *testing.T, actual interface{}, message ...string)

NotNil checks that the actual value is not nil

func True

func True(t *testing.T, actual bool, message ...string)

True checks that the actual value is true

Types

This section is empty.

Jump to

Keyboard shortcuts

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