aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: 1556dc7fed1b3e86a1f328619b629d932d84254e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Checkmate

<p>
    <a href="https://godoc.org/git.sr.ht/~eugenetriguba/checkmate">
        <img src="https://godoc.org/git.sr.ht/~eugenetriguba/checkmate?status.svg" alt="GoDoc">
    </a>
    <a href="https://goreportcard.com/report/git.sr.ht/~eugenetriguba/checkmate">
        <img src="https://goreportcard.com/badge/git.sr.ht/~eugenetriguba/checkmate" alt="Go Report Card Badge">
    </a>
    <img alt="Version Badge" src="https://img.shields.io/badge/version-0.5.0-blue" style="max-width:100%;">
</p>

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:

```bash
$ go get git.sr.ht/~eugenetriguba/checkmate
```

## Example Usage

```go
package main

import (
    "errors"
    "testing"

    "git.sr.ht/~eugenetriguba/checkmate/assert"
    "git.sr.ht/~eugenetriguba/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:
- [Overview](https://pkg.go.dev/git.sr.ht/~eugenetriguba/checkmate)
- [assert package](https://pkg.go.dev/git.sr.ht/~eugenetriguba/checkmate/assert)
- [check package](https://pkg.go.dev/git.sr.ht/~eugenetriguba/checkmate/check)