| 1 | // Copyright (c) The EfficientGo Authors. |
| 2 | // Licensed under the Apache License 2.0. |
| 3 | |
| 4 | // Initially copied from Thanos and contributed by https://github.com/bisakhmondal. |
| 5 | // |
| 6 | // Copyright (c) The Thanos Authors. |
| 7 | // Licensed under the Apache License 2.0. |
| 8 | |
| 9 | package errors |
| 10 | |
| 11 | import ( |
| 12 | "strings" |
| 13 | "testing" |
| 14 | ) |
| 15 | |
| 16 | func caller() stacktrace { |
| 17 | return newStackTrace() |
| 18 | } |
| 19 | |
| 20 | func TestStacktraceOutput(t *testing.T) { |
| 21 | st := caller() |
| 22 | expectedPhrase := "/errors/stacktrace_test.go:21" |
| 23 | if !strings.Contains(st.String(), expectedPhrase) { |
| 24 | t.Fatalf("expectedUnwrap %v phrase into the stacktrace, received stacktrace: \n%v", expectedPhrase, st.String()) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | func TestStacktraceProgramCounterLen(t *testing.T) { |
| 29 | st := caller() |
| 30 | output := st.String() |
| 31 | lines := len(strings.Split(strings.TrimSuffix(output, "\n"), "\n")) |
| 32 | if len(st) != lines { |
| 33 | t.Fatalf("output lines vs program counter size mismatch: program counter size %v, output lines %v", len(st), lines) |
| 34 | } |
| 35 | } |