-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |