Skip to content

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

@gopherbot

Description

@gopherbot

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions