Skip to content

travis: add testing #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
sudo: false

language: go

# Do not move these lines; they are referred to by README.md.
# Versions of go that are explicitly supported by gonum plus go tip.
go:
- 1.8.x
- 1.9.x
- 1.10.x
- master

matrix:
fast_finish: true
allow_failures:
- go: master

before_install:
# Required for format check.
- go get golang.org/x/tools/cmd/goimports
# Required for coverage.
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls

go_import_path: gonum.org/v1/tools

# Get deps, build, test, and ensure the code is gofmt'ed.
# If we are building as gonum, then we have access to the coveralls api key, so we can run coverage as well.
script:
- ${TRAVIS_BUILD_DIR}/.travis/check-formatting.sh
- go get -d -t -v ./...
- go build -v ./...
- if [[ $TRAVIS_SECURE_ENV_VARS = "true" ]]; then bash ./.travis/test-coverage.sh; fi
- ${TRAVIS_BUILD_DIR}/.travis/check-imports.sh
# This is run last since it alters the tree.
- ${TRAVIS_BUILD_DIR}/.travis/check-generate.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not needed ATM.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this one here though.


8 changes: 8 additions & 0 deletions .travis/check-formatting.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

test -z "$(goimports -d .)"
if [[ -n "$(gofmt -s -l .)" ]]; then
echo -e '\e[31mCode not gofmt simplified in:\n\n'
gofmt -s -l .
echo -e "\e[0"
fi
9 changes: 9 additions & 0 deletions .travis/check-generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# Add any go generate invocations below this line.


if [ -n "$(git diff)" ]; then
git diff
exit 1
fi
4 changes: 4 additions & 0 deletions .travis/check-imports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

set -e
check-imports -b "math/rand,github.com/gonum/.*"
34 changes: 34 additions & 0 deletions .travis/test-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually something that could be rewritten in Go and put as a standalone command in gonum/tools :)
(this script is using many UNIX commands...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File an issue for that? It can live here and be used Gonum-wide.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done: #5


PROFILE_OUT=$PWD/profile.out
ACC_OUT=$PWD/acc.out

testCover() {
# set the return value to 0 (succesful)
retval=0
# get the directory to check from the parameter. Default to '.'
d=${1:-.}
# skip if there are no Go files here
ls $d/*.go &> /dev/null || return $retval
# switch to the directory to check
pushd $d > /dev/null
# create the coverage profile
coverageresult=`go test -v $TAGS -coverprofile=$PROFILE_OUT`
# output the result so we can check the shell output
echo ${coverageresult}
# append the results to acc.out if coverage didn't fail, else set the retval to 1 (failed)
( [[ ${coverageresult} == *FAIL* ]] && retval=1 ) || ( [ -f $PROFILE_OUT ] && grep -v "mode: set" $PROFILE_OUT >> $ACC_OUT )
# return to our working dir
popd > /dev/null
# return our return value
return $retval
}

# Init acc.out
echo "mode: set" > $ACC_OUT

# Run test coverage on all directories containing go files.
find . -type d | while read d; do testCover $d || exit; done

# Upload the coverage profile to coveralls.io
[ -n "$COVERALLS_TOKEN" ] && goveralls -coverprofile=$ACC_OUT -service=travis-ci -repotoken $COVERALLS_TOKEN
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -9,6 +9,10 @@ Installation is done using `go get`.
go get -u gonum.org/v1/tools/...
```

## Supported Go versions

Gonum supports and tests on the [three most recent major versions of Go](https://github.com/gonum/tools/blob/master/.travis.yml#L6-L11).

## Issues

If you find any bugs, feel free to file an issue on the github issue tracker. Discussions on API changes, added features, code review, or similar requests are preferred on the gonum-dev Google Group.