Accidentally failed to commit these earlier, as part of:
[official-gcc.git] / libgo / go / runtime / debug / stack_test.go
blob5f9f60c94f345bacc43c6176ff224c12f6a12aba
1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package debug_test
7 import (
8 . "runtime/debug"
9 "strings"
10 "testing"
13 type T int
15 func (t *T) ptrmethod() []byte {
16 return Stack()
18 func (t T) method() []byte {
19 return t.ptrmethod()
23 The traceback should look something like this, modulo line numbers and hex constants.
24 Don't worry much about the base levels, but check the ones in our own package.
26 goroutine 10 [running]:
27 runtime/debug.Stack(0x0, 0x0, 0x0)
28 /Users/r/go/src/runtime/debug/stack.go:28 +0x80
29 runtime/debug.(*T).ptrmethod(0xc82005ee70, 0x0, 0x0, 0x0)
30 /Users/r/go/src/runtime/debug/stack_test.go:15 +0x29
31 runtime/debug.T.method(0x0, 0x0, 0x0, 0x0)
32 /Users/r/go/src/runtime/debug/stack_test.go:18 +0x32
33 runtime/debug.TestStack(0xc8201ce000)
34 /Users/r/go/src/runtime/debug/stack_test.go:37 +0x38
35 testing.tRunner(0xc8201ce000, 0x664b58)
36 /Users/r/go/src/testing/testing.go:456 +0x98
37 created by testing.RunTests
38 /Users/r/go/src/testing/testing.go:561 +0x86d
40 func TestStack(t *testing.T) {
41 b := T(0).method()
42 lines := strings.Split(string(b), "\n")
43 if len(lines) < 6 {
44 t.Fatal("too few lines")
46 n := 0
47 frame := func(line, code string) {
48 check(t, lines[n], code)
49 n++
50 check(t, lines[n], line)
51 n++
53 frame("stack_test.go", "\tmethod.N15_runtime_debug.T: return Stack()")
54 frame("stack_test.go", "\tmethod.N15_runtime_debug.T: return t.ptrmethod()")
55 frame("stack_test.go", "\tTestStack: b := T(0).method()")
56 frame("testing/testing.go", "")
59 func check(t *testing.T, line, has string) {
60 if !strings.Contains(line, has) {
61 t.Errorf("expected %q in %q", has, line)