Skip to content

Instantly share code, notes, and snippets.

@kuntao
Last active September 23, 2018 06:25
Show Gist options
  • Select an option

  • Save kuntao/531264f76b6f3ed4529e63460a97239f to your computer and use it in GitHub Desktop.

Select an option

Save kuntao/531264f76b6f3ed4529e63460a97239f to your computer and use it in GitHub Desktop.
`go test` したいがtestifyの中でやってるType Assertで落ちる。これは適当に書いたコードで `main.go` の実装は空です。
package main
import "fmt"
func main() {
fmt.Println("Nothing Implemented")
}
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
type MyString string
func TestMain(t *testing.T) {
var expected, actual MyString
expected = "expected string"
actual = "actual stirng"
// このassertで落ちる
assert.Equal(t, expected, actual, "string doesn't match")
// トレースを見ると
// assert.Equal : https://github.com/stretchr/testify/blob/master/assert/assertions.go#L338
// assert.diff : https://github.com/stretchr/testify/blob/master/assert/assertions.go#L1352
// の流れでpanic
}
@kuntao
Copy link
Author

kuntao commented Sep 23, 2018

% go test                                                                                                                                      (git)-[master]
--- FAIL: TestMain (0.00s)
panic: interface conversion: interface {} is main.MyString, not string [recovered]
	panic: interface conversion: interface {} is main.MyString, not string

goroutine 5 [running]:
testing.tRunner.func1(0xc000104100)
	/Users/kuntaro/.gvm/gos/go1.11/src/testing/testing.go:792 +0x387
panic(0x129a460, 0xc000094fc0)
	/Users/kuntaro/.gvm/gos/go1.11/src/runtime/panic.go:513 +0x1b9
github.com/kuntao/kuntao_monkey/vendor/github.com/stretchr/testify/assert.diff(0x1280a40, 0xc000010e80, 0x1280a40, 0xc000010e90, 0x0, 0x0)
	/Users/kuntaro/.gvm/pkgsets/go1.11/global/src/github.com/kuntao/kuntao_monkey/vendor/github.com/stretchr/testify/assert/assertions.go:1352 +0x454
github.com/kuntao/kuntao_monkey/vendor/github.com/stretchr/testify/assert.Equal(0x1331940, 0xc000104100, 0x1280a40, 0xc000010e80, 0x1280a40, 0xc000010e90, 0xc0000aff88, 0x1, 0x1, 0x5a963f6d3ffe)
	/Users/kuntaro/.gvm/pkgsets/go1.11/global/src/github.com/kuntao/kuntao_monkey/vendor/github.com/stretchr/testify/assert/assertions.go:338 +0x26c
github.com/kuntao/kuntao_monkey.TestMain(0xc000104100)
	/Users/kuntaro/.gvm/pkgsets/go1.11/global/src/github.com/kuntao/kuntao_monkey/main_test.go:17 +0x12e
testing.tRunner(0xc000104100, 0x12fcd68)
	/Users/kuntaro/.gvm/gos/go1.11/src/testing/testing.go:827 +0xbf
created by testing.(*T).Run
	/Users/kuntaro/.gvm/gos/go1.11/src/testing/testing.go:878 +0x353
exit status 2
FAIL	github.com/kuntao/kuntao_monkey	0.047s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment