gocover-cobertura

command module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 20 Imported by: 0

README

gocover-cobertura

Build Status codecov Go Report Card Go Reference License Latest Release

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 -tags flag)
  • update the code base to a more recent version of go
  • instead of forking an old version of golang.org/x/tools/cover to 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.

Installation

Just type the following to install the program and its dependencies:

go install github.com/fasmat/[email protected]

Usage

gocover-cobertura reads from the standard input:

go test -coverprofile=coverage.txt -covermode count github.com/gorilla/mux
gocover-cobertura < coverage.txt > coverage.xml

Note 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):

  • -h

    show help

  • -f FILENAME

    The relative or absolute path to coverage file that should be converted (default: stdin)

  • -o FILENAME

    The relative or absolute path to output file for the cobertura report (default: stdout)

  • -by-files

    Code 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 PATTERN

    ignore directories matching PATTERN regular 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 PATTERN

    ignore files matching PATTERN regular 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-files

    ignore generated files. Typically files containing a comment indicating that the file has been automatically generated. See genCodeRe regexp in ignore.go.

  • -tags

    comma-separated list of build tags to consider when looking for source files. This should match the build tags used when running go test -coverprofile=....

Documentation

Overview

gocover-cobertura converts Go code coverage profiles to Cobertura XML format.

It reads from standard input and writes to standard output. It can be used to generate code coverage reports compatible with tools that expect Cobertura format, such as SonarQube or Jenkins.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL