如何在go test中抑制“[no test files]”消息

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

How to suppress [no test files] message on go test

问题

我正在项目的根目录下运行go test ./...命令,但是有几个包没有任何测试,并报告[no test files]。如果我运行go test ./... | grep -v 'no test files'命令,如果测试失败,我将失去go test的返回代码。

在递归测试项目的根目录下的所有内容时,我可以忽略没有测试的包吗?

英文:

I'm running go test ./... in the root of my project but several packages don't have any tests and report [no test files]. If I run go test ./... | grep -v 'no test files' I lose the return code from go test in case a test fails.

Can I ignore packages with no tests while recursively testing everything from the root of the project?

答案1

得分: 2

像这样吗?

mkfifo /tmp/fifo-$$

grep -v 'no test files' </tmp/fifo-$$ & go test ./... >/tmp/fifo-$$
RES=$?
rm /tmp/fifo-$$
exit $RES
英文:

Something like this?

mkfifo /tmp/fifo-$$

grep -v &#39;no test files&#39; &lt;/tmp/fifo-$$ &amp; go test ./... &gt;/tmp/fifo-$$
RES=$?
rm /tmp/fifo-$$
exit $RES

答案2

得分: 2

一个相对紧凑的解决方案可能如下所示:

set -o pipefail
go test ./... | { grep -v 'no test files'; true; }
# 如果你想要关闭 pipefail,可以使用 set +o pipefail
英文:

A relatively compact solution could look like this:

set -o pipefail
go test ./... | { grep -v &#39;no test files&#39;; true; }
# reset pipefail with set +o pipefail if you want to swith it off again

huangapple
  • 本文由 发表于 2014年4月16日 01:27:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/23090540.html
匿名

发表评论

匿名网友

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

确定