OSDN Git Service

Remove the types float and complex.
[pf3gnuchains/gcc-fork.git] / libgo / go / runtime / debug / stack_test.go
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.
4
5 package debug
6
7 import (
8         "strings"
9         "testing"
10 )
11
12 type T int
13
14 func (t *T) ptrmethod() []byte {
15         return Stack()
16 }
17 func (t T) method() []byte {
18         return t.ptrmethod()
19 }
20
21 /*
22         The traceback should look something like this, modulo line numbers and hex constants.
23         Don't worry much about the base levels, but check the ones in our own package.
24
25                 /Users/r/go/src/pkg/runtime/debug/stack_test.go:15 (0x13878)
26                         *T.ptrmethod: return Stack()
27                 /Users/r/go/src/pkg/runtime/debug/stack_test.go:18 (0x138dd)
28                         T.method: return t.ptrmethod()
29                 /Users/r/go/src/pkg/runtime/debug/stack_test.go:23 (0x13920)
30                         TestStack: b := T(0).method()
31                 /Users/r/go/src/pkg/testing/testing.go:132 (0x14a7a)
32                         tRunner: test.F(t)
33                 /Users/r/go/src/pkg/runtime/proc.c:145 (0xc970)
34                         ???: runtimeĀ·unlock(&runtimeĀ·sched);
35 */
36 func TestStack(t *testing.T) {
37         b := T(0).method()
38         lines := strings.Split(string(b), "\n", -1)
39         if len(lines) <= 6 {
40                 t.Fatal("too few lines")
41         }
42         check(t, lines[0], "src/pkg/runtime/debug/stack_test.go")
43         check(t, lines[1], "\t*T.ptrmethod: return Stack()")
44         check(t, lines[2], "src/pkg/runtime/debug/stack_test.go")
45         check(t, lines[3], "\tT.method: return t.ptrmethod()")
46         check(t, lines[4], "src/pkg/runtime/debug/stack_test.go")
47         check(t, lines[5], "\tTestStack: b := T(0).method()")
48         check(t, lines[6], "src/pkg/testing/testing.go")
49 }
50
51 func check(t *testing.T, line, has string) {
52         if strings.Index(line, has) < 0 {
53                 t.Errorf("expected %q in %q", has, line)
54         }
55 }