Details
Description
SonarGo coverage and go test coverage show different results. We should match go test coverage to avoid confusion.
Let's take the following code as example:
// hello.go package hello import "rsc.io/quote" import "fmt" func Hello() string { fmt.Printf( "Hello") return quote.Hello() } func fn(myvar int) int { myvar = 42 return myvar }
// hello_test.go package hello import "testing" func TestHello(t *testing.T) { want := "Hello, world." if got := Hello(); got != want { t.Errorf("Hello() = %q, want %q", got, want) } }
Let's first run go test
$ go test -coverprofile=coverage.out HelloPASS coverage: 50.0% of statements ok example.com/hello 0.006s
If use gocov and gocov-xml to convert the output (gocov convert coverage.out | gocov-xml > coverage.xml) we see that it counts 4 lines to cover and 2 lines uncovered (50% coverage) It counts only one line for statements split on multiple lines.
SonarGo on the other hand will count 9 lines to cover and 4 lines uncovered (55.6% coverage):
- including empty lines in Hello and fn.
- counting multiple lines when a statement is split on multiple lines: fmt.Printf( \n "Hello") and myvar = \n 42
This ticket replaces https://github.com/SonarSource/sonar-go/issues/340 from the old sonar-go repository
Attachments
Issue Links
- is duplicated by
-
SONARSLANG-485 [GO] - Enum and type coverage computed by the analyser should match "go test"
-
- Closed
-
- links to
- relates to
-
SUPPORT-17469 Loading...