go-cover-view

command module
v0.0.0-...-d0a2ff7 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 20 Imported by: 0

README

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)

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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