Vitor De Mario
Vitor De Mario

Reputation: 1179

How to suppress [no test files] message on 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?

Upvotes: 16

Views: 7052

Answers (2)

yaccob
yaccob

Reputation: 1353

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

Upvotes: 2

fuz
fuz

Reputation: 93127

Something like this?

mkfifo /tmp/fifo-$$

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

Upvotes: 2

Related Questions