Skip to content
This repository was archived by the owner on Nov 23, 2018. It is now read-only.

Commit 8ba5841

Browse files
authored
Merge pull request #190 from evertlammerts/master
Cleaned up coverage script and fixed travis.yml bug. See gonum/integrate#33.
2 parents e841ef6 + 93b2f4c commit 8ba5841

File tree

2 files changed

+31
-39
lines changed

2 files changed

+31
-39
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ script:
1919
- go get -d -t -v ./...
2020
- go build -v ./...
2121
- go test -v ./...
22-
- diff <(gofmt -d .) <("")
22+
- test -z "`gofmt -d .`"
2323
- if [[ $TRAVIS_SECURE_ENV_VARS = "true" ]]; then bash ./.travis/test-coverage.sh; fi

.travis/test-coverage.sh

+30-38
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,35 @@
11
#!/bin/bash
22

3-
# based on http://stackoverflow.com/questions/21126011/is-it-possible-to-post-coverage-for-multiple-packages-to-coveralls
4-
# with script found at https://github.com/gopns/gopns/blob/master/test-coverage.sh
3+
PROFILE_OUT=`pwd`/profile.out
4+
ACC_OUT=`pwd`/acc.out
55

6-
echo "mode: set" > acc.out
7-
returnval=`go test -v -coverprofile=profile.out`
8-
echo ${returnval}
9-
if [[ ${returnval} != *FAIL* ]]
10-
then
11-
if [ -f profile.out ]
12-
then
13-
cat profile.out | grep -v "mode: set" >> acc.out
14-
fi
15-
else
16-
exit 1
17-
fi
6+
testCover() {
7+
# set the return value to 0 (succesful)
8+
retval=0
9+
# get the directory to check from the parameter. Default to '.'
10+
d=${1:-.}
11+
# skip if there are no Go files here
12+
ls $d/*.go &> /dev/null || return $retval
13+
# switch to the directory to check
14+
pushd $d > /dev/null
15+
# create the coverage profile
16+
coverageresult=`go test -v -coverprofile=$PROFILE_OUT`
17+
# output the result so we can check the shell output
18+
echo ${coverageresult}
19+
# append the results to acc.out if coverage didn't fail, else set the retval to 1 (failed)
20+
( [[ ${coverageresult} == *FAIL* ]] && retval=1 ) || ( [ -f $PROFILE_OUT ] && grep -v "mode: set" $PROFILE_OUT >> $ACC_OUT )
21+
# return to our working dir
22+
popd > /dev/null
23+
# return our return value
24+
return $retval
25+
}
1826

19-
for Dir in $(find ./* -maxdepth 10 -type d );
20-
do
21-
if ls $Dir/*.go &> /dev/null;
22-
then
23-
echo $Dir
24-
returnval=`go test -v -coverprofile=profile.out $Dir`
25-
echo ${returnval}
26-
if [[ ${returnval} != *FAIL* ]]
27-
then
28-
if [ -f profile.out ]
29-
then
30-
cat profile.out | grep -v "mode: set" >> acc.out
31-
fi
32-
else
33-
exit 1
34-
fi
35-
fi
36-
done
37-
if [ -n "$COVERALLS_TOKEN" ]
38-
then
39-
$HOME/gopath/bin/goveralls -coverprofile=acc.out -service=travis-ci -repotoken $COVERALLS_TOKEN
40-
fi
27+
# Init acc.out
28+
echo "mode: set" > $ACC_OUT
29+
30+
# Run test coverage on all directories containing go files
31+
find . -maxdepth 10 -type d | while read d; do testCover $d || exit; done
32+
33+
# Upload the coverage profile to coveralls.io
34+
[ -n "$COVERALLS_TOKEN" ] && goveralls -coverprofile=$ACC_OUT -service=travis-ci -repotoken $COVERALLS_TOKEN
4135

42-
rm -rf ./profile.out
43-
rm -rf ./acc.out

0 commit comments

Comments
 (0)