cweill / gotests

Automatically generate Go test boilerplate from your source code.
Apache License 2.0
4.92k stars 346 forks source link

testify template results in wrong assert import depending on module cache #153

Closed mgabeler-lee-6rs closed 3 years ago

mgabeler-lee-6rs commented 3 years ago

go.mod:

module example

go 1.16

require github.com/stretchr/testify v1.7.0 // indirect

example.go:

package example

func Foo(in string) string {
    return in
}

run: gotests -template testify -only '^Foo$' ./example.go

Output:

package example

import (
    "testing"

    "gotest.tools/assert"
)

func TestFoo(t *testing.T) {
// ...
}

Note the import of assert from the wrong package.

If I run go clean -modcache, and then go mod download and then run gotests again, it generates the proper imports.

The output of this tool should not be broken by the presence of unrelated packages in the module cache.

butuzov commented 3 years ago

It's because of how the imports process works, and testify clearly not provided. I guess I will fix this as part of #152 as it also affects my tests alongside of #154