test

package
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: GPL-3.0, GPL-3.0 Imports: 3 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 CappedWriter added in v0.20.0

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

CapperWriter is an implementation of io.Writer that stops buffering once a predefined size is reached.

func NewCappedWriter added in v0.20.0

func NewCappedWriter(size int) (*CappedWriter, error)

NewCappedWriter is the preferred method of initialisation for the CappedWriter type.

func (*CappedWriter) Reset added in v0.20.0

func (r *CappedWriter) Reset()

Reset empties the ring writer's buffer

func (*CappedWriter) String added in v0.20.0

func (r *CappedWriter) String() string

func (*CappedWriter) Write added in v0.20.0

func (r *CappedWriter) Write(p []byte) (n int, err error)

Write implements io.Writer

type CompareWriter added in v0.20.0

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

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

func (*CompareWriter) Clear added in v0.20.0

func (tw *CompareWriter) Clear()

clear string empties the buffer.

func (*CompareWriter) Compare added in v0.20.0

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

Compare buffered output with predefined/example string.

func (*CompareWriter) String added in v0.20.0

func (tw *CompareWriter) String() string

implements Stringer interface.

func (*CompareWriter) Write added in v0.20.0

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

type RingWriter added in v0.20.0

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

RingWriter is an implementation of io.Writer that will keep the buffer to a predefined size, keeping the most recent writes and dropping the earlier writes as appropriate.

func NewRingWriter added in v0.20.0

func NewRingWriter(size int) (*RingWriter, error)

NewRingWriter is the preferred method of initialisation for the CappedWriter type.

func (*RingWriter) Reset added in v0.20.0

func (r *RingWriter) Reset()

Reset empties the ring writer's buffer

func (*RingWriter) String added in v0.20.0

func (r *RingWriter) String() string

func (*RingWriter) Write added in v0.20.0

func (r *RingWriter) Write(p []byte) (n int, err error)

Write implements io.Writer

Jump to

Keyboard shortcuts

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