assert

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 4 Imported by: 0

README

Go Report Card

assert

assert is a tiny, zero-dependency assertion library for Go tests.

The project focuses on a single goal: provide the most useful test assertions with no framework bloat and no external dependency tree. If you like the convenience of assertion helpers but want to avoid alternatives like testify/assert, this library is designed for you.

It keeps the API intentionally small and practical, with helpers such as:

  • boolean assertions
  • error matching (ErrorIs)
  • nil / not-nil checks
  • panic assertions
  • timeout-based test guards

In short: a lean assertion toolkit that stays close to the standard testing package and gets out of your way.

One package, both assert and require semantics

Unlike ecosystems where you import separate packages for assert and require, this library uses one API and lets you configure failure behavior via New(failFunc ...).

  • Use a non-fatal fail function (for example t.Errorf) when you want assert-like behavior.
  • Use a fatal fail function (for example t.FailNow) when you want require-like behavior.
requireLike := assert.New()

assertLike := assert.New(func(t *testing.T, format string, params ...any) {
	t.Helper()
	t.Errorf(format, params...)
})

This gives you the same practical flexibility while keeping dependencies and API surface minimal.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assert

type Assert interface {
	Assert(t *testing.T, result bool)
	ErrorIs(t *testing.T, actual error, expected error)
	Nil(t *testing.T, actual any)
	NotNil(t *testing.T, actual any)
	WithTimeout(t *testing.T, duration time.Duration, test func(t *testing.T))
	Panics(t *testing.T, f func())
}

func New

func New(failFunc ...FailFunc) Assert

type FailFunc

type FailFunc func(t *testing.T, format string, params ...any)

Jump to

Keyboard shortcuts

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