Simple test assertions for Go. This is a fork of bmizerany/assert with improved support for things like nil pointers, etc.
$ go get github.com/stvp/assert
func Equal(t *testing.T, expected, got interface{}, messages ...interface{})
func NotEqual(t *testing.T, expected, got interface{}, messages ...interface{})
func True(t *testing.T, got interface{}, messages ...interface{})
func False(t *testing.T, got interface{}, messages ...interface{})
func Nil(t *testing.T, got interface{}, messages ...interface{})
func NotNil(t *testing.T, got interface{}, messages ...interface{})
func Contains(t *testing.T, expected string, got string, messages ...interface{})
func NotContains(t *testing.T, unexpected string, got string, messages ...interface{})
func WithinDuration(t *testing.T, duration time.Duration, goalTime, gotTime time.Time, messages ...interface{})
func Panics( t *testing.T, expected interface{}, messages ...interface{} )
package main
import "github.com/stvp/assert"
type CoolStruct struct{}
func TestThings(t *testing.T) {
myString := "cool"
assert.Equal(t, "cool", myString, "myString should be equal")
assert.NotEqual(t, "nope", myString)
var myStruct CoolStruct
assert.Nil(t, myStruct)
}
See assert_test.go for more usage examples.
You can add extra information to test failures by passing in any number of extra arguments:
assert.Equal(t, "foo", myString, "Should set up a proper foo string")
% go test
--- FAIL: TestImportantFeature (0.00 seconds)
assert.go:18: /Users/tyson/go/src/github.com/foo/bar/main_test.go:31
assert.go:38: 💩 Unexpected: "foo"
assert.go:40: 💩 - Should set up a proper foo string
FAIL
exit status 1
FAIL github.com/foo/bar 0.017s
Copyright Blake Mizerany and Keith Rarick. Licensed under the MIT license. Additional modifications by Stovepipe Studios.