File: stacktrace_test.go

package info (click to toggle)
golang-github-efficientgo-core 1.0.0~rc3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 580 kB
  • sloc: makefile: 68
file content (35 lines) | stat: -rw-r--r-- 946 bytes parent folder | download
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
// Copyright (c) The EfficientGo Authors.
// Licensed under the Apache License 2.0.

// Initially copied from Thanos and contributed by https://github.com/bisakhmondal.
//
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.

package errors

import (
	"strings"
	"testing"
)

func caller() stacktrace {
	return newStackTrace()
}

func TestStacktraceOutput(t *testing.T) {
	st := caller()
	expectedPhrase := "/errors/stacktrace_test.go:21"
	if !strings.Contains(st.String(), expectedPhrase) {
		t.Fatalf("expectedUnwrap %v phrase into the stacktrace, received stacktrace: \n%v", expectedPhrase, st.String())
	}
}

func TestStacktraceProgramCounterLen(t *testing.T) {
	st := caller()
	output := st.String()
	lines := len(strings.Split(strings.TrimSuffix(output, "\n"), "\n"))
	if len(st) != lines {
		t.Fatalf("output lines vs program counter size mismatch: program counter size %v, output lines %v", len(st), lines)
	}
}