Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"
"regexp"
"strings"
"testing"

"github.com/get-woke/woke/pkg/output"
Expand All @@ -20,9 +21,12 @@ import (
// run profiling with
// go test -v -cpuprofile cpu.prof -memprofile mem.prof -bench=. ./cmd
// memory:
// go tool pprof mem.prof
//
// go tool pprof mem.prof
//
// cpu:
// go tool pprof cpu.prof
//
// go tool pprof cpu.prof
func BenchmarkRootRunE(b *testing.B) {
zerolog.SetGlobalLevel(zerolog.NoLevel)
output.Stdout = io.Discard
Expand Down Expand Up @@ -70,12 +74,39 @@ func TestParseArgs(t *testing.T) {
t.Cleanup(func() {
stdin = false
})
assert.Equal(t, parser.DefaultPath, parseArgs([]string{}))
assert.Equal(t, []string{"../.."}, parseArgs([]string{"../.."}))

stdin = true
assert.Equal(t, []string{os.Stdin.Name()}, parseArgs([]string{}))
assert.Equal(t, []string{os.Stdin.Name()}, parseArgs([]string{"../.."}))
tests := []struct {
stdin bool
args []string
expectedArgs []string
}{
{
stdin: false,
args: []string{},
expectedArgs: parser.DefaultPath,
},
{
stdin: false,
args: []string{"../.."},
expectedArgs: []string{"../.."},
},
{
stdin: true,
args: []string{},
expectedArgs: []string{os.Stdin.Name()},
},
{
stdin: true,
args: []string{"../.."},
expectedArgs: []string{os.Stdin.Name()},
},
}
for _, tt := range tests {
t.Run(strings.Join(tt.args, " "), func(t *testing.T) {
stdin = tt.stdin
files := parseArgs(tt.args)
assert.Equal(t, tt.expectedArgs, files)
})
}
}

func TestRunE(t *testing.T) {
Expand Down