Skip to content

barbell-math/smoothbrain-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sbtest

import "github.com/barbell-math/smoothbrain-test"

A very simple library that helps with assertions in unit tests.

Index

func ContainsError(t *testing.T, expected error, got error)

Tests that the expected error is present in the given error.

func Eq

func Eq[T comparable](t *testing.T, expected T, got T)

Tests that the supplied values are equal. For equality rules refer to the language reference: https://go.dev/ref/spec#Comparison_operators

func EqFloat

func EqFloat[T ~float32 | float64](t *testing.T, expected T, got T, eps T)

Tests that the given float is within +/- eps distance of the expected float.

func EqFunc

func EqFunc[T any](t *testing.T, expected T, got T, cmp func(l T, r T) bool)

Tests that the given value is equal to the expected value using the supplied comparison function to determine equality.

func EqOneOf

func EqOneOf[T comparable](t *testing.T, expected T, data []T)

Tests that the expected value is present in the supplied slice. For equality rules refer to the language reference: https://go.dev/ref/spec#Comparison_operators

func False

func False(t *testing.T, v bool)

Tests that the supplied value is false. This is useful for validating that expressions that evaluate to a boolean. This should not be used for equality comparisons such as `False(t, 6!=5)`. For equality comparisons refer to one of the Eq* functions defined in this file.

func FormatError(t *testing.T, expected any, got any, base string, file string, line int)

Formats an error and calls the `t.Fatal` to stop any further execution of the unit test. The error will have the following format:

Error | File <file> Line #### | <message>
Expected: (<type>) <value>
Got:      (<type>) <value>

func MapsMatch[K comparable, V any](t *testing.T, expected map[K]V, got map[K]V)

Tests that the supplied maps match in length and content. For equality rules refer to the language reference: https://go.dev/ref/spec#Comparison_operators

func Neq

func Neq[T comparable](t *testing.T, expected any, got any)

Tests that the supplied values are not equal. For equality rules refer to the language reference: https://go.dev/ref/spec#Comparison_operators

func Nil

func Nil(t *testing.T, v any)

Tests that the supplied value is nil. `nil` slices, maps, pointers, and interfaces are considered to be nil and will pass this test.

func NoPanic

func NoPanic(t *testing.T, action func())

Tests that the supplied action does not result in a panic. Any panic that does occur is recovered so all future unit tests will still run.

func NotNil

func NotNil(t *testing.T, v any)

Tests that the supplied value is not nil. `nil` slices, maps, pointers, and interfaces are considered to be nil and will fail this test.

func Panics

func Panics(t *testing.T, action func())

Tests that the supplied action results in a panic. The panic is recovered so all future unit tests will still run.

func SlicesMatch[T comparable](t *testing.T, expected []T, got []T)

Tests that the supplied slices match. In order for the slices to match they must be the same length and values in the same index must compare equal. For equality rules refer to the language reference: https://go.dev/ref/spec#Comparison_operators

func SlicesMatchUnordered[T comparable](t *testing.T, expected []T, got []T)

Tests that the supplied slices match in length and content but not in order. For equality rules refer to the language reference: https://go.dev/ref/spec#Comparison_operators

func True

func True(t *testing.T, v bool)

Tests that the supplied value is true. This is useful for validating that expressions that evaluate to a boolean. This should not be used for equality comparisons such as `True(t, 5==5)`. For equality comparisons refer to one of the Eq* functions defined in this file.

Generated by gomarkdoc

Helpful Developer Cmds

To build the build system:

go build -o ./bs/bs ./bs

The build system can then be used as usual:

./bs/bs --help
./bs/bs buildbs # Builds the build system!

About

A very simple library that helps with assertions in unit tests.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages