go-carpet - show test coverage in terminal for Go source files

Overview

go-carpet - show test coverage for Go source files

GoDoc Build Status Coverage Status Report Card Homebrew formula exists

To view the test coverage in the terminal, just run go-carpet.

It works outside of the GOPATH directory. And it works recursively for multiple packages.

With -256colors option, shades of green indicate the level of coverage.

By default skip vendor directories (Godeps,vendor), otherwise use -include-vendor option.

Usage

usage: go-carpet [options] [paths]
  -256colors
    	use more colors on 256-color terminal (indicate the level of coverage)
  -args string
    	pass additional arguments for go test
  -file string
    	comma-separated list of files to test (default: all)
  -func string
    	comma-separated functions list (default: all functions)
  -include-vendor
    	include vendor directories for show coverage (Godeps, vendor)
  -summary
    	only show summary for each file
  -version
    	get version

For view coverage in less, use -R option:

go-carpet | less -R

Install

From source:

go get -u github.com/msoap/go-carpet
sudo ln -s $(go env GOPATH)/bin/go-carpet /usr/local/bin/go-carpet

Download binaries from: releases (OS X/Linux/Windows)

Install from homebrew (OS X):

brew tap msoap/tools
brew install go-carpet
# update:
brew upgrade go-carpet

Screenshot

screen shot 2016-03-06

See also

Comments
  • Option to exclude directory

    Option to exclude directory

    Instead of specifying all the directories to include, it would be nice to have the option to just specify the directories to exclude. For example, if I have vendored code in Godeps/, I could just specify to exclude the Godeps folder but run on everything else.

    enhancement 
    opened by jcscottiii 4
  • Strange Highlighting?

    Strange Highlighting?

    This may be my environments or "something" but the highlighting seems to be in odd places occasionally. Some output I'm looking at now has a line with the text return typedValue and half the line is not highlighted and half is, as in

    return typedValue
    (imagine the bold is green).

    opened by gholt 3
  • Coverage stats

    Coverage stats

    Just some random idea: maybe you can add coverage stats to each file and at the end show average coverage for all files or by package etc. (weighted, taking into account number of lines in each file). Something like you can see on gocover: https://gocover.io/github.com/msoap/go-carpet

    Cheers

    enhancement 
    opened by matrixik 3
  • Go Modules Support

    Go Modules Support

    Sorry for the repeat. :) Turns out the quick fix I did to work with Go Modules style code directories wasn't quite exact. It seems to work fine in the root of the go.mod enabled repo, but not in subdirs/packages. My first guess is that the code will need to look for go.mod in the current and parent directories to determine the source file paths. I don't quite have time to mess with it right now; hence this issue in case someone does have time before me.

    opened by gholt 2
  • Not working with many Go paths

    Not working with many Go paths

    Hi,

    I tried to use your tool, but looks like it not working with many Go paths. I believe problem is https://github.com/msoap/go-carpet/blob/master/go-carpet.go#L127

    When I have;

    export GOROOT=$HOME/.go
    export PATH=$PATH:$GOROOT/bin
    export GOPATH=$HOME/golibs/os:$HOME/golibs/forks:$HOME/golibs/my
    export PATH=$PATH:$HOME/golibs/my/bin:$HOME/golibs/forks/bin:$HOME/golibs/os/bin
    

    I get errors when running:

    dobek@Lapek2:~/go/os/sr/gi/Ge/go.rice <master:βœ”>
    20:26:22 Ξ» go-carpet .                                                                                                                            [40d21h44m]
    2016/03/04 20:26:24 open /home/dobek/golibs/os:/home/dobek/golibs/forks:/home/dobek/golibs/my/src/github.com/GeertJohan/go.rice/appended.go: no such file or directory
    2016/03/04 20:26:25 open /home/dobek/golibs/os:/home/dobek/golibs/forks:/home/dobek/golibs/my/src/github.com/GeertJohan/go.rice/rice/append.go: no such file or directory
    

    Cherrs

    bug 
    opened by matrixik 2
  • Early support for Go Modules

    Early support for Go Modules

    This isn't the greatest code by any stretch, but it seems to get the job done. Hopefully as Go Modules become more prevalent, they will release official APIs for us (or maybe they already have and I just don't know where to look).

    Fixes #12

    enhancement 
    opened by gholt 1
  • Add file summary mode

    Add file summary mode

    The go tools will show a package-level summary (with -covermode=count), and go-carpet shows file summaries plus line coverage. At times, I'd like to just see a file-level summary of coverage.

    I have a proof-of-concept patch that I can submit as a PR, but I wanted to open an issue for discussion before doing so. My patch outputs:

    $ go-carpet -ls
    github.com/msoap/go-carpet/ast.go - 100.0%
    github.com/msoap/go-carpet/go-carpet.go - 65.8%
    github.com/msoap/go-carpet/terminal_posix.go - 100.0%
    github.com/msoap/go-carpet/utils.go - 100.0%
    Coverage: 70.9% of statements
    
    enhancement 
    opened by moorereason 1
  • Install failing on OSX

    Install failing on OSX

    Hi,

    Thanks for releasing this tool, I found it very useful. I had no problem using it on linux, but on Mac OS X (10.11.3 ) I get this error while installing

    go get -u github.com/msoap/go-carpet
    go install runtime/internal/sys: mkdir /usr/local/go/pkg/linux_amd64: permission denied
    

    Any idea how to get around this?

    wontfix 
    opened by julien 1
  • uncovered option to display only less than 100% coverage

    uncovered option to display only less than 100% coverage

    I would like to thank you in advance for providing us such a helpful and cool tool!!

    I understand that 100% coverage is a myth though, I would like to have an option that only shows the uncovered ones, if possible.

     usage: go-carpet [options] [paths]
       -256colors
         	use more colors on 256-color terminal (indicate the level of coverage)
       -args string
         	pass additional arguments for go test
       -file string
         	comma-separated list of files to test (default: all)
       -func string
         	comma-separated functions list (default: all functions)
       -include-vendor
         	include vendor directories for show coverage (Godeps, vendor)
    +  -mincov int
    +     	only show files that coverage were less than this value (default: 100)
       -summary
         	only show summary for each file
       -version
         	get version
    

    My current workaround is to create a shell script as below. But it would be nice to have it by default.

    #!/bin/bash
    
    name_file_coverage='coverage.out'
    
    # getNameFilesUncovered echoes file names in comma-separated list which didn't
    # cover 100%. This will be used for β€œgo-carpet` -file option.
    function getNameFilesUncovered() {
        list=$(go tool cover -func="$name_file_coverage" | grep -v '100.0%\|init\|total' | awk '{print $1}')
        echo "$list" | while IFS= read -r line; do
            basename "${line}" | sed -e 's/\.[^\.]*$/\.go/'
        done | uniq | tr '\n' ','
    }
    
    # Run test and create cover profile
    go test -timeout 30s -cover -v -coverprofile "$name_file_coverage" ./...
    
    # Run go-carpet by specifing files into test
    go-carpet -file "$(getNameFilesUncovered)"
    
    enhancement 
    opened by KEINOS 0
  • Go Modules Support?

    Go Modules Support?

    It's quite possible I'm doing something wrong, but go-carpet doesn't seem to work with new Go code in the Go Modules (outside of GOPATH) style.

    go version             # go version go1.11.2 linux/amd64
    mkdir tp
    cd tp
    go mod init tp
    echo -e 'package main\nfunc main(){}\n' > main.go
    echo -e 'package main\nimport "testing"\nfunc TestMain(t *testing.T){}\n' > main_test.go
    go test                # works fine
    go-carpet              # 2019/02/20 20:27:23 file 'tp/main.go' not found in GOPATH
    
    opened by gholt 0
  • Omit files

    Omit files

    Please add option to exclude files from the report -- primarily to omit auto-generated sources.

    Edit. Even better ignore files following the go convention:

    var (
    	genHdr = []byte("// Code generated ")
    	genFtr = []byte(" DO NOT EDIT.")
    )
    
    // isGenerated reports whether the source file is generated code
    // according the rules from https://golang.org/s/generatedcode.
    // This is inherited from the original go lint.
    func isGenerated(src []byte) bool {
    	sc := bufio.NewScanner(bytes.NewReader(src))
    	for sc.Scan() {
    		b := sc.Bytes()
    		if bytes.HasPrefix(b, genHdr) && bytes.HasSuffix(b, genFtr) && len(b) >= len(genHdr)+len(genFtr) {
    			return true
    		}
    	}
    	return false
    }
    
    enhancement 
    opened by illotum 0
Releases(v1.10.0)
Owner
Sergey Mudrik
𐄁𐄁𐄁𐄁 𐄁 𐄁𑁋𐄁𐄁 𐄁𑁋𐄁𐄁 𑁋𑁋𑁋
Sergey Mudrik
Test coverage in Go, the whole package

Test coverage in Go, the whole package

Eleni Fragkiadaki 5 Jan 20, 2022
The portal gates to coverage reports

Covergates - Portal Gates to Coverage Reports Purpose Covergates is to make the easiest way to setup a self-hosted coverage report service. It's an al

Covergates 55 Dec 18, 2022
A Comprehensive Coverage Testing System for The Go Programming Language

goc δΈ­ζ–‡ι‘΅ | goc is a comprehensive coverage testing system for The Go Programming Language, especially for some complex scenarios, like system testing c

Qiniu Cloud 613 Jan 8, 2023
Coverage testing tool for The Go Programming Language

gocov Coverage reporting tool for The Go Programming Language Installation go get github.com/axw/gocov/gocov Usage There are currently four gocov comm

Andrew Wilkins 790 Jan 3, 2023
Hsuan-Fuzz: REST API Fuzzing by Coverage Level Guided Blackbox Testing

Hsuan-Fuzz: REST API Fuzzing by Coverage Level Guided Blackbox Testing Architecture Usage package main import ( restAPI "github.com/iasthc/hsuan-

Chung-Hsuan Tsai 20 Nov 30, 2022
go-test-trace is like go test but it also generates distributed traces.

go-test-trace go-test-trace is like go test but it also generates distributed traces. Generated traces are exported in OTLP to a OpenTelemetry collect

JBD 376 Jan 5, 2023
Flugel Test Documentation for steps to run and test the automatio

Flugel Test Documentation Documentation for steps to run and test the automation #Test-01 1 - Local Test Using Terratest (End To End) 1- By runing " t

Suc0_Unix 0 Nov 13, 2022
Test-assignment - Test assignment with golang

test-assignment We have a two steam of data and we need to save it in the map: I

null 0 Jan 19, 2022
This repository includes consumer driven contract test for provider, unit test and counter api.

This repository includes consumer driven contract test for provider, unit test and counter api.

Ahmet Zümberoğlu 0 Feb 1, 2022
Automatically generate Go test boilerplate from your source code.

gotests gotests makes writing Go tests easy. It's a Golang commandline tool that generates table driven tests based on its target source files' functi

Charles Weill 4.4k Jan 8, 2023
Test your command line interfaces on windows, linux and osx and nodes viΓ‘ ssh and docker

Commander Define language independent tests for your command line scripts and programs in simple yaml files. It runs on windows, osx and linux It can

null 209 Dec 17, 2022
Run a real Postgres database locally on Linux, OSX or Windows as part of another Go application or test

embedded-postgres Run a real Postgres database locally on Linux, OSX or Windows as part of another Go application or test. When testing this provides

Fergus Strange 494 Dec 27, 2022
End to end functional test and automation framework

Declarative end to end functional testing (endly) This library is compatible with Go 1.12+ Please refer to CHANGELOG.md if you encounter breaking chan

Viant, Inc 231 Jan 6, 2023
Test your code without writing mocks with ephemeral Docker containers πŸ“¦ Setup popular services with just a couple lines of code ⏱️ No bash, no yaml, only code πŸ’»

Gnomock – tests without mocks ??️ Spin up entire dependency stack ?? Setup initial dependency state – easily! ?? Test against actual, close to product

Yury Fedorov 1k Dec 29, 2022
http integration test framework

go-hit hit is an http integration test framework written in golang. It is designed to be flexible as possible, but to keep a simple to use interface f

Tobias Salzmann 157 Dec 29, 2022
Go testing in the browser. Integrates with `go test`. Write behavioral tests in Go.

GoConvey is awesome Go testing Welcome to GoConvey, a yummy Go testing tool for gophers. Works with go test. Use it in the terminal or browser accordi

SmartyStreets 7.6k Dec 30, 2022
A Go test assertion library for verifying that two representations of JSON are semantically equal

jsonassert is a Go test assertion library for verifying that two representations of JSON are semantically equal. Usage Create a new *jsonassert.Assert

Roger Guldbrandsen 102 Jan 4, 2023
Ruby on Rails like test fixtures for Go. Write tests against a real database

testfixtures Warning: this package will wipe the database data before loading the fixtures! It is supposed to be used on a test database. Please, doub

null 895 Jan 8, 2023
A tool for generating self-contained, type-safe test doubles in go

counterfeiter When writing unit-tests for an object, it is often useful to have fake implementations of the object's collaborators. In go, such fake i

Max Brunsfeld 772 Jan 5, 2023