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?
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.
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 .
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.
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.
Something like this?
mkfifo /tmp/fifo-$$
grep -v 'no test files' </tmp/fifo-$$ & go test ./... >/tmp/fifo-$$
RES=$?
rm /tmp/fifo-$$
exit $RES
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With