英文:
Executing Go Tests Underscore (_) in place of correct path
问题
感谢您的帮助。
在我的Mac上,当我执行go test ./...
命令时,正确的“路径”会在输出中显示:
ok github.com/cnuss/server 0.008s
ok github.com/cnuss/server/database 0.008s
? github.com/cnuss/server/handlers [没有测试文件]
ok github.com/cnuss/server/stats 0.014s
然而,在Ubuntu 14.04 Trusty容器中构建时,路径被替换为“_”(下划线):
ok _/tmp/cnuss/server 0.003s
ok _/tmp/cnuss/server/database 0.003s
? _/tmp/cnuss/server/handlers [没有测试文件]
ok _/tmp/cnuss/server/stats 0.008s
路径的更改也反映在-coverprofile
输出文件中,这影响了我正在使用的一些覆盖工具。
所以问题是,是什么影响了执行go test
时解析的路径?在我的Mac Book上的行为是正确的。
英文:
thanks in advance for the help.
On my Mac, when I execute a go test ./...
the correct "path" is outputted in the output:
ok github.com/cnuss/server 0.008s
ok github.com/cnuss/server/database 0.008s
? github.com/cnuss/server/handlers [no test files]
ok github.com/cnuss/server/stats 0.014s
However, when I build in an Ubuntu 14.04 Trusty container, the path has been replaced by an "_" (underscore):
ok _/tmp/cnuss/server 0.003s
ok _/tmp/cnuss/server/database 0.003s
? _/tmp/cnuss/server/handlers [no test files]
ok _/tmp/cnuss/server/stats 0.008s
The change in the path is also reflected in the -coverprofile
output file, which in turns affects some of the coverage tools I'm using.
So question is, what affects the path that is resolved while executing go test
? The behavior on my Mac Book is the correct behavior.
答案1
得分: 3
你的Linux环境可能没有设置GOPATH
。
如果我在当前目录下创建一个名为src/foo/foo.go
的文件,内容为package foo
,我可以看到差异:
$ unset GOPATH
$ go test ./src/foo
? _/home/james/.../src/foo [没有测试文件]
$ export GOPATH=`pwd`
$ go test ./src/foo
? foo [没有测试文件]
如果没有设置GOPATH
(或者包在GOPATH
之外),它会像这是一个相对导入一样处理。
英文:
You probably don't have GOPATH
set in your Linux environment.
If I create a file src/foo/foo.go
in the current directory with the contents package foo
, I can see the difference:
$ unset GOPATH
$ go test ./src/foo
? _/home/james/.../src/foo [no test files]
$ export GOPATH=`pwd`
$ go test ./src/foo
? foo [no test files]
Without GOPATH
set (or with a package outside of GOPATH
), it is acting as if this is a relative import.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论