-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallstack_test.go
More file actions
58 lines (50 loc) · 2.06 KB
/
callstack_test.go
File metadata and controls
58 lines (50 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package golog
import (
"testing"
)
func testFuncForCallingFunction() string {
defer func() {}() // Prevent inlining
return CallingFunction()
}
func genericTestFuncForCallingFunction[T any]() string {
defer func() {}() // Prevent inlining
return CallingFunction()
}
func testFuncForCallingFunctionName() string {
defer func() {}() // Prevent inlining
return CallingFunctionName()
}
func genericTestFuncForCallingFunctionName[T any]() string {
defer func() {}() // Prevent inlining
return CallingFunctionName()
}
func TestCallingFunction(t *testing.T) {
f := CallingFunction()
if f != "github.com/domonda/golog.TestCallingFunction" {
t.Errorf("CallingFunction() should return the name of the calling function, but got %q", f)
}
if testFuncForCallingFunction() != "github.com/domonda/golog.testFuncForCallingFunction" {
t.Errorf("CallingFunction() should return the name of the calling function, but got %q", testFuncForCallingFunction())
}
if genericTestFuncForCallingFunction[int]() != "github.com/domonda/golog.genericTestFuncForCallingFunction" {
t.Errorf("CallingFunction() should return the name of the calling function, but got %q", genericTestFuncForCallingFunction[int]())
}
}
func TestCallingFunctionName(t *testing.T) {
name := CallingFunctionName()
if name != "TestCallingFunctionName" {
t.Errorf("CallingFunctionName() should return the name of the calling function, but got %q", name)
}
if testFuncForCallingFunctionName() != "testFuncForCallingFunctionName" {
t.Errorf("CallingFunctionName() should return the name of the calling function, but got %q", testFuncForCallingFunctionName())
}
if genericTestFuncForCallingFunctionName[int]() != "genericTestFuncForCallingFunctionName" {
t.Errorf("CallingFunctionName() should return the name of the calling function, but got %q", genericTestFuncForCallingFunctionName[int]())
}
}
func TestCallingFunctionPackageName(t *testing.T) {
pkg := CallingFunctionPackageName()
if pkg != "golog" {
t.Errorf("CallingFunctionPackageName() should return the package name of the calling function, but got %q", pkg)
}
}