testarossa

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

README

Testa Rossa

TestaRossa is a simple utility on top of Go's standard testing library that prints the full/path/to/the/source/file/of/the/unit_test.go:line of a failed assertion, which in VSCode is a clickable link. Unlike t.Log, output is printed using fmt.Printf during the execution of the test rather than at its conclusion.

func TestMe(t *testing.T) {
	testarossa.Equal(t, 1, 0, "You are not the %d", 1)
	err := errors.New("This is bad")
	testarossa.NoError(t, err)

	droids := 1234
	testarossa.FailIf(t, droids != 0, "These are not the droids you are looking for")
	err = errors.New("This is really bad")
	testarossa.FatalIfError(t, err)
}

outputs

--- FAIL: TestMe
    /my_projects/go/github.com/microbus-io/testarossa/fail_test.go:27
    You are not the 1
--- FAIL: TestMe
    /my_projects/go/github.com/microbus-io/testarossa/fail_test.go:29
    Expected no error
    This is bad
--- FAIL: TestMe
    /my_projects/go/github.com/microbus-io/testarossa/fail_test.go:32
    These are not the droids you are looking for
--- FAIL: TestMe
    /my_projects/go/github.com/microbus-io/testarossa/fail_test.go:34
    This is really bad
--- FAIL: TestMe (0.00s)
FAIL
FAIL	github.com/microbus-io/testarossa	0.193s
FAIL

TestaRossa is licensed by Microbus LLC under the Apache License 2.0.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(t TestingT, s string, substr string, args ...any) bool

Contains fails the test if the string does not contain a substring.

func Equal

func Equal(t TestingT, expected any, actual any, args ...any) bool

Equal fails the test if the two values are not equal.

func Error

func Error(t TestingT, err error, args ...any) bool

Error fails the test if err is nil.

func ErrorContains

func ErrorContains(t TestingT, err error, substr string, args ...any) bool

ErrorContains fails the test if the err is nil or if it does not contain the substring.

func FailIf

func FailIf(t TestingT, condition bool, args ...any) bool

FailIf fails the test if the condition is met. If returns back the result of evaluating the condition.

func FailIfError

func FailIfError(t TestingT, err error, args ...any) bool

FailIfError is a shortcut to FailIf(t, err != nil, append([]any{err}, args...)...) .

func False

func False(t TestingT, condition bool, args ...any) bool

False fails the test if the condition is true.

func FatalIf

func FatalIf(t TestingT, condition bool, args ...any)

FatalIf fails the test and stops further execution if the condition is met.

func FatalIfError

func FatalIfError(t TestingT, err error, args ...any)

FatalIfError is a shortcut to FatalIf(t, err != nil, append([]any{err}, args...)...) .

func Nil

func Nil(t TestingT, obj any, args ...any) bool

Nil fails the test if the object is not nil.

func NoError

func NoError(t TestingT, err error, args ...any) bool

NoError fails the test if err is not nil.

func NotContains

func NotContains(t TestingT, s string, substr string, args ...any) bool

NotContains fails the test if the string contain a substring.

func NotEqual

func NotEqual(t TestingT, expected any, actual any, args ...any) bool

NotEqual fails the test if the two values are equal.

func NotNil

func NotNil(t TestingT, obj any, args ...any) bool

NotNil fails the test if the object is nil.

func NotZero

func NotZero[T int8 | int16 | int32 | int64 | int | float32 | float64](t TestingT, actual T, args ...any) bool

NotZero fails the test if the value is 0.

func SliceContains

func SliceContains[T any](t TestingT, slice []T, contains T, args ...any) bool

SliceContains fails the test if the slice does not contain the item.

func SliceEqual

func SliceEqual[T comparable](t TestingT, expected []T, actual []T, args ...any) bool

SliceEqual fails the test if the two values are not equal.

func SliceLen

func SliceLen[T any](t TestingT, slice []T, length int, args ...any) bool

SliceLen fails the test if the length of the slice does not match the expected len.

func SliceNotContains

func SliceNotContains[T any](t TestingT, slice []T, contains T, args ...any) bool

SliceNotContains fails the test if the slice contains the item.

func SliceNotEqual

func SliceNotEqual[T comparable](t TestingT, expected []T, actual []T, args ...any) bool

SliceNotEqual fails the test if the two values are equal.

func StrLen

func StrLen(t TestingT, s string, length int, args ...any) bool

StrLen fails the test if the length of the string does not match the expected len.

func True

func True(t TestingT, condition bool, args ...any) bool

True fails the test if the condition is false.

func Zero

func Zero[T int8 | int16 | int32 | int64 | int | float32 | float64](t TestingT, actual T, args ...any) bool

Zero fails the test if the value is not 0.

Types

type TestingT

type TestingT interface {
	Fail()
	FailNow()
	Name() string
}

TestingT is an interface that both *testing.T and *testing.B implement.

Jump to

Keyboard shortcuts

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