-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_test.go
42 lines (34 loc) · 1.08 KB
/
example_test.go
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
package stack_test
import (
"errors"
"fmt"
"github.com/romanyx/stack"
)
func ExampleTrace() {
err := frameA()
for _, frame := range stack.Trace(err) {
fmt.Printf("%s:%d %s()\n", frame.File, frame.Line, frame.Function)
}
// Example output:
// github.com/romanyx/stack/helper_test.go:16 github.com/romanyx/stack_test.frameB()
// github.com/romanyx/stack/helper_test.go:12 github.com/romanyx/stack_test.frameA()
// github.com/romanyx/stack/example_test.go:10 github.com/romanyx/stack_test.ExampleTrance()
// /usr/local/go/src/testing/run_example.go:62 testing.runExample()
// /usr/local/go/src/testing/example.go:44 testing.runExamples()
// /usr/local/go/src/testing/testing.go:1118 testing.(*M).Run()
// _testmain.go:52 main.main()
// /usr/local/go/src/runtime/proc.go:203 runtime.main()
// /usr/local/go/src/runtime/asm_amd64.s:1357 runtime.goexit()
}
func ExampleOrigin() {
err := frameA()
fmt.Println(stack.Origin(err))
// Output:
// origin
}
func ExampleErrorf() {
err := stack.Errorf("annotated: %w", errOrigin)
fmt.Println(errors.Is(err, errOrigin))
// Output:
// true
}