打印测试包的名称在它们被编译时

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

Print the names of test packages as they are compiled

问题

运行go buildgo install时使用-v选项会“在编译过程中打印包的名称”。当我运行go test时,如何获得相同的效果?-v选项在这里表示输出测试信息。在对某些包运行测试时,由于某些依赖项的长时间编译,测试可能会意外地花费很长时间。我希望能够看到这个过程的一些信息。

我能想到的最好的选择是尝试类似于go build -v ./...的命令,但我不知道这是否会包括构建测试的依赖项,并且这是一个单独的步骤。

英文:

Running go build or go install with -v will "print the names of packages as they are compiled". How do I get the same when I run go test? -v there means to output test information. When running tests on some packages, they can unexpectedly take a long time, due to long compiles for some dependencies. I'd like some visibility in to that process.

The best option I can think of is to try something like go build -v ./..., but I don't know if that will include building the dependencies of tests, and it's a separate step.

答案1

得分: 0

使用go build不可行:

> 在编译包时,build会忽略以'_test.go'结尾的文件。

test命令没有打印包名的标志。-v的含义与build不同。

一个绕过的解决方案是使用调试标志-x并将输出导入到grep中。-x的输出很难处理,因为它是调试信息,不适合在实际命令管道中使用。

go test -x ./... 2>&1 | grep -E "^cd"

cd开头的行包含正在编译的包,因为它会进入这些包。

这包括这些测试的依赖关系以及测试包与工作目录.之间的来回切换。这不是一个完美的解决方案,但至少是个办法。

英文:

Using go build is not viable:

> When compiling packages, build ignores files that end in '_test.go'.

The test command doesn't have the flag to print package names. -v has a different meaning than build.

A roundabout solution is to use the debug flag -x and pipe the output to grep. The output of -x is unwieldy, because it's debug and it's not meant to be used in actual command pipelines.

go test -x ./... 2>&1 | grep -E "^cd"

The lines that start with cd are those containing the packages that are being compiled, as it cd's into them.

This includes the dependencies of those tests and back and forth between test packages and the working dir .. Not a perfect solution, but it's something.

huangapple
  • 本文由 发表于 2021年8月13日 10:56:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/68766239.html
匿名

发表评论

匿名网友

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

确定