This library provides googletest inspired matchers in Golang.
It uses generics to provide typesafe matchers so trying to match non-compatible types will fail at compile time.
import m "github.com/ntnj/go-generics/matchers"
func TestM(t *testing.T) {
got := 42
m.Expect(t, got, m.Eq(42))
list := []int{2,4,6}
m.Expect(t, list, m.Contains(m.Eq(4)))
m.Expect(t, list, m.IsPermutationOf(m.Eq(4), m.Eq(6), m.Eq(2)))
}
In case of match failure, the test will fail with a nicely formatted error message, making both the tests and errors easier to read.