Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

testing

go

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?

like image 396
Vitor De Mario Avatar asked Apr 15 '14 17:04

Vitor De Mario


People also ask

How do I ignore generated files from Go test coverage?

By using "_test" in the name definitions If you would like to ignore files which are used in the tests then make sense use _test at the end of the name. For example, my_service_mock_test.go . The files with _test at the end of the name will be ignored by default.

Where do I put test files in go?

The convention for naming test files in Go is to end the file name with the _test.go suffix and place the file in the same directory as the code it tests. In the example above, the Multiply function is in integers.go , so its tests are placed in integers_test.go .

What does T helper do Golang?

Note: The t. Helper() function indicates to the Go test runner that our Equal() function is a test helper. This means that when t. Errorf() is called from our Equal() function, the Go test runner will report the filename and line number of the code which called our Equal() function in the output.

Which command is used to run the tests in go?

Running subtests in Go The t. Run() command takes two arguments — the first matches against parameters passed to go test , and the second is the name of a test function.


2 Answers

Something like this?

mkfifo /tmp/fifo-$$

grep -v 'no test files' </tmp/fifo-$$ & go test ./... >/tmp/fifo-$$
RES=$?
rm /tmp/fifo-$$
exit $RES
like image 109
fuz Avatar answered Nov 04 '22 19:11

fuz


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
like image 40
yaccob Avatar answered Nov 04 '22 19:11

yaccob