Allow tests to run with non-interactive shells

/dev/tty isn't available when running under Jenkins, so certain tricks
with 'tee' don't work.  Work around this with temporary variables and
files.

also, changes how tool executables are verified as well as does not
require the caller to have GOPATH/bin in their PATH

Change-Id: I2df8dfcb016d5e5dea924d750b0d6e35419e8367
diff --git a/Makefile b/Makefile
index be79cbd..ae04c2f 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@
 # limitations under the License.
 #
 
-SHELL=/bin/bash -o pipefail
+SHELL=/bin/bash -e -o pipefail
 
 ifeq ($(TAG),)
 TAG := latest
@@ -124,13 +124,14 @@
 	docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-adapter-simulated-onu:${TAG} -f docker/Dockerfile.simulated_onu .
 
 lint-style:
-	hash gofmt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
-	  go get -u github.com/golang/go/src/cmd/gofmt; \
-	fi
-
-	if [[ "$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*') | tee /dev/tty)" ]]; then \
-	  echo "Lint failed on one or more files ^; run 'go fmt' to fix."; \
-	  exit 1; \
+ifeq (,$(shell which gofmt))
+	  go get -u github.com/golang/go/src/cmd/gofmt;
+endif
+	gofmt_out="$$(gofmt -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\
+	if [ ! -z "$$gofmt_out" ]; then \
+	  echo "$$gofmt_out" ;\
+	  echo "Lint failed on one or more files ^; run 'go fmt' to fix." ;\
+	  exit 1 ;\
 	fi
 
 lint-sanity:
@@ -141,17 +142,25 @@
 
 lint: lint-style lint-sanity lint-dep
 
+GO_JUNIT_REPORT:=$(shell which go-junit-report)
+GOCOVER_COBERTURA:=$(shell which gocover-cobertura)
 test:
-	hash go-junit-report > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
-	  go get -u github.com/jstemmer/go-junit-report; \
-	fi
-	hash gocover-cobertura > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
-	  go get -u github.com/t-yuki/gocover-cobertura; \
-	fi
+ifeq (,$(GO_JUNIT_REPORT))
+	go get -u github.com/jstemmer/go-junit-report
+	GO_JUNIT_REPORT=$(GOPATH)/bin/go-junit-report
+endif
+
+ifeq (,$(GOCOVER_COBERTURA))
+	go get -u github.com/t-yuki/gocover-cobertura
+	GOCOVER_COBERTURA=$(GOPATH)/bin/gocover-cobertura
+endif
 
 	mkdir -p ./tests/results
-	go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee /dev/tty | go-junit-report > ./tests/results/go-test-results.xml; \
-	RETURN=$$?; \
-	gocover-cobertura < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml && exit $$RETURN
+
+	go test -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\
+	RETURN=$$? ;\
+	$(GO_JUNIT_REPORT) < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
+	$(GOCOVER_COBERTURA) < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
+	exit $$RETURN
 
 # end file