Skip to content

Commit

Permalink
Add more coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobg committed Jan 21, 2024
1 parent 3c2123d commit 9bada19
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion cmd/decouple/decouple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import (
"encoding/json"
"path/filepath"
"reflect"
"strings"
"testing"

"github.com/bobg/go-generics/v3/iter"
)

func TestRun(t *testing.T) {
func TestRunJSON(t *testing.T) {
buf := new(bytes.Buffer)
if err := run(buf, false, true, []string{"../.."}); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -44,3 +47,28 @@ func TestRun(t *testing.T) {
t.Errorf("got %v, want %v", got, want)
}
}

func TestRunPlain(t *testing.T) {
buf := new(bytes.Buffer)
if err := run(buf, false, false, []string{"../.."}); err != nil {
t.Fatal(err)
}

lines, err := iter.ToSlice(iter.Lines(buf))
if err != nil {
t.Fatal(err)
}

if len(lines) != 2 {
t.Fatalf("got %d lines, want 2", len(lines))
}
if !strings.HasSuffix(lines[0], ": showJSON") {
t.Fatalf(`line 1 is "%s", want something ending in ": showJSON"`, lines[0])
}

lines[1] = strings.TrimSpace(lines[1])
const want = "checker: [NameForMethods]"
if lines[1] != want {
t.Fatalf(`line 2 is "%s", want "%s"`, lines[1], want)
}
}

0 comments on commit 9bada19

Please sign in to comment.