blob: 9cf23a7f6c70cf4dfb9bde76186d7359432730bd [file] [log] [blame]
Jamie Hannafordb2b237f2014-09-15 12:17:47 +02001package testhelper
2
Jamie Hannaford6bcf2582014-09-15 12:52:51 +02003import (
4 "reflect"
5 "testing"
6)
Jamie Hannafordb2b237f2014-09-15 12:17:47 +02007
Jamie Hannaford0f26e5c2014-09-15 15:46:58 +02008// AssertEquals compares two arbitrary values and performs a comparison. If the
Jamie Hannaford2964aed2014-09-15 12:20:02 +02009// comparison fails, a fatal error is raised that will fail the test
Jamie Hannaford0f26e5c2014-09-15 15:46:58 +020010func AssertEquals(t *testing.T, expected, actual interface{}) {
Jamie Hannafordb2b237f2014-09-15 12:17:47 +020011 if expected != actual {
12 t.Fatalf("Expected [%#v] but got [%#v]", expected, actual)
13 }
14}
15
Jamie Hannaford0f26e5c2014-09-15 15:46:58 +020016// CheckEquals is similar to AssertEquals, except with a non-fatal error
17func CheckEquals(t *testing.T, expected, actual interface{}) {
18 if expected != actual {
19 t.Errorf("Expected [%#v] but got [%#v]", expected, actual)
20 }
21}
22
23// AssertDeepEquals - like Equals - performs a comparison - but on more complex
Jamie Hannaford6bcf2582014-09-15 12:52:51 +020024// structures that requires deeper inspection
Jamie Hannaford0f26e5c2014-09-15 15:46:58 +020025func AssertDeepEquals(t *testing.T, actual, expected interface{}) {
Jamie Hannaford6bcf2582014-09-15 12:52:51 +020026 if !reflect.DeepEqual(actual, expected) {
27 t.Fatalf("Expected %#v but got %#v", expected, actual)
28 }
29}
30
Jamie Hannaford0f26e5c2014-09-15 15:46:58 +020031// CheckDeepEquals is similar to AssertDeepEquals, except with a non-fatal error
32func CheckDeepEquals(t *testing.T, actual, expected interface{}) {
33 if !reflect.DeepEqual(actual, expected) {
34 t.Errorf("Expected %#v but got %#v", expected, actual)
35 }
36}
37
38// AssertNoErr is a convenience function for checking whether an error value is
39// an actual error
40func AssertNoErr(t *testing.T, e error) {
Jamie Hannafordb2b237f2014-09-15 12:17:47 +020041 if e != nil {
42 t.Fatalf("Unexpected error: %#v", e)
43 }
44}
Jamie Hannaford0f26e5c2014-09-15 15:46:58 +020045
46// CheckNoErr is similar to AssertNoErr, except with a non-fatal error
47func CheckNoErr(t *testing.T, e error) {
48 if e != nil {
49 t.Errorf("Unexpected error: %#v", e)
50 }
51}