执行Go测试时,将下划线(_)替换为正确的路径。

huangapple go评论94阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2015年7月28日 06:05:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/31664129.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定