英文:
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 'no test files' </tmp/fifo-$$ & go test ./... >/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 'no test files'; true; }
# reset pipefail with set +o pipefail if you want to swith it off again
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论