| 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 errorsscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/ |
| 10 | |
| 11 | import ( |
| 12 | "stringsscip-go gomod github.com/golang/go/src go1.17 strings/" |
| 13 | "testingscip-go gomod github.com/golang/go/src go1.17 testing/" |
| 14 | ) |
| 15 | |
| 16 | func callerscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/caller().() stacktracescip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/stacktrace# { |
| 17 | return newStackTracescip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/newStackTrace().() |
| 18 | } |
| 19 | |
| 20 | func TestStacktraceOutputscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/TestStacktraceOutput().(t *testingscip-go gomod github.com/golang/go/src go1.17 testing/.Tscip-go gomod github.com/golang/go/src go1.17 testing/T#) { |
| 21 | st := callerscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/caller().() |
| 22 | expectedPhrase := "/errors/stacktrace_test.go:21" |
| 23 | if !stringsscip-go gomod github.com/golang/go/src go1.17 strings/.Containsscip-go gomod github.com/golang/go/src go1.17 strings/Contains().(st.Stringscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/stacktrace#String().(), expectedPhrase) { |
| 24 | t.Fatalfscip-go gomod github.com/golang/go/src go1.17 testing/common#Fatalf().("expectedUnwrap %v phrase into the stacktrace, received stacktrace: \n%v", expectedPhrase, st.Stringscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/stacktrace#String().()) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | func TestStacktraceProgramCounterLenscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/TestStacktraceProgramCounterLen().(t *testingscip-go gomod github.com/golang/go/src go1.17 testing/.Tscip-go gomod github.com/golang/go/src go1.17 testing/T#) { |
| 29 | st := callerscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/caller().() |
| 30 | output := st.Stringscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/errors`/stacktrace#String().() |
| 31 | lines := len(stringsscip-go gomod github.com/golang/go/src go1.17 strings/.Splitscip-go gomod github.com/golang/go/src go1.17 strings/Split().(stringsscip-go gomod github.com/golang/go/src go1.17 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.17 strings/TrimSuffix().(output, "\n"), "\n")) |
| 32 | if len(st) != lines { |
| 33 | t.Fatalfscip-go gomod github.com/golang/go/src go1.17 testing/common#Fatalf().("output lines vs program counter size mismatch: program counter size %v, output lines %v", len(st), lines) |
| 34 | } |
| 35 | } |