Skip to content

Commit

Permalink
Add option to pass packages to test command
Browse files Browse the repository at this point in the history
  • Loading branch information
konradreiche committed May 25, 2024
1 parent 9233fb6 commit 4b5ff21
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ go install github.com/konradreiche/coverdiff@latest

```
Usage:
coverdiff test [packages]
coverdiff [file]
coverdiff test
Flags:
-h, --help print help text
Examples:
coverdiff test
coverdiff test ./...
PAGER=delta coverdiff test
go test -cover -coverprofile=coverage.out
cat coverage.out | coverdiff
Expand Down
7 changes: 4 additions & 3 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ func command(stdin io.Reader, stdout io.Writer) error {
var fileName string
switch flag.CommandLine.Arg(0) {
case "test":
output, err := runGoTests()
packages := flag.CommandLine.Arg(1)
output, err := runGoTests(packages)
if err != nil {
return err
}
Expand Down Expand Up @@ -67,7 +68,7 @@ func usePager(
return cmd.Run()
}

func runGoTests() (*bytes.Buffer, error) {
func runGoTests(packages string) (*bytes.Buffer, error) {
tempFile, err := createTempFile()
if err != nil {
return nil, err
Expand All @@ -77,7 +78,7 @@ func runGoTests() (*bytes.Buffer, error) {
cmd := exec.Command(
"go",
"test",
"./...",
packages,
"-cover",
"-coverprofile="+tempFile.Name(),
)
Expand Down
1 change: 1 addition & 0 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func TestCommand(t *testing.T) {

t.Run("run-go-tests", func(t *testing.T) {
os.Args[1] = "test"
os.Args[2] = "./size"
flag.Parse()

changeDir(t, "testdata")
Expand Down
9 changes: 7 additions & 2 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
const usage = `📑 coverdiff - print Go test coverage as diff
Usage:
coverdiff test [packages]
coverdiff [file]
coverdiff test
Flags:
-h, --help print help text
Expand All @@ -19,9 +19,14 @@ differences directly on the terminal, similar to Go's -html option. You can
provide the cover profile as a file, pass it through standard input, or let
coverdiff run the Go tests.
To handle larger outputs and add syntax highlighting automatically, set the
PAGER environment variable to your preferred pager, such as delta.
Examples:
coverdiff test
coverdiff test ./...
PAGER=delta coverdiff test
go test -cover -coverprofile=coverage.out
cat coverage.out | coverdiff
Expand Down

0 comments on commit 4b5ff21

Please sign in to comment.