Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cover: zero coverage for cgo project #13625

Closed
zhulik opened this issue Dec 15, 2015 · 4 comments
Closed

cmd/cover: zero coverage for cgo project #13625

zhulik opened this issue Dec 15, 2015 · 4 comments

Comments

@zhulik
Copy link

@zhulik zhulik commented Dec 15, 2015

Hi, i writing bindings for libmediainfo and when i start to write tests i noted, that coverage is 0.0% and coverprofile is empty, i don't see any files in dropdown when doing go tool cover -html=coverage.out.

go version go1.5.2 linux/amd64

Steps to reproduce:

git clone https://github.com/zhulik/go_mediainfo.git
cd go_mediainfo
go test -cover

I know, that this is not first issue with cgo and coverage, #6333 is closed over a year ago, but i have the same issue now.

@ianlancetaylor ianlancetaylor changed the title Zero coverage for cgo project cmd/cover: zero coverage for cgo project Dec 15, 2015
@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Dec 15, 2015
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Apr 8, 2016

@robpike, is cmd/cover compatible with cgo?

@robpike
Copy link
Contributor

@robpike robpike commented Apr 8, 2016

It's supposed to. See #6333.

@ALTree
Copy link
Member

@ALTree ALTree commented May 14, 2016

Simple reproducer:

rand.go:

package rand

/*
#include <stdlib.h>
*/
import "C"

func Random() int {
    return int(C.random())
}

func Seed(i int) {
    C.srandom(C.uint(i))
}

rand_test.go:

package rand_test

import (
    "testing"

    "github.com/ALTree/rand"
)

func TestRandom(t *testing.T) {
    x := rand.Random()
    if x < 0 {
        t.Fatalf("%d < 0\n", x)
    }
}

go test -cover gives 0.0% if and only if the tests are in a separate package (in this case, rand_test). If the package declaration in rand_test.go is changed to package rand, -cover reports a correct value; and that is the reason the test introduced in CL 71230049 by rsc didn't catch the problem (that test has package p for both the cgo file and the _test file).

@rsc rsc modified the milestones: Go1.8, Go1.7 May 17, 2016
@gopherbot
Copy link

@gopherbot gopherbot commented Nov 3, 2016

CL https://golang.org/cl/32614 mentions this issue.

@gopherbot gopherbot closed this in 1c08c72 Nov 3, 2016
@golang golang locked and limited conversation to collaborators Nov 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
You can’t perform that action at this time.