package tokenize import ( "strings" "testing" ) func SomeFunc1() { SomeFunc2() } func SomeFunc2() { SomeFunc3() } func SomeFunc3() { callerPanic("SomeFunc2", "{name} was called from {caller}") } func TestCallerPanic(t *testing.T) { defer func() { r := recover() err := r.(string) if !strings.Contains(err, "SomeFunc2 was called from") || !strings.Contains(err, "callerinfo_test.go:") { t.Fatalf("Unexpected error message: %s", err) } }() SomeFunc1() } func TestCallerBefore_WithFunctionNameNotInStack(t *testing.T) { caller := callerBefore("NotExistingAtAll") AssertEqual(t, "unknown caller", caller, "result for name not in stack") }