parse_panic_test.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package errors
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. var createdBy = `panic: hello!
  7. goroutine 54 [running]:
  8. runtime.panic(0x35ce40, 0xc208039db0)
  9. /0/c/go/src/pkg/runtime/panic.c:279 +0xf5
  10. github.com/loopj/bugsnag-example-apps/go/revelapp/app/controllers.func·001()
  11. /0/go/src/github.com/loopj/bugsnag-example-apps/go/revelapp/app/controllers/app.go:13 +0x74
  12. net/http.(*Server).Serve(0xc20806c780, 0x910c88, 0xc20803e168, 0x0, 0x0)
  13. /0/c/go/src/pkg/net/http/server.go:1698 +0x91
  14. created by github.com/loopj/bugsnag-example-apps/go/revelapp/app/controllers.App.Index
  15. /0/go/src/github.com/loopj/bugsnag-example-apps/go/revelapp/app/controllers/app.go:14 +0x3e
  16. goroutine 16 [IO wait]:
  17. net.runtime_pollWait(0x911c30, 0x72, 0x0)
  18. /0/c/go/src/pkg/runtime/netpoll.goc:146 +0x66
  19. net.(*pollDesc).Wait(0xc2080ba990, 0x72, 0x0, 0x0)
  20. /0/c/go/src/pkg/net/fd_poll_runtime.go:84 +0x46
  21. net.(*pollDesc).WaitRead(0xc2080ba990, 0x0, 0x0)
  22. /0/c/go/src/pkg/net/fd_poll_runtime.go:89 +0x42
  23. net.(*netFD).accept(0xc2080ba930, 0x58be30, 0x0, 0x9103f0, 0x23)
  24. /0/c/go/src/pkg/net/fd_unix.go:409 +0x343
  25. net.(*TCPListener).AcceptTCP(0xc20803e168, 0x8, 0x0, 0x0)
  26. /0/c/go/src/pkg/net/tcpsock_posix.go:234 +0x5d
  27. net.(*TCPListener).Accept(0xc20803e168, 0x0, 0x0, 0x0, 0x0)
  28. /0/c/go/src/pkg/net/tcpsock_posix.go:244 +0x4b
  29. github.com/revel/revel.Run(0xe6d9)
  30. /0/go/src/github.com/revel/revel/server.go:113 +0x926
  31. main.main()
  32. /0/go/src/github.com/loopj/bugsnag-example-apps/go/revelapp/app/tmp/main.go:109 +0xe1a
  33. `
  34. var normalSplit = `panic: hello!
  35. goroutine 54 [running]:
  36. runtime.panic(0x35ce40, 0xc208039db0)
  37. /0/c/go/src/pkg/runtime/panic.c:279 +0xf5
  38. github.com/loopj/bugsnag-example-apps/go/revelapp/app/controllers.func·001()
  39. /0/go/src/github.com/loopj/bugsnag-example-apps/go/revelapp/app/controllers/app.go:13 +0x74
  40. net/http.(*Server).Serve(0xc20806c780, 0x910c88, 0xc20803e168, 0x0, 0x0)
  41. /0/c/go/src/pkg/net/http/server.go:1698 +0x91
  42. goroutine 16 [IO wait]:
  43. net.runtime_pollWait(0x911c30, 0x72, 0x0)
  44. /0/c/go/src/pkg/runtime/netpoll.goc:146 +0x66
  45. net.(*pollDesc).Wait(0xc2080ba990, 0x72, 0x0, 0x0)
  46. /0/c/go/src/pkg/net/fd_poll_runtime.go:84 +0x46
  47. net.(*pollDesc).WaitRead(0xc2080ba990, 0x0, 0x0)
  48. /0/c/go/src/pkg/net/fd_poll_runtime.go:89 +0x42
  49. net.(*netFD).accept(0xc2080ba930, 0x58be30, 0x0, 0x9103f0, 0x23)
  50. /0/c/go/src/pkg/net/fd_unix.go:409 +0x343
  51. net.(*TCPListener).AcceptTCP(0xc20803e168, 0x8, 0x0, 0x0)
  52. /0/c/go/src/pkg/net/tcpsock_posix.go:234 +0x5d
  53. net.(*TCPListener).Accept(0xc20803e168, 0x0, 0x0, 0x0, 0x0)
  54. /0/c/go/src/pkg/net/tcpsock_posix.go:244 +0x4b
  55. github.com/revel/revel.Run(0xe6d9)
  56. /0/go/src/github.com/revel/revel/server.go:113 +0x926
  57. main.main()
  58. /0/go/src/github.com/loopj/bugsnag-example-apps/go/revelapp/app/tmp/main.go:109 +0xe1a
  59. `
  60. var lastGoroutine = `panic: hello!
  61. goroutine 16 [IO wait]:
  62. net.runtime_pollWait(0x911c30, 0x72, 0x0)
  63. /0/c/go/src/pkg/runtime/netpoll.goc:146 +0x66
  64. net.(*pollDesc).Wait(0xc2080ba990, 0x72, 0x0, 0x0)
  65. /0/c/go/src/pkg/net/fd_poll_runtime.go:84 +0x46
  66. net.(*pollDesc).WaitRead(0xc2080ba990, 0x0, 0x0)
  67. /0/c/go/src/pkg/net/fd_poll_runtime.go:89 +0x42
  68. net.(*netFD).accept(0xc2080ba930, 0x58be30, 0x0, 0x9103f0, 0x23)
  69. /0/c/go/src/pkg/net/fd_unix.go:409 +0x343
  70. net.(*TCPListener).AcceptTCP(0xc20803e168, 0x8, 0x0, 0x0)
  71. /0/c/go/src/pkg/net/tcpsock_posix.go:234 +0x5d
  72. net.(*TCPListener).Accept(0xc20803e168, 0x0, 0x0, 0x0, 0x0)
  73. /0/c/go/src/pkg/net/tcpsock_posix.go:244 +0x4b
  74. github.com/revel/revel.Run(0xe6d9)
  75. /0/go/src/github.com/revel/revel/server.go:113 +0x926
  76. main.main()
  77. /0/go/src/github.com/loopj/bugsnag-example-apps/go/revelapp/app/tmp/main.go:109 +0xe1a
  78. goroutine 54 [running]:
  79. runtime.panic(0x35ce40, 0xc208039db0)
  80. /0/c/go/src/pkg/runtime/panic.c:279 +0xf5
  81. github.com/loopj/bugsnag-example-apps/go/revelapp/app/controllers.func·001()
  82. /0/go/src/github.com/loopj/bugsnag-example-apps/go/revelapp/app/controllers/app.go:13 +0x74
  83. net/http.(*Server).Serve(0xc20806c780, 0x910c88, 0xc20803e168, 0x0, 0x0)
  84. /0/c/go/src/pkg/net/http/server.go:1698 +0x91
  85. `
  86. var result = []StackFrame{
  87. StackFrame{File: "/0/c/go/src/pkg/runtime/panic.c", LineNumber: 279, Name: "panic", Package: "runtime"},
  88. StackFrame{File: "/0/go/src/github.com/loopj/bugsnag-example-apps/go/revelapp/app/controllers/app.go", LineNumber: 13, Name: "func.001", Package: "github.com/loopj/bugsnag-example-apps/go/revelapp/app/controllers"},
  89. StackFrame{File: "/0/c/go/src/pkg/net/http/server.go", LineNumber: 1698, Name: "(*Server).Serve", Package: "net/http"},
  90. }
  91. var resultCreatedBy = append(result,
  92. StackFrame{File: "/0/go/src/github.com/loopj/bugsnag-example-apps/go/revelapp/app/controllers/app.go", LineNumber: 14, Name: "App.Index", Package: "github.com/loopj/bugsnag-example-apps/go/revelapp/app/controllers", ProgramCounter: 0x0})
  93. func TestParsePanic(t *testing.T) {
  94. todo := map[string]string{
  95. "createdBy": createdBy,
  96. "normalSplit": normalSplit,
  97. "lastGoroutine": lastGoroutine,
  98. }
  99. for key, val := range todo {
  100. Err, err := ParsePanic(val)
  101. if err != nil {
  102. t.Fatal(err)
  103. }
  104. if Err.TypeName() != "panic" {
  105. t.Errorf("Wrong type: %s", Err.TypeName())
  106. }
  107. if Err.Error() != "hello!" {
  108. t.Errorf("Wrong message: %s", Err.TypeName())
  109. }
  110. if Err.StackFrames()[0].Func() != nil {
  111. t.Errorf("Somehow managed to find a func...")
  112. }
  113. result := result
  114. if key == "createdBy" {
  115. result = resultCreatedBy
  116. }
  117. if !reflect.DeepEqual(Err.StackFrames(), result) {
  118. t.Errorf("Wrong stack for %s: %#v", key, Err.StackFrames())
  119. }
  120. }
  121. }