Skip to content

Commit

Permalink
Coverage stuff (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnstoppableMango authored Jan 13, 2025
1 parent 50d8eb6 commit 5024fb9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
bin/
*.test
.envrc
cover.profile
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ tidy: go.sum
test_all:
$(GINKGO) run -r ./

cover: cover.profile
go tool cover -func=$<

cover.profile: $(shell $(DEVCTL) list --go) | bin/ginkgo bin/devctl
$(GINKGO) run --coverprofile=cover.profile -r ./

go.sum: go.mod $(shell $(DEVCTL) list --go) | bin/devctl
go mod tidy

Expand Down
15 changes: 15 additions & 0 deletions internal/testing/testing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package testing

import "errors"

type ErrReader string

func (e ErrReader) Read([]byte) (int, error) {
return 0, errors.New(string(e))
}

type ErrWriter string

func (e ErrWriter) Write(p []byte) (int, error) {
return 0, errors.New(string(e))
}
8 changes: 8 additions & 0 deletions scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
. "github.com/onsi/gomega"

"github.com/unmango/go-make"
"github.com/unmango/go-make/internal/testing"
"github.com/unmango/go-make/token"
)

Expand Down Expand Up @@ -117,4 +118,11 @@ var _ = Describe("Scanner", func() {
Expect(s.Scan()).To(BeTrue())
Expect(s.Token()).To(Equal(token.NEWLINE))
})

It("should return IO errors", func() {
s := make.NewScanner(testing.ErrReader("io error"))

Expect(s.Scan()).To(BeFalse())
Expect(s.Err()).To(MatchError("io error"))
})
})
42 changes: 42 additions & 0 deletions write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
. "github.com/onsi/gomega"

"github.com/unmango/go-make"
"github.com/unmango/go-make/internal/testing"
)

var _ = Describe("Write", func() {
Expand Down Expand Up @@ -105,4 +106,45 @@ var _ = Describe("Write", func() {
Expect(err).NotTo(HaveOccurred())
Expect(buf.String()).To(Equal("target:\ntarget2:\n"))
})

It("should write a Makefile", func() {
buf := &bytes.Buffer{}
w := make.NewWriter(buf)

_, err := w.WriteMakefile(make.Makefile{
Rules: []make.Rule{{
Target: []string{"target"},
}},
})

Expect(err).NotTo(HaveOccurred())
})

It("should return errors found when writing a Makefile", func() {
w := make.NewWriter(testing.ErrWriter("io error"))

_, err := w.WriteMakefile(make.Makefile{
Rules: []make.Rule{{
Target: []string{"target"},
}},
})

Expect(err).To(MatchError("io error"))
})

It("should return errors found when writing PreReqs", func() {
w := make.NewWriter(testing.ErrWriter("io error"))

_, err := w.WritePreReqs([]string{"blah"})

Expect(err).To(MatchError("io error"))
})

It("should return errors found when writing Recipes", func() {
w := make.NewWriter(testing.ErrWriter("io error"))

_, err := w.WriteRecipes([]string{"blah"})

Expect(err).To(MatchError("io error"))
})
})

0 comments on commit 5024fb9

Please sign in to comment.