This is a fork of https://github.com/boumenot/gocover-cobertura.
At the time of this writing the repository appears to be on pause with several outstanding PRs, and open issues. The main motivator for creating this fork was to add the ability to pass build tags to the converter that were used when recording the coverage.
Additionally the following changes were made:
- allow passing build tags to converter (see
-tagsflag) - update the code base to a more recent version of go
- instead of forking an old version of
golang.org/x/tools/coverto parse the coverage profile, use the latest version of the package directly - reduce the number of dependencies used by the tool (3 vs 7)
- stricter linting of the codebase with
golangci-lint - increase test coverage
- small improvements to CLI (add help with
-h, allow for inputs/outputs other than stdin/stdout)
This is a simple helper tool for generating XML output in Cobertura format for CIs like Jenkins and others from go tool cover output.
Just type the following to install the program and its dependencies:
go install github.com/fasmat/gocover-cobertura@v1.0.0gocover-cobertura reads from the standard input:
go test -coverprofile=coverage.txt -covermode count github.com/gorilla/mux
gocover-cobertura < coverage.txt > coverage.xmlNote that you should run this from the directory which holds your go.mod file, so the tool can match the profile to
the source files.
Some flags can be passed (each flag should only be used once):
-
-hshow help
-
-f FILENAMEThe relative or absolute path to coverage file that should be converted (default: stdin)
-
-o FILENAMEThe relative or absolute path to output file for the cobertura report (default: stdout)
-
-by-filesCode coverage is organized by class by default. This flag organizes code coverage by the name of the file, which the same behavior as
go tool cover. -
-ignore-dirs PATTERNignore directories matching
PATTERNregular expression. Full directory names are matched, examples of use:# A specific directory -ignore-dirs '^github\.com/fasmat/gocover-cobertura/testdata$' # All directories called "autogen" and any of their sub-directories -ignore-dirs '/autogen$'
-
-ignore-files PATTERNignore files matching
PATTERNregular expression. Full file names are matched, examples of use:# A specific file -ignore-files '^github\.com/fasmat/gocover-cobertura/profile\.go$' # All files ending with _gen.go -ignore-files '_gen\.go$' # All files in a directory autogen (or any of its subdirs) -ignore-files '/autogen/'
-
-ignore-gen-filesignore generated files. Typically files containing a comment indicating that the file has been automatically generated. See
genCodeReregexp in ignore.go. -
-tagscomma-separated list of build tags to consider when looking for source files. This should match the build tags used when running
go test -coverprofile=....