Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uncovered option to display only less than 100% coverage #19

Closed
KEINOS opened this issue Aug 12, 2021 · 0 comments
Closed

uncovered option to display only less than 100% coverage #19

KEINOS opened this issue Aug 12, 2021 · 0 comments

Comments

@KEINOS
Copy link
Contributor

KEINOS commented Aug 12, 2021

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)"
KEINOS added a commit to KEINOS/Fork_go-carpet that referenced this issue Aug 29, 2022
KEINOS added a commit to KEINOS/Fork_go-carpet that referenced this issue Sep 6, 2022
msoap pushed a commit that referenced this issue Sep 8, 2022
* chore: add test for `-mincov` option

* feat: "-mincov" option to set coverage threshold (issue #19)

* docs: add description of "-mincov" option

* chore: add more test for `-mincov` option (getCoverForDir)

* fix: skip files early on `getCoverForDir()`

See: #20 (comment)

* fix: remove redundant filtering

Filtering in `getCoverForDir()` is enough.
@msoap msoap closed this as completed Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants