| 1 | // Copyright 2014 Quoc-Viet Nguyen. All rights reserved. |
| 2 | // This software may be modified and distributed under the terms |
| 3 | // of the BSD license. See the LICENSE file for details. |
| 4 | |
| 5 | package test |
| 6 | |
| 7 | import ( |
| 8 | "runtime" |
| 9 | "strings" |
| 10 | "testing" |
| 11 | ) |
| 12 | |
| 13 | func AssertEquals(t *testing.T, expected, actual interface{}) { |
| 14 | _, file, line, ok := runtime.Caller(1) |
| 15 | if !ok { |
| 16 | file = "???" |
| 17 | line = 0 |
| 18 | } else { |
| 19 | // Get file name only |
| 20 | idx := strings.LastIndex(file, "/") |
| 21 | if idx >= 0 { |
| 22 | file = file[idx+1:] |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | if expected != actual { |
| 27 | t.Logf("%s:%d: Expected: %+v (%T), actual: %+v (%T)", file, line, |
| 28 | expected, expected, actual, actual) |
| 29 | t.FailNow() |
| 30 | } |
| 31 | } |