diff --git a/Dockerfile b/Dockerfile index cc5a19276f..b06c6553e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -65,6 +65,9 @@ RUN git clone https://git.fedorahosted.org/git/lvm2.git /usr/local/lvm2 && cd /u RUN cd /usr/local/lvm2 && ./configure --enable-static_link && make device-mapper && make install_device-mapper # see https://git.fedorahosted.org/cgit/lvm2.git/tree/INSTALL +# Grab Go's cover tool for dead-simple code coverage testing +RUN go get code.google.com/p/go.tools/cmd/cover + VOLUME /var/lib/docker WORKDIR /go/src/github.com/dotcloud/docker diff --git a/hack/make.sh b/hack/make.sh index 7b39f3161c..91f641af89 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -39,6 +39,7 @@ DEFAULT_BUNDLES=( dynbinary dyntest dyntest-integration + cover tgz ubuntu ) @@ -64,6 +65,11 @@ LDFLAGS='-X main.GITCOMMIT "'$GITCOMMIT'" -X main.VERSION "'$VERSION'" -w' LDFLAGS_STATIC='-X github.com/dotcloud/docker/utils.IAMSTATIC true -linkmode external -extldflags "-lpthread -static -Wl,--unresolved-symbols=ignore-in-object-files"' BUILDFLAGS='-tags netgo' +HAVE_GO_TEST_COVER= +if go help testflag | grep -q -- -cover; then + HAVE_GO_TEST_COVER=1 +fi + # If $TESTFLAGS is set in the environment, it is passed as extra arguments to 'go test'. # You can use this to select certain tests to run, eg. # @@ -71,6 +77,14 @@ BUILDFLAGS='-tags netgo' # go_test_dir() { dir=$1 + testcover=() + if [ "$HAVE_GO_TEST_COVER" ]; then + # if our current go install has -cover, we want to use it :) + mkdir -p "$DEST/coverprofiles" + coverprofile="docker${dir#.}" + coverprofile="$DEST/coverprofiles/${coverprofile//\//-}" + testcover=( -cover -coverprofile "$coverprofile" ) + fi ( # we run "go test -i" ouside the "set -x" to provde cleaner output cd "$dir" go test -i -ldflags "$LDFLAGS" $BUILDFLAGS @@ -78,7 +92,7 @@ go_test_dir() { ( set -x cd "$dir" - go test -ldflags "$LDFLAGS" $BUILDFLAGS $TESTFLAGS + go test ${testcover[@]} -ldflags "$LDFLAGS" $BUILDFLAGS $TESTFLAGS ) } diff --git a/hack/make/cover b/hack/make/cover new file mode 100644 index 0000000000..6dc71d1c7e --- /dev/null +++ b/hack/make/cover @@ -0,0 +1,21 @@ +#!/bin/bash + +DEST="$1" + +bundle_cover() { + coverprofiles=( "$DEST/../"*"/coverprofiles/"* ) + for p in "${coverprofiles[@]}"; do + echo + ( + set -x + go tool cover -func="$p" + ) + done +} + +if [ "$HAVE_GO_TEST_COVER" ]; then + bundle_cover 2>&1 | tee "$DEST/report.log" +else + echo >&2 'warning: the current version of go does not support -cover' + echo >&2 ' skipping test coverage report' +fi