I've noticed what looks at its surface that some code that is covered 
doesn't show up in the cover profile data. Unfortunately, I don't have a 
minimal example as I have no idea how to drill down. So please bear with my 
explanations and hopefully it's a problem between VT100 and chair, I just 
don't see it yet.

I see the same behavior with go 1.22.0 as well as 1.21.7.

This is the repository where I see the seemingly odd 
profile: https://github.com/thediveo/notwork (sic!)

I run all tests as follows with coverage, see 
also https://github.com/thediveo/notwork/blob/master/scripts/cov.sh, but 
this is the gist:

GOCOVERTMPDIR="$(mktemp -d)"
trap 'rm -rf -- "$GOCOVERTMPDIR"' EXIT
go test -cover -v -race -exec sudo -tags ${BUILDTAGS} -p=1 \
  -count=1 ./... -args -test.gocoverdir="$GOCOVERTMPDIR"
go tool covdata textfmt -i="$GOCOVERTMPDIR" -o=coverage.out
go tool cover -html=coverage.out -o=coverage.html

The problem now is 
in 
https://github.com/thediveo/notwork/blob/14cb6bc6ffc51704df84f95b88fdd0097c62bad6/link/link.go#L81,
 
where the if branch is shown as uncovered:

if veth, ok := link.(*netlink.Veth); ok {
    Expect(rand.Read(randbytes)).Error().NotTo(HaveOccurred())
    peername := prefix + hex.EncodeToString(randbytes)
    veth.PeerName = peername
}

This branch is covered, as can be seen by putting a panic into it. This 
test 
https://github.com/thediveo/notwork/blob/14cb6bc6ffc51704df84f95b88fdd0097c62bad6/veth/veth_test.go#L36
 
here causes this branch to be taken, 
via 
https://github.com/thediveo/notwork/blob/14cb6bc6ffc51704df84f95b88fdd0097c62bad6/veth/veth.go#L38.

This coverage behavior should be hopefully reprodroducable by cloning the 
repository and running "make coverage" in its top-level directory.

So what am I doing wrong here?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/45fc1f9f-d331-4013-aafe-b597f9ebb81en%40googlegroups.com.

Reply via email to