Git Product home page Git Product logo

go-cover-view's Introduction

go-cover-view

ci codecov Go Report Card

simple go coverage report viewer

Install

go get github.com/johejo/go-cover-view
go install github.com/johejo/go-cover-view

Get Started

Create a new go module.

mkdir -p example
cd example/
go mod init example.com/example

Create a Go file.

example.go

package example

func example() bool {
	println("covered")
	if false {
		println("not covered")
	}
	return true
}

Create a Go test file.

example_test.go

package example

import "testing"

func Test_example(t *testing.T) {
	example()
}

Run test and generate coverage report.

go test . -cover -coverprofile coverage.txt

view coverage report.

go-cover-view
example.com/example/example.go
  1: package example
  2: 
O 3: func example() bool {
O 4: 	println("covered")
X 5: 	if false {
X 6: 		println("not covered")
X 7: 	}
O 8: 	return true
  9: }

json output

go-cover-view -output json
[
  {
    "fileName": "example.com/example/example.go",
    "coveredLines": [3, 4, 8], 
    "uncoveredLines": [5, 6, 7]
  }
]

markdown output

go-cover-view -output markdown
# Coverage Report


<details> <summary> example.com/example/example.go </summary>

\```
  1: package example
  2:
O 3: func example() bool {
O 4: 	println("covered")
X 5: 	if false {
X 6: 		println("not covered")
X 7: 	}
O 8: 	return true
  9: }
\```

</details>

GitHub Actions Integration

Pull Request comment with markdown report

Screenshot

GitHub Actions workflow example

name: ci
on:
  pull_request:
    branches:
      - master
jobs:
  test:
    strategy:
      matrix:
        os: [ubuntu-latest]
        go: ["1.14"]
    runs-on: ${{ matrix.os }}
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-go@v2
        with:
          go-version: ${{ matrix.go }}

      - name: "test"
        run: |
          go test -cover -coverprofile coverage.txt -race -v ./...

      - name: "pull request comment"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          git fetch origin master
          go get github.com/johejo/go-cover-view
          go install github.com/johejo/go-cover-view
          go-cover-view -ci github-actions -git-diff-base origin/master

Help

Usage of go-cover-view:
  -ci string
        ci type: available values "", "github-actions"
        github-actions:
                Comment the markdown report to Pull Request on GitHub.
  -covered string
        prefix for covered line (default "O")
  -git-diff-base string
        git diff base (default "origin/master")
  -git-diff-only
        only files with git diff
  -modfile string
        go.mod path
  -output string
        output type: available values "simple", "json", "markdown" (default "simple")
  -report string
        coverage report path (default "coverage.txt")
  -uncovered string
        prefix for uncovered line (default "X")

License

MIT

Author

Mitsuo Heijo (@johejo)

go-cover-view's People

Contributors

renovate-bot avatar johejo avatar

Stargazers

Michael A. King avatar Y. Meyer-Norwood avatar Tsuyoshi CHO avatar

Watchers

James Cloos avatar  avatar

go-cover-view's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v2
  • golangci/golangci-lint-action v2
  • actions/checkout v2
  • actions/setup-go v2
  • codecov/codecov-action v1
gomod
go.mod
  • go 1.14
  • github.com/google/go-github/v32 v32.1.0
  • github.com/stretchr/testify v1.7.1
  • golang.org/x/mod v0.5.1
  • golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8@d3ed0bb246c8

  • Check this box to trigger a request for Renovate to run again on this repository

[DepShield] (CVSS 5.9) Vulnerability due to usage of golang.org/x:crypto:0.0.0-20190308221718-c2843e01d9a2

Vulnerabilities

DepShield reports that this application's usage of golang.org/x:crypto:0.0.0-20190308221718-c2843e01d9a2 results in the following vulnerability(s):


Occurrences

golang.org/x:crypto:0.0.0-20190308221718-c2843e01d9a2 is a transitive dependency introduced by the following direct dependency(s):

golang.org/x:tools:0.0.0-20200604042327-9b20fe4cabe8
        └─ golang.org/x:mod:0.2.0
              └─ golang.org/x:crypto:0.0.0-20191011191535-87dc89f01550
                    └─ golang.org/x:net:0.0.0-20190404232315-eb5bcb51f2a3
                          └─ golang.org/x:crypto:0.0.0-20190308221718-c2843e01d9a2
              └─ golang.org/x:tools:0.0.0-20191119224855-298f0cb1881e
                    └─ golang.org/x:net:0.0.0-20190620200207-3b0461eec859
                          └─ golang.org/x:crypto:0.0.0-20190308221718-c2843e01d9a2
        └─ golang.org/x:net:0.0.0-20200226121028-0de0cce0169b
              └─ golang.org/x:crypto:0.0.0-20190308221718-c2843e01d9a2

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

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.