common.go 650 B

12345678910111213141516171819202122232425262728293031
  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. package test
  5. import (
  6. "runtime"
  7. "strings"
  8. "testing"
  9. )
  10. func AssertEquals(t *testing.T, expected, actual interface{}) {
  11. _, file, line, ok := runtime.Caller(1)
  12. if !ok {
  13. file = "???"
  14. line = 0
  15. } else {
  16. // Get file name only
  17. idx := strings.LastIndex(file, "/")
  18. if idx >= 0 {
  19. file = file[idx+1:]
  20. }
  21. }
  22. if expected != actual {
  23. t.Logf("%s:%d: Expected: %+v (%T), actual: %+v (%T)", file, line,
  24. expected, expected, actual, actual)
  25. t.FailNow()
  26. }
  27. }