在此先感谢您的帮助。在我的 Mac 上,当我执行一个go test ./...正确的“路径”在输出中输出:ok github.com/cnuss/server 0.008sok github.com/cnuss/server/database 0.008s? github.com/cnuss/server/handlers [no test files]ok github.com/cnuss/server/stats 0.014s但是,当我在 Ubuntu 14.04 Trusty 容器中构建时,路径已被“_”(下划线)替换:ok _/tmp/cnuss/server 0.003sok _/tmp/cnuss/server/database 0.003s? _/tmp/cnuss/server/handlers [no test files]ok _/tmp/cnuss/server/stats 0.008s路径的变化也反映在-coverprofile输出文件中,这反过来影响我正在使用的一些覆盖工具。所以问题是,什么会影响执行时解析的路径go test?我的 Mac Book 上的行为是正确的行为。
1 回答
慕田峪4524236
TA贡献1875条经验 获得超5个赞
您可能没有GOPATH在 Linux 环境中设置。
如果我src/foo/foo.go在当前目录中创建一个包含内容的文件package foo,我可以看到不同之处:
$ unset GOPATH
$ go test ./src/foo
? _/home/james/.../src/foo [no test files]
$ export GOPATH=`pwd`
$ go test ./src/foo
? foo [no test files]
如果没有GOPATH设置(或在 之外有一个包GOPATH),它就好像这是一个相对导入。
- 1 回答
- 0 关注
- 190 浏览
添加回答
举报
0/150
提交
取消