Coder Social home page Coder Social logo

covermate's Introduction

Build Status

Covermate

Covermate is a tool to assist with managing code-coverage metrics. Go provides builtin tools for assessing code test-coverage. Covermate extends the capabilities of the Go test-coverage report by allowing coverage-omissions to be flagged, or tagged as exclusions. This allows untested code to be tracked and managed.

Covermate can be integrated into a CI pipeline to verify that untested blocks of code are specifically excluded, and also that the overall coverage meets a specified threshold.

Covermate will exit with non-zero if:

  • There is a block of code which is not tested and does not have a // nocover comment.
  • The overall code coverage does not meet a specified threshold.

Note: As per -coverprofile, packages with no tests are ignored.

Note: As per -coverprofile, coverage is package-specific. i.e. code is only considered covered, if it is called from a test within the same package.

Installion

go install github.com/digio/covermate

Usage

usage: covermate [<flags>]

Flags:
      --help                     Show context-sensitive help (also try --help-long and --help-man).
  -f, --filename="coverage.out"  coverage report from go test
  -t, --tag="nocover"            comment tag to exclude blocks from mandatory coverage
  -T, --threshold=-1             minimum required overall coverage

Covermate depends on the coverage report generated by go test with the -coverprofile option.

To execute the commands together:

go test ./... -coverprofile=coverage.out && covermate

By default covermate will not assess the overall level of code coverage. A threshold can be set by providing a value between 0 and 100 with the -T option. If a theshold is set, and the total coverage is below the specified level, covermate will exit with an error.

Example

If a block of code has no test coverage, it must include a specific tag in the comments (nocover by default), or it will generate an error.

    // Depending on the nature of `data`, it may not be possible to make `json.Marshal()` return an error.
    data, err := createData()
    if err != nil {
        return err // if this block is not tested, covermate will exit with error
    }
    b, err := json.Marshal(data)
    if err != nil {
        return err // nocover - this block is tagged as being excluded from mandatory code coverage
    }

covermate's People

Contributors

aopat avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.