diff --git a/.gitignore b/.gitignore index 4a65c2279c..09d363d1ce 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ /build/ cli/winresources/rsrc_386.syso cli/winresources/rsrc_amd64.syso +coverage.txt +profile.out diff --git a/Makefile b/Makefile index 566da5a636..b9180d4e02 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,11 @@ clean: # the "-tags daemon" part is temporary .PHONY: test test: - go test -tags daemon -v $(shell go list ./... | grep -v /vendor/) + ./scripts/test/unit $(shell go list ./... | grep -v /vendor/) + +.PHONY: test-coverage +test-coverage: + ./scripts/test/unit-with-coverage .PHONY: lint lint: diff --git a/circle.yml b/circle.yml index e791bb93bf..dabc4c5aad 100644 --- a/circle.yml +++ b/circle.yml @@ -29,13 +29,16 @@ jobs: docker run --name cross cli-builder make cross docker cp cross:/go/src/github.com/docker/cli/build /work/build - run: - name: "Unit Test" + name: "Unit Test with Coverage" command: | if [ "$CIRCLE_NODE_INDEX" != "2" ]; then exit; fi dockerfile=dockerfiles/Dockerfile.dev echo "COPY . ." >> $dockerfile docker build -f $dockerfile --tag cli-builder . - docker run cli-builder make test + docker run --name test cli-builder make test-coverage + docker cp test:/go/src/github.com/docker/cli/coverage.txt coverage.txt + apk add -U bash curl + curl -s https://codecov.io/bash | bash - run: name: "Validate Vendor and Code Generation" command: | diff --git a/scripts/test/unit b/scripts/test/unit new file mode 100755 index 0000000000..8c2f9c75df --- /dev/null +++ b/scripts/test/unit @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -eu -o pipefail + +go test -tags daemon -v $@ diff --git a/scripts/test/unit-with-coverage b/scripts/test/unit-with-coverage new file mode 100755 index 0000000000..9073e2daf6 --- /dev/null +++ b/scripts/test/unit-with-coverage @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -eu -o pipefail + +for pkg in $(go list ./... | grep -v /vendor/); do + ./scripts/test/unit \ + -cover \ + -coverprofile=profile.out \ + -covermode=atomic \ + ${pkg} + + if test -f profile.out; then + cat profile.out >> coverage.txt + rm profile.out + fi +done