assert

package module
v0.0.0-...-155bc9a Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 6 Imported by: 8

README

assert

Provides invariant checking in Golang code.

How to use

package main

import assert "github.com/ymz-ncnk/assert/panic"

// Turns on assertions.
func init() {
  assert.On = true
}

func main(){
  assert.Equal(1, 1)
}

There are also two packages error and fatal that can be used in tests:

package main

import asserterror "github.com/ymz-ncnk/assert/error"

func TestSome(t *testing.T) {
  asserterror.Equal(t, 1, 1)
  asserterror.Equal(t, 1, 2, "optional message")
  asserterror.Equal(t, 1, 2, "optional message with %s", "args")
}

Documentation

Index

Constants

View Source
const MsgSep = ": "

Variables

This section is empty.

Functions

func Bigger

func Bigger[T constraints.Ordered](a, b T, callback Callback, t *testing.T) bool

Bigger invariant will call callback if a is lesser than b.

func Equal

func Equal[T comparable](a, b T, callback Callback, t *testing.T) bool

Equal invariant will call callback if two compared variables are not equal.

func EqualBytes

func EqualBytes(a, b []byte, callback Callback, t *testing.T) bool

EqualBytes invariant will call callback if two byte slices are not equal.

func EqualDeep

func EqualDeep(a, b any, callback Callback, t *testing.T) bool

EqualDeep invariant will call callback if two variables are not deep equal.

func EqualError

func EqualError(a, b error, callback Callback, t *testing.T) bool

EqualError invariant will call callback if two errors are not equal.

func Format

func Format(msg string, msgAndArgs ...any) string

func Lesser

func Lesser[T constraints.Ordered](a, b T, callback Callback, t *testing.T) bool

Lesser invariant will call callback if a is bigger than b.

func SameTime

func SameTime(a, b time.Time, delta time.Duration, callback Callback,
	t *testing.T) bool

Types

type Callback

type Callback func(msg string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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