assert

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package assert provides a small collection of test assertion helpers built on top of the standard testing package.

The functions in this package are designed to be used directly inside Go test functions. Each helper accepts a *testing.T, calls t.Helper so that failure messages point to the call site, and reports errors via t.Errorf rather than t.Fatalf, allowing a test to record multiple failures in a single run.

Available Assertions

AssertEqual(t, got, want)    // deep equality via reflect.DeepEqual
AssertNil(t, value)         // value must be nil
AssertNotNil(t, value)      // value must not be nil
AssertTrue(t, condition)    // boolean must be true
AssertFalse(t, condition)   // boolean must be false

Usage

func TestAdd(t *testing.T) {
    result := Add(2, 3)
    assert.AssertEqual(t, result, 5)
}

assert is used throughout the replify test suite as a lightweight alternative to external assertion libraries, keeping test dependencies minimal while still providing clear failure messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEqual

func AssertEqual(t *testing.T, object1, object2 any)

AssertEqual compares two objects for equality and reports a test failure if they are not equal.

This function uses the `reflect.DeepEqual` function to check if `object1` and `object2` are deeply equal. If they are not, the function marks the test as failed and reports an error message.

Parameters:

  • `t`: The testing instance (from `*testing.T`) used to report failures.
  • `object1`: The first object to compare.
  • `object2`: The second object to compare.

Example:

AssertEqual(t, actualValue, expectedValue)

func AssertFalse

func AssertFalse(t *testing.T, b bool)

AssertFalse checks if the given boolean is false and reports a test failure if it is not.

This function internally calls `AssertEqual` to compare the boolean value `b` with `false`. If the comparison fails, it marks the test as failed and reports an error.

Parameters:

  • `t`: The testing instance (from `*testing.T`) used to report failures.
  • `b`: The boolean value to check.

Example:

AssertFalse(t, hasError)

func AssertNil

func AssertNil(t *testing.T, object any)

AssertNil checks if the given object is nil and reports a test failure if it is not.

This function uses the `IsNil` helper function to determine if the object is nil. If the object is not nil, it marks the test as failed and reports an error.

Parameters:

  • `t`: The testing instance (from `*testing.T`) used to report failures.
  • `object`: The object to check for nil.

Example:

AssertNil(t, err)

func AssertNotNil

func AssertNotNil(t *testing.T, object any)

AssertNotNil checks if the given object is not nil and reports a test failure if it is nil.

This function uses the `IsNil` helper function to determine if the object is nil. If the object is nil, it marks the test as failed and reports an error.

Parameters:

  • `t`: The testing instance (from `*testing.T`) used to report failures.
  • `object`: The object to check for non-nil.

Example:

AssertNotNil(t, result)

func AssertTrue

func AssertTrue(t *testing.T, b bool)

AssertTrue checks if the given boolean is true and reports a test failure if it is not.

This function internally calls `AssertEqual` to compare the boolean value `b` with `true`. If the comparison fails, it marks the test as failed and reports an error.

Parameters:

  • `t`: The testing instance (from `*testing.T`) used to report failures.
  • `b`: The boolean value to check.

Example:

AssertTrue(t, isValid)

Types

This section is empty.

Jump to

Keyboard shortcuts

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