uartois / sonar-golang

Sonarqube plugin for the golang language.
GNU Lesser General Public License v3.0
245 stars 32 forks source link

The number of executable lines in not-tested source file is no correctly computed #60

Closed lylex closed 6 years ago

lylex commented 6 years ago

Description

A not-tested source file will over-decrease the code coverage, even if the definitions are all calculated.

Steps to Reproduce

  1. Create a project with two source files(e.g. a.go and b.go)
  2. Write test for a.go(i.e. a_test.go)
  3. Run the calculation, and you will find the coverage is not expected. Each lines in the b.go are calculated in the total lines.

Versions

Versions of your sonar installation (server, sonar-scanner), gometalinter, go and OS.

Sonar Server: 6.5(build 27846) Sonar-golang Plugin: 1.2.11-rc10 GO: go1.9.2

danielleberre commented 6 years ago

Well, this is the classical behavior: you expect to have 100% coverage when both a.go and b.go are covered by tests.

Or did I miss something?

Would you like to exclude some files from coverage computation?

lylex commented 6 years ago

@danielleberre Sorry for the confusion, let me explain a little bit more with an example.

Assume we have the following folder:

└── src └── ├── a.go ├── b.go ├── coverage.xml ├── report.xml ├── sonar-project.properties ├── sonar-scanner.properties └── test.xml And a.go is, `package main import ( "fmt" ) func main() { foo() fmt.Println("vim-go") }` while b.go is `package main import ( "fmt" ) func foo() { fmt.Println("in foo") }` After we generated the coverage.xml, report.xml and test.xml, and then run sonar-runner successfully, we will see the uncovered lines is unexpected.   | Coverage | Uncovered Lines | Uncovered Conditions -- | -- | -- | -- a.go | 0.0% | 10 | – b.go | 0.0% | 9 | – As we can see, uncovered lines in a.go should be 2, and b.go should be 1. So, when a certain package contains no test files, each lines of the packages will calculated as uncovered lines, and that is not corrected.
danielleberre commented 6 years ago

ok, I see.

When files are tested, we rely on the coverage file to detect "executable lines", so that information is correct.

When files are not tested, we simply report the number of lines, we do not restrict to executable lines.

@thibaultfalque any idea how to count the number of executable lines in untested files?

thibaultfalque commented 6 years ago

63947781319a4a533c734ceefe8bfa1197e9972a

thibaultfalque commented 6 years ago

We improved the calculation of untested lines. We will publish a release soon.

thibaultfalque commented 6 years ago

@lylex could you test with the last release ?

lylex commented 6 years ago

@thibaultfalque I have tried the new release with my project, and I still find something unexpected. I believe that is not the same root cause, so I verify this issue and open #61.