github.com/saurabh-prakash/go-cover-view@v0.0.1/README.md (about)

     1  # go-cover-view
     2  
     3  
     4  [![ci](https://github.com/saurabh-prakash/go-cover-view/workflows/ci/badge.svg?branch=master)](https://github.com/saurabh-prakash/go-cover-view/actions?query=workflow%3Aci)
     5  [![codecov](https://codecov.io/gh/johejo/go-cover-view/branch/master/graph/badge.svg)](https://codecov.io/gh/johejo/go-cover-view)
     6  [![Go Report Card](https://goreportcard.com/badge/github.com/saurabh-prakash/go-cover-view)](https://goreportcard.com/report/github.com/saurabh-prakash/go-cover-view)
     7  
     8  simple go coverage report viewer
     9  
    10  ## Install
    11  
    12  ```
    13  go get github.com/saurabh-prakash/go-cover-view
    14  go install github.com/saurabh-prakash/go-cover-view
    15  ```
    16  
    17  ## Get Started
    18  
    19  Create a new go module.
    20  ```sh
    21  mkdir -p example
    22  cd example/
    23  go mod init example.com/example
    24  ```
    25  
    26  Create a Go file.
    27  
    28  example.go
    29  ```go
    30  package example
    31  
    32  func example() bool {
    33  	println("covered")
    34  	if false {
    35  		println("not covered")
    36  	}
    37  	return true
    38  }
    39  ```
    40  
    41  Create a Go test file.
    42  
    43  example_test.go
    44  ```go
    45  package example
    46  
    47  import "testing"
    48  
    49  func Test_example(t *testing.T) {
    50  	example()
    51  }
    52  ```
    53  
    54  Run test and generate coverage report.
    55  
    56  ```sh
    57  go test . -cover -coverprofile coverage.txt
    58  ```
    59  
    60  view coverage report.
    61  
    62  ```sh
    63  go-cover-view
    64  ```
    65  
    66  ```
    67  example.com/example/example.go
    68    1: package example
    69    2: 
    70  O 3: func example() bool {
    71  O 4: 	println("covered")
    72  X 5: 	if false {
    73  X 6: 		println("not covered")
    74  X 7: 	}
    75  O 8: 	return true
    76    9: }
    77  ```
    78  
    79  json output
    80  
    81  ```sh
    82  go-cover-view -output json
    83  ```
    84  
    85  ```json
    86  [
    87    {
    88      "fileName": "example.com/example/example.go",
    89      "coveredLines": [3, 4, 8], 
    90      "uncoveredLines": [5, 6, 7]
    91    }
    92  ]
    93  ```
    94  
    95  markdown output
    96  
    97  ```sh
    98  go-cover-view -output markdown
    99  ```
   100  
   101  ```markdown
   102  # Coverage Report
   103  
   104  
   105  <details> <summary> example.com/example/example.go </summary>
   106  
   107  \```
   108    1: package example
   109    2:
   110  O 3: func example() bool {
   111  O 4: 	println("covered")
   112  X 5: 	if false {
   113  X 6: 		println("not covered")
   114  X 7: 	}
   115  O 8: 	return true
   116    9: }
   117  \```
   118  
   119  </details>
   120  ```
   121  
   122  ## GitHub Actions Integration
   123  
   124  Pull Request comment with markdown report
   125  
   126  ![Screenshot](https://user-images.githubusercontent.com/25817501/85069957-f1c8f300-b1ef-11ea-9ea3-7200e26483da.png)
   127  
   128  GitHub Actions workflow example
   129  
   130  ```yaml
   131  name: ci
   132  on:
   133    pull_request:
   134      branches:
   135        - master
   136  jobs:
   137    test:
   138      strategy:
   139        matrix:
   140          os: [ubuntu-latest]
   141          go: ["1.14"]
   142      runs-on: ${{ matrix.os }}
   143      timeout-minutes: 10
   144      steps:
   145        - uses: actions/checkout@v2
   146        - uses: actions/setup-go@v2
   147          with:
   148            go-version: ${{ matrix.go }}
   149  
   150        - name: "test"
   151          run: |
   152            go test -cover -coverprofile coverage.txt -race -v ./...
   153  
   154        - name: "pull request comment"
   155          env:
   156            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
   157          run: |
   158            git fetch origin master
   159            go get github.com/saurabh-prakash/go-cover-view
   160            go install github.com/saurabh-prakash/go-cover-view
   161            go-cover-view -ci github-actions -git-diff-base origin/master
   162  ```
   163  
   164  ## Help
   165  
   166  ```
   167  Usage of go-cover-view:
   168    -ci string
   169          ci type: available values "", "github-actions"
   170          github-actions:
   171                  Comment the markdown report to Pull Request on GitHub.
   172    -covered string
   173          prefix for covered line (default "O")
   174    -git-diff-base string
   175          git diff base (default "origin/master")
   176    -git-diff-only
   177          only files with git diff
   178    -modfile string
   179          go.mod path
   180    -output string
   181          output type: available values "simple", "json", "markdown" (default "simple")
   182    -report string
   183          coverage report path (default "coverage.txt")
   184    -uncovered string
   185          prefix for uncovered line (default "X")
   186  ```
   187  
   188  ## License
   189  
   190  MIT
   191  
   192  ## Author
   193  
   194  Mitsuo Heijo (@johejo)