Panic message in test function removes info. to debug

43 views
Skip to first unread message

Archos

unread,
Jan 11, 2012, 12:52:16 PM1/11/12
to golang-nuts
If you get a panic message in a test function, then the message it
doesn't show info. about the stack (code and line where it was got).
It only shows:

===
--- FAIL: Example_decl
panic: runtime error: invalid memory address or nil pointer
dereference
===

func TestXXX(t *testing.T) { ... }


I know that the solution is easy; to use a normal test function to fix
it. But I want to be safe that it's so by design.

Rob 'Commander' Pike

unread,
Jan 11, 2012, 1:10:05 PM1/11/12
to Archos, golang-nuts
you need to provide an example. i put a deliberate crash at fmt_test.go:450.

% gotest
rm -f _test/fmt.a
6g -p fmt -o _gotest_.6 doc.go format.go print.go scan.go
rm -f _test/fmt.a
gopack grc _test/fmt.a _gotest_.6

panic: runtime error: invalid memory address or nil pointer dereference

[signal 0xb code=0x1 addr=0x0 pc=0x18d46]

goroutine 3 [running]:
/Users/r/go/src/pkg/fmt/_xtest_.TestSprintf(0x421af2a0, 0x195588e0)
/Users/r/go/src/pkg/fmt/fmt_test.go:450 +0x25
testing.tRunner(0x421af2a0, 0x189d68, 0x0, 0x0)
/Users/r/go/src/pkg/testing/testing.go:198 +0x41
created by testing.RunTests
/Users/r/go/src/pkg/testing/testing.go:275 +0x772

goroutine 1 [chan receive]:
testing.RunTests(0x2000, 0x189d50, 0x2300000023, 0x421bc001, 0x200000002, ...)
/Users/r/go/src/pkg/testing/testing.go:276 +0x795
testing.Main(0x2000, 0x189d50, 0x2300000023, 0x183928, 0x800000008, ...)
/Users/r/go/src/pkg/testing/testing.go:211 +0x62
main.main()
/Users/r/go/src/pkg/fmt/_testmain.go:72 +0x91
gotest: "./6.out" failed: exit status 2
%
%
% go test
FAIL fmt


panic: runtime error: invalid memory address or nil pointer dereference

[signal 0xb code=0x1 addr=0x0 pc=0x22d6c]

goroutine 3 [running]:
fmt_test.TestSprintf(0x421a82a0, 0x29cb8df0)
/Users/r/go/src/pkg/fmt/fmt_test.go:450 +0x25
testing.tRunner(0x421a82a0, 0x182d68, 0x0, 0x0)
/Users/r/go/src/pkg/testing/testing.go:198 +0x41
created by testing.RunTests
/Users/r/go/src/pkg/testing/testing.go:275 +0x772

goroutine 1 [chan receive]:
testing.RunTests(0x2000, 0x182d50, 0x2300000023, 0x421b5001, 0x200000002, ...)
/Users/r/go/src/pkg/testing/testing.go:276 +0x795
testing.Main(0x2000, 0x182d50, 0x2300000023, 0x17c928, 0x800000008, ...)
/Users/r/go/src/pkg/testing/testing.go:211 +0x62
main.main()
/var/folders/x_/rw5vv6kw8xj41q0059bfc4v00000gt/T/go-build763602956/fmt/_test/_testmain.go:127 +0x91
bismarck=% go
%

Archos

unread,
Jan 11, 2012, 5:45:11 PM1/11/12
to golang-nuts

On Jan 11, 6:10 pm, Rob 'Commander' Pike <r...@google.com> wrote:
> you need to provide an example. i put a deliberate crash at fmt_test.go:450.

I've tried with several errors but nothing. It only faills in my code.
I've commented all tests excep the example function where it faills
(for that can be reproduced easily):

git clone git://github.com/kless/GoJscript.git && cd GoJscript/gojs
gotest

You should get:
===
testing: warning: no tests to run
--- FAIL: Example_decl
panic: runtime error: invalid memory address or nil pointer
dereference
===

Now, to get the full error, you should comment out, the line 57 in
file "gojs_test.go", and try again "gotest".

Archos

unread,
Jan 12, 2012, 4:10:31 AM1/12/12
to golang-nuts

On Jan 11, 6:10 pm, Rob 'Commander' Pike <r...@google.com> wrote:
> you need to provide an example. i put a deliberate crash at fmt_test.go:450.
>
The exampe functions are masking the errors, without doubt.

===
import "testing"
import "fmt"

func Example_ff() {
var a map[int][]string
a[1][10] = "foo"

fmt.Println(a[1])
}
===
PASS


8c6f3122826c+ tip (last weekly)
Ubuntu 11.10, AMD64
Reply all
Reply to author
Forward
0 new messages