【问题标题】:Executing Go Tests Underscore (_) in place of correct path执行 Go 测试下划线 (_) 代替正确路径
【发布时间】:2015-07-27 22:05:10
【问题描述】:

提前感谢您的帮助。

在我的 Mac 上,当我执行 go test ./... 时,输出中会输出正确的“路径”:

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

但是,当我在 Ubuntu 14.04 Trusty 容器中构建时,路径已被替换为“_”(下划线):

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

路径的变化也反映在-coverprofile 输出文件中,进而影响我正在使用的一些覆盖工具。

所以问题是,是什么影响了在执行go test 时解析的路径?我的 Mac Book 上的行为是正确的行为。

【问题讨论】:

  • go on each 的版本是什么?

标签: unit-testing testing go


【解决方案1】:

您的 Linux 环境中可能没有设置 GOPATH

如果我在当前目录中创建一个文件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 之外的包),它的行为就好像这是一个相对导入。

【讨论】:

  • 就是这样,谢谢! GOPATH 在 Linux 环境中设置错误。
猜你喜欢
  • 2017-12-30
  • 2010-09-23
  • 2015-10-07
  • 1970-01-01
  • 2016-06-29
  • 1970-01-01
  • 2020-02-28
  • 2015-04-17
  • 1970-01-01
相关资源
最近更新 更多