From aa03e53ca8d55e74e562f5f56d90e4fd2579fb4e Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 29 Apr 2015 01:27:47 +0200 Subject: [PATCH] Use Makefile for Travis tests --- .gitignore | 4 ++++ .travis.yml | 7 +++---- Makefile | 5 ++++- build/test-global-coverage.sh | 26 ++++++++++++++++++++++++++ gocoverage.sh | 31 ------------------------------- 5 files changed, 37 insertions(+), 36 deletions(-) create mode 100755 build/test-global-coverage.sh delete mode 100755 gocoverage.sh diff --git a/.gitignore b/.gitignore index a90cb225b..241c26a55 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,7 @@ deploy/osx/Mist\ Installer.dmg /build/_workspace/ /build/bin/ +# travis +profile.tmp +profile.cov + diff --git a/.travis.yml b/.travis.yml index d6954e0cb..b0f295fb6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,13 +4,12 @@ go: before_install: - sudo add-apt-repository ppa:beineri/opt-qt541 -y - sudo apt-get update -qq - - sudo apt-get install -yqq libgmp3-dev libreadline6-dev qt54quickcontrols qt54webengine + - sudo apt-get install -yqq libgmp3-dev qt54quickcontrols qt54webengine install: # - go get code.google.com/p/go.tools/cmd/goimports # - go get github.com/golang/lint/golint # - go get golang.org/x/tools/cmd/vet - - go get golang.org/x/tools/cmd/cover - - go get github.com/mattn/goveralls + - go get golang.org/x/tools/cmd/cover github.com/mattn/goveralls before_script: # - gofmt -l -w . # - goimports -l -w . @@ -18,7 +17,7 @@ before_script: # - go vet ./... # - go test -race ./... script: - - ./gocoverage.sh + - make travis-test-with-coverage after_success: - if [ "$COVERALLS_TOKEN" ]; then goveralls -coverprofile=profile.cov -service=travis-ci -repotoken $COVERALLS_TOKEN; fi env: diff --git a/Makefile b/Makefile index 917e7f4ac..03e3bf4c6 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # with Go source code. If you know what GOPATH is then you probably # don't need to bother with make. -.PHONY: geth mist test clean +.PHONY: geth mist all test travis-test-with-coverage clean GOBIN = build/bin geth: @@ -21,5 +21,8 @@ all: test: all build/env.sh go test ./... +travis-test-with-coverage: all + build/env.sh build/test-global-coverage.sh + clean: rm -fr build/_workspace/pkg/ Godeps/_workspace/pkg $(GOBIN)/* diff --git a/build/test-global-coverage.sh b/build/test-global-coverage.sh new file mode 100755 index 000000000..417c829f4 --- /dev/null +++ b/build/test-global-coverage.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# This script runs all package tests and merges the resulting coverage +# profiles. Coverage is accounted per package under test. + +set -e + +if [ ! -f "build/env.sh" ]; then + echo "$0 must be run from the root of the repository." + exit 2 +fi + +echo "mode: count" > profile.cov + +for pkg in $(go list ./...); do + # drop the namespace prefix. + dir=${pkg##github.com/ethereum/go-ethereum/} + + if [[ $dir != "tests/vm" ]]; then + go test -covermode=count -coverprofile=$dir/profile.tmp $pkg + fi + if [[ -f $dir/profile.tmp ]]; then + tail -n +2 $dir/profile.tmp >> profile.cov + rm $dir/profile.tmp + fi +done diff --git a/gocoverage.sh b/gocoverage.sh deleted file mode 100755 index 5479d8d3b..000000000 --- a/gocoverage.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -set -e - -# Add godep workspace to GOPATH. We do it manually instead of using -# 'godep go test' or 'godep restore' so godep doesn't need to be installed. -GOPATH="$PWD/Godeps/_workspace:$GOPATH" - -# Install packages before testing. Not doing this would cause -# 'go test' to recompile all package dependencies before testing each package. -go install ./... - -# Run test coverage on each subdirectories and merge the coverage profile. -echo "mode: count" > profile.cov - -# Standard go tooling behavior is to ignore dirs with leading underscors -for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -type d); -do -if ls $dir/*.go &> /dev/null; then - # echo $dir - if [[ $dir != "./tests/vm" && $dir != "." ]] - then - go test -covermode=count -coverprofile=$dir/profile.tmp $dir - fi - if [ -f $dir/profile.tmp ] - then - cat $dir/profile.tmp | tail -n +2 >> profile.cov - rm $dir/profile.tmp - fi -fi -done