Skip to content

Commit

Permalink
tests: Adapt to check changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguystone committed Feb 2, 2024
1 parent 857b7f6 commit 8e711dd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 38 deletions.
50 changes: 25 additions & 25 deletions dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,80 +16,80 @@ func testDump(file string, showCovered bool) (string, error) {
return out.String(), err
}

func hasLines(c *check.T, out string, lines []string) {
func hasLines(t *testing.T, out string, lines []string) {
for _, line := range lines {
linere := strings.ReplaceAll(line, "\t", "\\s*")
r := regexp.MustCompile(linere)
c.Truef(r.MatchString(out), "%s did not match", line)
check.Truef(t, r.MatchString(out), "%s did not match", line)
}
}

func TestDumpBasic(t *testing.T) {
c := check.NewT(t)
t.Parallel()

out, err := testDump("testdata/basic/cover.out", false)
c.Must.Nil(err)
c.Log(out)
check.MustNil(t, err)
t.Log(out)

c.False(strings.Contains(out, "a.go"))
hasLines(c, out, []string{
check.False(t, strings.Contains(out, "a.go"))
hasLines(t, out, []string{
"b.go 8 0 0.0% 3-20",
"TOTAL 17 9 52.9%",
})

}

func TestDumpShowCovered(t *testing.T) {
c := check.NewT(t)
t.Parallel()

out, err := testDump("testdata/basic/cover.out", true)
c.Must.Nil(err)
c.Log(out)
check.MustNil(t, err)
t.Log(out)

hasLines(c, out, []string{
hasLines(t, out, []string{
"a.go 8 8 100.0%",
"b.go 8 0 0.0% 3-20",
"TOTAL 17 9 52.9%",
})
}

func TestDumpNoFiles(t *testing.T) {
c := check.NewT(t)
t.Parallel()

out, err := testDump("testdata/nofiles/cover.out", true)
c.Must.Nil(err)
c.Equal(out, "No files covered.\n")
check.MustNil(t, err)
check.Equal(t, out, "No files covered.\n")
}

func TestDumpCompleteCoverage(t *testing.T) {
c := check.NewT(t)
t.Parallel()

out, err := testDump("testdata/fullcoverage/cover.out", false)
c.Must.Nil(err)
c.Log(out)
check.MustNil(t, err)
t.Log(out)

c.False(strings.Contains(out, "a.go"))
hasLines(c, out, []string{
check.False(t, strings.Contains(out, "a.go"))
hasLines(t, out, []string{
"TOTAL 1 1 100.0%",
})
}

func TestDumpCompleteCoverageShowCovered(t *testing.T) {
c := check.NewT(t)
t.Parallel()

out, err := testDump("testdata/fullcoverage/cover.out", true)
c.Must.Nil(err)
c.Log(out)
check.MustNil(t, err)
t.Log(out)

hasLines(c, out, []string{
hasLines(t, out, []string{
"a.go 1 1 100.0%",
"TOTAL 1 1 100.0%",
})
}

func TestDumpInvalidCoverageFile(t *testing.T) {
c := check.NewT(t)
t.Parallel()

_, err := testDump("testdata/basic/a.go", true)
c.NotNil(err)
check.NotNil(t, err)
}
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module github.com/thatguystone/gocovr

go 1.20
go 1.22

require (
github.com/thatguystone/cog v0.0.0-20220822191731-d909dcd61c3f
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4
golang.org/x/tools v0.0.0-20190206175659-4892ae6946ab
github.com/thatguystone/cog v0.0.0-20240202220025-9b4b201c1c4d
golang.org/x/sync v0.6.0
golang.org/x/tools v0.17.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/mod v0.14.0 // indirect
)
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/thatguystone/cog v0.0.0-20220822191731-d909dcd61c3f h1:FnXk9fVB7JF4bKkee3GzplEU2FmfUoACPlYGWAw5zPY=
github.com/thatguystone/cog v0.0.0-20220822191731-d909dcd61c3f/go.mod h1:qrIV9w4B3vVDH8GAR8FHjq+rbaDf8dGJ1Y89I35zADU=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/tools v0.0.0-20190206175659-4892ae6946ab h1:sdt20jFck8SCqI78a71BatxIf/EDLZJpgR2DuQaMMdE=
golang.org/x/tools v0.0.0-20190206175659-4892ae6946ab/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
github.com/thatguystone/cog v0.0.0-20240202220025-9b4b201c1c4d h1:yc3FwDos58U8SRd9ign2nXTcBeBLclaQWLtFqYz3iOM=
github.com/thatguystone/cog v0.0.0-20240202220025-9b4b201c1c4d/go.mod h1:xY/zhbNkyHTe2MsdKZV10aXpF7ne1R0pGNYRGprk6U0=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
4 changes: 1 addition & 3 deletions util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
)

func TestLCP(t *testing.T) {
c := check.NewT(t)

tests := []struct {
a string
b string
Expand All @@ -33,6 +31,6 @@ func TestLCP(t *testing.T) {

for _, test := range tests {
res := lcp(test.a, test.b)
c.Equal(res, test.lcp)
check.Equal(t, res, test.lcp)
}
}

0 comments on commit 8e711dd

Please sign in to comment.