Skip to content

Instantly share code, notes, and snippets.

@packrat386
Created November 15, 2016 20:02
Show Gist options
  • Save packrat386/4f276d5b47ad4a3f23d0e4cf333f0cce to your computer and use it in GitHub Desktop.
Save packrat386/4f276d5b47ad4a3f23d0e4cf333f0cce to your computer and use it in GitHub Desktop.
Assert panics comparing number to nil
package lolwut
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestEqual(t *testing.T) {
assert.Equal(t, 1, nil)
}
[fg-386] ~ > go test lolwut_test.go
--- FAIL: TestEqual (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0xa0 pc=0x101fb5]
goroutine 5 [running]:
panic(0x397680, 0xc82000a110)
/usr/local/Cellar/go/1.6.3/libexec/src/runtime/panic.go:481 +0x3e6
testing.tRunner.func1(0xc820092090)
/usr/local/Cellar/go/1.6.3/libexec/src/testing/testing.go:467 +0x192
panic(0x397680, 0xc82000a110)
/usr/local/Cellar/go/1.6.3/libexec/src/runtime/panic.go:443 +0x4e9
github.com/stretchr/testify/assert.isNumericType(0x0, 0x0, 0x1)
/Users/acoyle/go/src/github.com/stretchr/testify/assert/assertions.go:311 +0x25
github.com/stretchr/testify/assert.formatUnequalValues(0x2fd020, 0xc82000b388, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/acoyle/go/src/github.com/stretchr/testify/assert/assertions.go:301 +0x400
github.com/stretchr/testify/assert.Equal(0x12148c0, 0xc820092090, 0x2fd020, 0xc82000b388, 0x0, 0x0, 0x0, 0x0, 0x0, 0x54230)
/Users/acoyle/go/src/github.com/stretchr/testify/assert/assertions.go:281 +0xe9
command-line-arguments.TestEqual(0xc820092090)
/Users/acoyle/lolwut_test.go:10 +0xba
testing.tRunner(0xc820092090, 0x5eedf0)
/usr/local/Cellar/go/1.6.3/libexec/src/testing/testing.go:473 +0x98
created by testing.RunTests
/usr/local/Cellar/go/1.6.3/libexec/src/testing/testing.go:582 +0x892
FAIL command-line-arguments 0.012s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment