assert

package module
v0.0.0-...-65b52e7 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2025 License: MIT Imports: 8 Imported by: 0

README

Assert Package

The assert package provides helper functions for writing tests in Go. It offers detailed error messages and diffs for failed assertions.

Installation

To install the package, use:

go get github.com/r2k1/assert

Example

Here's a sample usage of the assert package:

// Check for equality
assert.Equal(t, actual, expected, "Person objects should be equal")
// Error:    Not equal
// Message:  Person objects should be equal
// Expected: assert.Person{Name:"Alice", Age:30}
// Actual:   assert.Person{Name:"Alice", Age:25}
// Diff:     {
//         -   Age: 25,
//         +   Age: 30,
//         }

// Stop test execution if not equal
assert.MustEqual(t, doSomething(), nil)
// Error:    Not equal
// Expected: <nil>
// Actual:   &errors.errorString{s:"failed to do something!"}}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal[T any](t testing.TB, actual, expected T, msgAndArgs ...any) bool

Equal checks if two objects of any type are equal and reports an error if they are not.

func MustEqual

func MustEqual[T any](t testing.TB, actual, expected T)

MustEqual asserts that two objects are equal and stops test execution if they are not.

func MustNotEqual

func MustNotEqual[T any](t testing.TB, actual, expected T)

MustNotEqual asserts that two objects are not equal and stops test execution if they are not.

func NotEqual

func NotEqual[T any](t testing.TB, actual, expected T, msgAndArgs ...any) bool

NotEqual checks if two objects of any type are not equal and reports an error if they are.

Types

This section is empty.

Jump to

Keyboard shortcuts

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