[GO] Sonargo coverage results does not match "go test"

Sonargo coverage results does not match results given by native go test command. The difference is due to Sonargo considering lines from .go files that do not have any test cases as uncovered lines,whereas go test -cover command ignores those files.

Sample code given below for reference. In the below code, dummy.go file has only type/var declarations, which is a VALID scenario.

Can this be considered a bug ?

total 48
drwxr-xr-x   8 joeblogs  XXXX\Domain Users   256B Oct 22 14:18 ./
drwxr-xr-x  21 joeblogs  XXXX\Domain Users   672B Oct 22 13:49 ../
-rw-r--r--   1 joeblogs  XXXX\Domain Users    70B Oct 22 14:19 c.out
-rw-r--r--   1 joeblogs  XXXX\Domain Users    69B Oct 22 14:18 dummy.go
-rw-------   1 joeblogs  XXXX\Domain Users    52B Oct 22 14:02 go.mod
-rw-------   1 joeblogs  XXXX\Domain Users   499B Oct 22 14:03 go.sum
-rw-r--r--   1 joeblogs  XXXX\Domain Users   186B Oct 22 14:15 hello.go
-rw-r--r--   1 joeblogs  XXXX\Domain Users   181B Oct 22 14:15 hello_test.go
WM-WORKSTATION>$ cat hello.go
package hello

import "fmt"
import "rsc.io/quote"

func Hello() string {
    return quote.Hello()

func fn(myvar int) int {
    myvar = 42
    return myvar
WM-WORKSTATION>$ cat dummy.go
package hello

const dummy = 0

type test struct {
  x int
  y int
WM-WORKSTATION>$ cat 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)
WM-WORKSTATION>$ go test ./... -v -coverprofile=c.out
=== RUN   TestHello
Hello--- PASS: TestHello (0.00s)
coverage: 50.0% of statements
ok  	hello	0.018s	coverage: 50.0% of statements
WM-WORKSTATION>$ cat c.out
mode: set
hello/hello.go:6.21,9.2 2 1
hello/hello.go:11.24,14.2 2 0
WM-WORKSTATION>$`Preformatted text`

Hi Chandra,

No, it’s not a bug but a feature. SonarGo tries to compensate for the fact that go test does not contain go files without any test cases. We believe that all source code should be tested and try to enforce that.
If in a project you have a specific context, where you intentionally don’t want to include coverage of some files, it’s possible to configure it using the sonar.coverage.exclusions property, see Ignore Code Coverage or Ignore Files in SonarQube documentation.