Skip to content

Instantly share code, notes, and snippets.

@rjeczalik
Last active March 31, 2019 20:16
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save rjeczalik/6f01430e8554bf59b88e to your computer and use it in GitHub Desktop.
Save rjeczalik/6f01430e8554bf59b88e to your computer and use it in GitHub Desktop.
Go, multiple packages and coveralls.io

Go, multiple packages and coveralls.io

Single profile for single Go package

For Go projects that consist of only one package, the following Travis configuration is enough to get started with coveralls.io. You may want to encrypt your $COVERALLS_TOKEN via Travis encryption keys though.

language: go
go:
  - 1.3.1

env:
  global:
    - PATH=$HOME/gopath/bin:$PATH

install:
  - go get code.google.com/p/go.tools/cmd/cover github.com/mattn/goveralls github.com/modocache/gover

script:
  - go test -coverprofile=.coverprofile .
  - goveralls -coverprofile=.coverprofile -service=travis-ci -repotoken $COVERALLS_TOKEN

Single profile for multiple Go packages

As of now (version 1.3.1) go tool does not support creating combined coverage profiles for multiple packages. A workaround may be to run go test separately for each package and combine the profiles into one; in order to achieve that go list can be used for globing test packages and creating the test command strings and gover command for concatenating the profiles.

language: go
go:
  - 1.3.1

env:
  global:
    - PATH=$HOME/gopath/bin:$PATH

install:
  - go get code.google.com/p/go.tools/cmd/cover github.com/mattn/goveralls github.com/modocache/gover

script:
  - go list -f '{{if len .TestGoFiles}}"go test -coverprofile={{.Dir}}/.coverprofile {{.ImportPath}}"{{end}}' ./... | xargs sh -c
  - gover
  - goveralls -coverprofile=gover.coverprofile -service=travis-ci -repotoken $COVERALLS_TOKEN
@drewwells
Copy link

Great use of go list. The multi-package command didn't work for me. xargs treats it as one big string. To split the string on the newline, I used:

go list -f '{{if len .TestGoFiles}}"go test -coverprofile={{.Dir}}/.coverprofile {{.ImportPath}}"{{end}}' ./... | xargs -L 1 sh -c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment