rillig / gobco

Measure branch coverage of golang tests
62 stars 12 forks source link

How does this tool calculate the branch coverage of the entire project? #28

Closed byte-jiao closed 11 months ago

byte-jiao commented 1 year ago

How does this tool calculate the branch coverage of the entire project? When I execute it in the root directory of the project, I encounter the following error:

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.(*instrumenter).writeGobcoFiles(0x1?, {0xc00008c540?, 0x1?}, {0x0?, 0x0?, 0x0?})
        /Users/bytedance/go/pkg/mod/github.com/rillig/gobco@v1.2.2/instrumenter.go:574 +0x3cf
main.(*instrumenter).instrument(0xc000388000, {0x117bcff, 0x1}, {0x0, 0x0}, {0xc00008c540, 0x5f})
        /Users/bytedance/go/pkg/mod/github.com/rillig/gobco@v1.2.2/instrumenter.go:79 +0x1b2
main.(*gobco).instrument(0xc0000d2000)
        /Users/bytedance/go/pkg/mod/github.com/rillig/gobco@v1.2.2/main.go:266 +0x275
main.gobcoMain({0x11b4478?, 0xc0000ac008?}, {0x11b4478?, 0xc0000ac010?}, {0xc00009a180, 0x3, 0x3})
        /Users/bytedance/go/pkg/mod/github.com/rillig/gobco@v1.2.2/main.go:28 +0x72
main.main()
        /Users/bytedance/go/pkg/mod/github.com/rillig/gobco@v1.2.2/main.go:21 +0x46

If I add some parameters, for example:

gobco test ./app/... -stats ./b.out

I will encounter the following error:

panic: gobco: checking multiple packages doesn't work yet

goroutine 1 [running]:
main.(*gobco).parseArgs(0xc000114000?, {0xc0000140b0?, 0x5?, 0x5?})
        /Users/bytedance/go/pkg/mod/github.com/rillig/gobco@v1.2.2/main.go:121 +0x205
main.(*gobco).parseCommandLine(0x11b4478?, {0xc0000140a0?, 0x11b4478?, 0xc000012020?})
        /Users/bytedance/go/pkg/mod/github.com/rillig/gobco@v1.2.2/main.go:61 +0x38
main.gobcoMain({0x11b4478?, 0xc000012018?}, {0x11b4478?, 0xc000012020?}, {0xc0000140a0, 0x5, 0x5})
        /Users/bytedance/go/pkg/mod/github.com/rillig/gobco@v1.2.2/main.go:26 +0x5e
main.main()
        /Users/bytedance/go/pkg/mod/github.com/rillig/gobco@v1.2.2/main.go:21 +0x46
rillig commented 1 year ago

How does this tool calculate the branch coverage of the entire project?

Currently, gobco can only calculate the branch coverage of a single Go package, but not of a complete project. That would be a nice addition, though.

panic: runtime error: index out of range [0] with length 0

That's because the root directory of your project doesn't contain any Go package. This is a situation that didn't occur in my testing scenarios. I'll fix it.

panic: gobco: checking multiple packages doesn't work yet

Gobco currently doesn't support the ... argument. I had a look at how the Go tools handle this path specification, but all the related code was quite large and in an internal package, so I decided not to implement it for now.

rillig commented 11 months ago

One of the panics is fixed in 1.3.0, the other one is a duplicate of https://github.com/rillig/gobco/issues/12.