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: does not take into account cgo’s preprocessing #8726

Closed
gopherbot opened this issue Sep 14, 2014 · 2 comments
Closed

cmd/cover: does not take into account cgo’s preprocessing #8726

gopherbot opened this issue Sep 14, 2014 · 2 comments
Milestone

Comments

@gopherbot
Copy link
Contributor

by ivan.ukhov:

Hello,


Consider studying the test coverage of the attached example (main.go and main_test.go).
The example relies on some C code and, thus, involves cgo. Cgo does some preprocessing
to the source code (main.cgo1.go) and, in particular, transforms the line

13  if C.check(C.int(0)) != 0 {

into

15  if _Cfunc_check(_Ctype_int(0)) != 0 {

The coverage profile reported by `go test -coverprofile cover.out` (cover.out) is given
with respect to the preprocessed code, not the original one. Consequently, some column
numbers reported in cover.out are invalid with respect to the original code. As a
result, the htmlGen function in html.go (the cover command) fails to properly detect
block boundaries, which boils down to some span tags left open (cover.html) and, hence,
incorrect highlighting in HTML.


Best wishes,
Ivan

$ go version
go version go1.3.1 darwin/amd64

Attachments:

  1. main.go (219 bytes)
  2. main_test.go (75 bytes)
  3. cover.out (124 bytes)
  4. cover.html (2217 bytes)
  5. main.cgo1.go (605 bytes)
@ianlancetaylor
Copy link
Member

Comment 1:

Labels changed: added repo-tools, release-none.

@bradfitz bradfitz removed the new label Dec 18, 2014
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc removed the release-none label Apr 10, 2015
@rsc rsc changed the title go.tools/cmd/cover: does not take into account cgo’s preprocessing x/tools/cmd/cover: does not take into account cgo’s preprocessing Apr 14, 2015
@rsc rsc modified the milestones: Unreleased, Unplanned Apr 14, 2015
@rsc rsc removed the repo-tools label Apr 14, 2015
@rsc rsc modified the milestones: Unreleased, Go1.11 Nov 10, 2017
@rsc rsc changed the title x/tools/cmd/cover: does not take into account cgo’s preprocessing cmd/cover: does not take into account cgo’s preprocessing Nov 10, 2017
@gopherbot
Copy link
Contributor Author

Change https://golang.org/cl/77155 mentions this issue: cmd/go: run cover before cgo

@golang golang locked and limited conversation to collaborators Nov 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants