test

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: GPL-3.0, GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package test bundles a bunch of useful functions useful for testing purposes, particular useful in conjunction with the standard go test harness

The AssertMainThread() and AssertNonMainThread() functions require a bit of explanation. When compiled with the "assertions" tag these functions will panic if the calling function is in the wrong thread. Otherwise they are stubbed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertMainThread

func AssertMainThread()

AssertMainThread is a stub for when "assertions" build tag is missing.

func AssertNonMainThread

func AssertNonMainThread()

AssertNonMainThread is a stub for when "assertions" build tag is missing.

func Equate

func Equate(t *testing.T, value, expectedValue interface{})

Equate is used to test equality between one value and another. Generally, both values must be of the same type but if a is of type uint16, b can be uint16 or int. The reason for this is that a literal number value is of type int. It is very convenient to write something like this, without having to cast the expected number value:

var r uint16
r = someFunction()
test.Equate(t, r, 10)

This is by no means a comprehensive comparison function. With a bit more work with the reflect package we could generalise the testing a lot more. At is is however, it's good enough.

func ExpectedFailure

func ExpectedFailure(t *testing.T, v interface{}) bool

ExpectedFailure tests argument v for a failure condition suitable for it's type. Currentlly support types:

bool -> bool == false
error -> error != nil

If type is nil then the test will fail.

func ExpectedSuccess

func ExpectedSuccess(t *testing.T, v interface{}) bool

ExpectedSuccess tests argument v for a success condition suitable for it's type. Currentlly support types:

bool -> bool == true
error -> error == nil

If type is nil then the test will succeed.

Types

type Writer

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

Writer is an implementation of the io.Writer interface. It should be used to capture output and to compare with predefined strings.

func (*Writer) Clear added in v0.3.4

func (tw *Writer) Clear()

clear string empties the buffer.

func (*Writer) Compare

func (tw *Writer) Compare(s string) bool

Compare buffered output with predefined/example string.

func (*Writer) String added in v0.3.4

func (tw *Writer) String() string

implements Stringer interface.

func (*Writer) Write

func (tw *Writer) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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