aboutsummaryrefslogtreecommitdiffstats

Checkmate

Go Reference Version Badge

Checkmate is a Go library designed to enhance the testing experience by providing a set of assertion functions. With Go, there is no built-in assertion library which can make writing tests feel more verbose than it needs to be, so Checkmate aims to fill that gap.

Installation

To install Checkmate, use the following command:

$ go get git.eugenetriguba.com/checkmate

Example Usage

package main

import (
    "errors"
    "testing"

    "git.eugenetriguba.com/checkmate/assert"
    "git.eugenetriguba.com/checkmate/check"
)

func TestUserCreation(t *testing.T) {
    user := &User{Name: "Alice", Age: 25}

    // assert functions fail the test and stop execution
    // on failure
    assert.NotNil(t, user)
    assert.Equal(t, user.Name, "Alice")
    assert.True(t, user.Age > 0)

    // check functions fail the test but continue execution
    // of the test.
    //
    // They're useful for situation where you don't want to
    // stop on the first assertion failure, so you get more
    // output on test failure.
    check.Equal(t, user.Age, 25)
    check.DeepEqual(t, user, &User{Name: "Alice", Age: 25})
}

func TestValidateEmail_InvalidFormat(t *testing.T) {
    err := validateEmail("invalid-email")

    assert.ErrorContains(t, err, "invalid email format")
    assert.ErrorIs(t, err, ErrInvalidFormat)
}

Reference

For documentation on the API, see: