I'd like to wrap standard golang test functions, such as t.Errorf
from the testing package.
I tried this:
// AssertEqual tests that the expected and actual values match
func AssertEqual(t *testing.T, expected interface{}, actual interface{}) {
switch expected.(type) {
case string:
if expected != actual {
t.Errorf("Error:
expected: %s
actual: %s", expected, actual)
}
default:
t.Errorf("Unsupported type")
}
}
However, when a test fails, I get the function and line number of my helper function:
test_asserts.go:12: Error:
expected:
actual: TestValue
Is there a way to error at the line number of the caller?