Error when using go test in a Makefile

My makefile is as below:

PWD=$(shell pwd)
export GOPATH:=$(PWD)/third_party:$(PWD)

test:
    go test -cover sample

When in do the above steps manually it works perfectly and i get the expected output

coverage: 76.0% of statements
FAIL    sample 0.009s

But When I put this command in the form of make file as shown above i get below error.
make test

 coverage: 76.0% of statements
FAIL    sample    0.009s
make: *** [test] Error 1

Please help me in by providing pointers as why Makefile is throwing error.

Make throws and error because go test exits with a non-zero value indicating the tests did not pass.

To have make ignore the return value, prepend the command with -:

test:
	-go test -cover sample
2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.