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:
Let's first run go test
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