英文:
Print the names of test packages as they are compiled
问题
运行go build
或go 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论