-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathstack_trace_test.go
More file actions
63 lines (51 loc) · 1.56 KB
/
Copy pathstack_trace_test.go
File metadata and controls
63 lines (51 loc) · 1.56 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
59
60
61
62
63
package agilepool
import (
"strings"
"testing"
)
// TestStack verifies basic stack trace functionality
func TestStack(t *testing.T) {
// Get stack trace skipping this function frame
stack := Stack(1)
stackStr := string(stack)
// Verify non-empty result
if len(stackStr) == 0 {
t.Error("Stack returned empty content")
}
// Verify test function name appears in trace
if !strings.Contains(stackStr, "TestStack") {
t.Errorf("Stack should contain TestStack function, got:\n%s", stackStr)
}
// Verify format includes file path and line number
if !strings.Contains(stackStr, ".go:") {
t.Errorf("Stack format error, should contain file path and line number:\n%s", stackStr)
}
t.Logf("Stack trace:\n%s", stackStr)
}
// TestNestedCall verifies stack trace captures multiple nested function calls
func TestNestedCall(t *testing.T) {
result := level1(t)
resultStr := string(result)
if len(resultStr) == 0 {
t.Error("Nested call returned empty content")
}
// All nested functions should appear in trace
if !strings.Contains(resultStr, "level1") {
t.Error("Should contain level1 function")
}
if !strings.Contains(resultStr, "level2") {
t.Error("Should contain level2 function")
}
if !strings.Contains(resultStr, "TestNestedCall") {
t.Error("Should contain TestNestedCall function")
}
t.Logf("Nested call stack:\n%s", resultStr)
}
// level1 is a helper for testing nested stack traces
func level1(t *testing.T) []byte {
return level2(t)
}
// level2 captures full stack trace (skip=0 includes all frames)
func level2(t *testing.T) []byte {
return Stack(0)
}