From 32543614e32df1643e43fd1445dc7090ea4972a7 Mon Sep 17 00:00:00 2001 From: Trevor Rosen Date: Sat, 4 Nov 2017 18:48:11 -0500 Subject: [PATCH] Fail build if any tests fail Fixes #464 * Move CI testing into ci/test.sh * Delegate to script in Makefile --- Makefile | 11 ++--------- ci/test.sh | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) create mode 100755 ci/test.sh diff --git a/Makefile b/Makefile index 115fa4c6..285f6ef6 100644 --- a/Makefile +++ b/Makefile @@ -12,18 +12,11 @@ race: # Check for code well-formedness fmt_check: - gofmt -s -d . | read + ! gofmt -s -d . | read # Test and generate coverage test_with_coverage: - echo "" > profile.cov - for package in $(excluding_vendor) ; do \ - go test -covermode=count -coverprofile=tmp.cov $$package ; \ - if [ -f tmp.cov ]; then \ - cat tmp.cov >> profile.cov ; \ - rm tmp.cov ; \ - fi ; \ - done + ./ci/test.sh deps: ifeq (,$(shell which dep)) diff --git a/ci/test.sh b/ci/test.sh new file mode 100755 index 00000000..9cb815f0 --- /dev/null +++ b/ci/test.sh @@ -0,0 +1,38 @@ +#!/bin/bash +set -euo pipefail + +# Print commands as executed +#set -x + + +# Hold the package names that contain failures +fail_packages=() + +pushd $PWD/.. + # Set up coverage report file + COVERAGE_REPORT_LOCATION="./profile.cov" + echo "" > $COVERAGE_REPORT_LOCATION + + # Exclude vendor in the same way as Makefile does + EXCLUDING_VENDOR=$(go list ./... | grep -v /vendor/) + + # Iterate over all non-vendor packages and run tests with coverage + for package in $EXCLUDING_VENDOR; do \ + result=$(go test -covermode=count -coverprofile=tmp.cov $package) + echo $result + + # If a `go test` command has failures, it will exit 1 + if [ $? -ne 0 ]; then + fail_packages+=($package); + fi; + if [ -f tmp.cov ]; then + cat tmp.cov >> profile.cov; + rm tmp.cov; + fi; + done + + # exit 1 if there have been any test failures + if [ ${#fails[@]} -ne 0 ]; then + exit 1 + fi; +popd