go2jenkins

command module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

README

go2jenkins

Create Jenkins coverage files for golang Create coverage files for golang that the Jenkins coverage plugin can read and display. Including complexity metrics and branch coverage.

Installation

Simple install it by go install:

go install https://github.com/Fabianexe/go2jenkins@latest

Usage

go2jenkins can be run without any arguments. Howver, this means that it will for sources in the current directory, do not add coverage data and write a coverage.xml in the current directory.

So some flags exists to change this behavior:

Flags
  • -h or --help to get a help message
  • -s or --source to specify the source directory
  • -c or --coverage to specify the coverage profile as written by go test -coverprofile
  • -o or --output to specify the output file
  • -v or --verbose to get more output. Can be used multiple times to increase the verbosity

Beside these flags, the following flags can be used to change the behavior of the coverage report:

  • --cyclomatic to use cyclomatic complexity metrics (default is cognitive complexity)
  • --generatedFiles to include generated files in the coverage report
  • --noneCodeLines to include none code lines in the coverage report
  • --errorIf to include error ifs in the coverage report
Example
go2jenkins -s ./src -c ./coverage.out -o ./coverage.xml

This will create a coverage report for the sources in the ./src directory, using the coverage profile ./coverage.out and write the report to ./coverage.xml.

The accuracy of go test -coverprofile

The go test -coverprofile command is a great tool to get coverage information about your project. However, it measures the coverage on a bock level. This means that if you function conatins empty lines, only comments, or lines with only a closing bracket, they will be counted in line metrics.

This project tries to solve this problem by using the go/ast package to determine the actual lines of code from the source.

Another result from this is that branches on a line level can be determined. If a line contains an if statement, with multiple conditions, it is still one block for the coverage profile. There are projects that try to solve this problem for example gobco. However, they for the moment not compatible with the Jenkins coverage plugin. Thus, we add branch coverage on method and file level. Where such multi condition statements are counted as one branche.

Others

So far we are aware about two other projects that do something similar:

However, both of them focus on the coverage part and take over a big downsides of the go test -coverprofile command. Only packages with any coverage are included in the report (will be fixed in go). This means that if you have a package with no tests at all, it will not be included in the report. This is a big problem if you want to have a complete report of your project or any meaningfully coverage metrics.

Further this project is more about the Jenkins integration. So it is more than just a coverage tool. It adds complexity metrics, more options to determine coverage, and branch coverage.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg
cleaner
Package cleaner cleans the coverage data and discard lines, classes and packages that are not relevant
Package cleaner cleans the coverage data and discard lines, classes and packages that are not relevant
commands
Package commands contains all cobra commands that are used from the main
Package commands contains all cobra commands that are used from the main
complexity
Package complexity enriches the enties with complexity metrics
Package complexity enriches the enties with complexity metrics
coverage
Package coverage loads a golang coverage report and enrich the entities with the information
Package coverage loads a golang coverage report and enrich the entities with the information
entity
Package entity contains all entities that are used in every component of the application
Package entity contains all entities that are used in every component of the application
source
Package source reads source files from a given path and create entities from this
Package source reads source files from a given path and create entities from this
writer
Package writer writes xml file based on the cobertura dtd: https://github.com/cobertura/cobertura/blob/master/cobertura/src/test/resources/dtds/coverage-04.dtd
Package writer writes xml file based on the cobertura dtd: https://github.com/cobertura/cobertura/blob/master/cobertura/src/test/resources/dtds/coverage-04.dtd

Jump to

Keyboard shortcuts

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