gotestyourself / gotestyourself/gotest.tools
Import aliases break the so-called “minimal module support” in GOPATH mode
- Dominant language
- Go
- Stars
- 576
- Forks
- 54
- Avg merge
- 6d 3h
- Merged PRs (30d)
- 2
Description
For those of us still using GOPATH mode, it's still possible (or at least it should be) to use modern go packages with a `go.mod` seamlessly.
For a working example : https://github.com/godbus/dbus
```
$ GOPATH=$(pwd) go get github.com/godbus/dbus
$ echo $?
0
$ head -1 src/github.com/godbus/dbus/go.mod
module github.com/godbus/dbus/v5
```
However it doesn't work with gotest.tools:
```
$ GOPATH=$(pwd) go get -v gotest.tools
package gotest.tools: code in directory /tmp/gotestdir/src/gotest.tools expects import "gotest.tools/v3"
$ echo $?
1
$ head -1 src/gotest.tools/go.mod
module gotest.tools/v3
```
Question one: why does it work with `godbus`?
Answer: Thanks to the so-called “minimal module support” that was introduced in https://github.com/golang/go/commit/28ae82663a1c57c185312b60a2eae8cf06cc24b4. Basically and as I understand it, Go rewrites the import path on the fly, so we can have godbus installed in the directory `$GOPATH/src/github.com/godbus/dbus`, despite the fact that ALL the import directives in the code refer to `github.com/godbus/dbus/v5`. The directory `v5` does not need to exist.
Question two: why it doesn't work with `gotest.tools` then?
Answer: Because of the import aliases. In gotest.tools, all the package lines are of the form `package assert // import "gotest.tools/v3/assert"`. It seems that the `// import ...` prevents Go from rewriting the import path and dropping the `v3` suffix.
Suggestion: drop the import aliases?
I don't know the reason for these import aliases honestly. I tried to remove them all, and it works for me, but I don't know if it might break other configs.
Contributor guide
Assessment
This issue has not been assessed yet.