Skip to content

Commit

Permalink
Add internal/assert package
Browse files Browse the repository at this point in the history
  • Loading branch information
lufia committed Apr 3, 2020
1 parent 2cff4c2 commit 5918d1c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ github.com/atotto/clipboard v0.0.0-20171229224153-bc5958e1c833 h1:h/E5ryZTJAtOY6
github.com/atotto/clipboard v0.0.0-20171229224153-bc5958e1c833/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/kballard/go-shellquote v0.0.0-20170619183022-cd60e84ee657 h1:vE7J1m7cCpiRVEIr1B5ccDxRpbPsWT5JU3if2Di5nE4=
github.com/kballard/go-shellquote v0.0.0-20170619183022-cd60e84ee657/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kr/pretty v0.0.0-20160823170715-cfb55aafdaf3 h1:dhwb1Ev84SKKVBfLuhR4bw/29yYHzwtTyTLUWWnvYxI=
Expand Down
37 changes: 37 additions & 0 deletions internal/assert/assert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Package assert provides functions for testing.
package assert

import (
"fmt"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
)

// Equal makes the test as failed using default formatting if got is not equal to want.
func Equal(t testing.TB, want, got interface{}, args ...interface{}) {
t.Helper()
if !reflect.DeepEqual(want, got) {
msg := fmt.Sprint(args...)
t.Errorf("%s\n%s", msg, cmp.Diff(want, got))
}
}

// NotEqual makes the test as failed using default formatting if got is equal to want.
func NotEqual(t testing.TB, want, got interface{}, args ...interface{}) {
t.Helper()
if reflect.DeepEqual(want, got) {
msg := fmt.Sprint(args...)
t.Errorf("%s\nUnexpected: <%#v>", msg, want)
}
}

// T makes the test as failed using default formatting if ok is false.
func T(t testing.TB, ok bool, args ...interface{}) {
t.Helper()
if !ok {
msg := fmt.Sprint(args...)
t.Errorf("%s\nFailure", msg)
}
}

0 comments on commit 5918d1c

Please sign in to comment.