sonar-r-plugin icon indicating copy to clipboard operation
sonar-r-plugin copied to clipboard

plans to include code coverage & test results reports ?

Open billmania42 opened this issue 5 years ago • 5 comments

Hello, Are there any plans to extend this plugin to accept R covr coverage reports, and or unit test results reports in the generic sonarqube xml format?

This would add a lot of value to this plugin.

billmania42 avatar Jun 10 '20 14:06 billmania42

It has not been planned yet. If you provide an example of the outputs you want to consume by the plugin I can add it. It should be easy.

kmoco2am avatar Jun 16 '20 12:06 kmoco2am

OK, I will try and look into this sometime this week.

billmania42 avatar Sep 14 '20 16:09 billmania42

Hi. @kmoco2am

I'm generating coverage with the command "cov <- covr :: azure (quiet = FALSE)" and testing with "rcmdcheck :: rcmdcheck (args = '--no-manual', error_on = 'warning', check_dir = 'check' ) ".

I have attached the generated files and the format, as it would be possible to add these results to the sonarqube analysis.

Thanks for any help and I stay tuned.

file: coverage.xml

<?xml version="1.0" encoding="UTF-8"?>
<coverage line-rate="0.965811965811966" branch-rate="0" lines-covered="113" lines-valid="117" branches-covered="0" branches-valid="0" complexity="0" version="3.5.1" timestamp="2021-02-10 08:13:54">
  <sources/>
  <packages>
    <package name="ClickBvlLib" line-rate="0.965811965811966" branch-rate="0" complexity="0">
      <classes>
        <class name="costo_amortizado_ca.cpp" filename="src/costo_amortizado_ca.cpp" line-rate="0.965811965811966" branch-rate="0" complexity="0">
          <methods/>
          <lines>
            <line number="46" hits="1" branch="false"/>
            <line number="58" hits="2" branch="false"/>
            <line number="59" hits="2" branch="false"/>
            <line number="60" hits="2" branch="false"/>
            <line number="61" hits="2" branch="false"/>
            <line number="62" hits="1" branch="false"/>
            <line number="65" hits="1" branch="false"/>
            <line number="67" hits="11" branch="false"/>
            <line number="68" hits="10" branch="false"/>
            <line number="69" hits="10" branch="false"/>
            <line number="70" hits="10" branch="false"/>
            <line number="71" hits="10" branch="false"/>
            <line number="72" hits="10" branch="false"/>
            <line number="73" hits="10" branch="false"/>
            <line number="74" hits="10" branch="false"/>
            <line number="75" hits="10" branch="false"/>
            <line number="76" hits="10" branch="false"/>
            <line number="77" hits="10" branch="false"/>
            <line number="78" hits="10" branch="false"/>
            <line number="79" hits="10" branch="false"/>
            <line number="80" hits="10" branch="false"/>
            <line number="81" hits="10" branch="false"/>
            <line number="82" hits="10" branch="false"/>
            <line number="85" hits="0" branch="false"/>
            <line number="89" hits="10" branch="false"/>
            <line number="90" hits="4800" branch="false"/>
            <line number="91" hits="4790" branch="false"/>
            <line number="92" hits="479" branch="false"/>
            <line number="93" hits="479" branch="false"/>
            <line number="94" hits="479" branch="false"/>
            <line number="95" hits="479" branch="false"/>
            <line number="96" hits="479" branch="false"/>
            <line number="97" hits="479" branch="false"/>
            <line number="98" hits="479" branch="false"/>
            <line number="99" hits="479" branch="false"/>
            <line number="100" hits="479" branch="false"/>
            <line number="101" hits="479" branch="false"/>
            <line number="102" hits="479" branch="false"/>
            <line number="103" hits="479" branch="false"/>
            <line number="104" hits="479" branch="false"/>
            <line number="105" hits="479" branch="false"/>
            <line number="111" hits="10" branch="false"/>
            <line number="112" hits="10" branch="false"/>
            <line number="113" hits="10" branch="false"/>
            <line number="114" hits="489" branch="false"/>
            <line number="115" hits="479" branch="false"/>
            <line number="116" hits="12696" branch="false"/>
            <line number="117" hits="12696" branch="false"/>
            <line number="118" hits="479" branch="false"/>
            <line number="119" hits="479" branch="false"/>
            <line number="122" hits="479" branch="false"/>
            <line number="123" hits="10" branch="false"/>
            <line number="124" hits="10" branch="false"/>
            <line number="125" hits="10" branch="false"/>
            <line number="126" hits="10" branch="false"/>
            <line number="127" hits="10" branch="false"/>
            <line number="128" hits="10" branch="false"/>
            <line number="130" hits="469" branch="false"/>
            <line number="133" hits="469" branch="false"/>
            <line number="134" hits="2" branch="false"/>
            <line number="135" hits="0" branch="false"/>
            <line number="136" hits="0" branch="false"/>
            <line number="137" hits="0" branch="false"/>
            <line number="138" hits="2" branch="false"/>
            <line number="139" hits="467" branch="false"/>
            <line number="141" hits="469" branch="false"/>
            <line number="142" hits="469" branch="false"/>
            <line number="143" hits="469" branch="false"/>
            <line number="144" hits="469" branch="false"/>
            <line number="145" hits="469" branch="false"/>
            <line number="147" hits="479" branch="false"/>
            <line number="148" hits="10" branch="false"/>
            <line number="154" hits="10" branch="false"/>
            <line number="155" hits="10" branch="false"/>
            <line number="156" hits="489" branch="false"/>
            <line number="157" hits="12696" branch="false"/>
            <line number="158" hits="12696" branch="false"/>
            <line number="159" hits="479" branch="false"/>
            <line number="160" hits="479" branch="false"/>
            <line number="164" hits="479" branch="false"/>
            <line number="165" hits="10" branch="false"/>
            <line number="166" hits="10" branch="false"/>
            <line number="167" hits="10" branch="false"/>
            <line number="169" hits="469" branch="false"/>
            <line number="170" hits="469" branch="false"/>
            <line number="171" hits="469" branch="false"/>
            <line number="173" hits="479" branch="false"/>
            <line number="176" hits="10" branch="false"/>
            <line number="177" hits="10" branch="false"/>
            <line number="178" hits="10" branch="false"/>
            <line number="179" hits="10" branch="false"/>
            <line number="180" hits="10" branch="false"/>
            <line number="181" hits="10" branch="false"/>
            <line number="182" hits="10" branch="false"/>
            <line number="183" hits="10" branch="false"/>
            <line number="184" hits="10" branch="false"/>
            <line number="185" hits="10" branch="false"/>
            <line number="186" hits="10" branch="false"/>
            <line number="187" hits="10" branch="false"/>
            <line number="188" hits="10" branch="false"/>
            <line number="189" hits="10" branch="false"/>
            <line number="191" hits="2" branch="false"/>
            <line number="192" hits="2" branch="false"/>
            <line number="193" hits="2" branch="false"/>
            <line number="194" hits="2" branch="false"/>
            <line number="195" hits="2" branch="false"/>
            <line number="196" hits="2" branch="false"/>
            <line number="197" hits="2" branch="false"/>
            <line number="198" hits="2" branch="false"/>
            <line number="199" hits="2" branch="false"/>
            <line number="200" hits="2" branch="false"/>
            <line number="201" hits="2" branch="false"/>
            <line number="202" hits="2" branch="false"/>
            <line number="203" hits="2" branch="false"/>
            <line number="204" hits="2" branch="false"/>
            <line number="205" hits="3" branch="false"/>
            <line number="206" hits="2" branch="false"/>
          </lines>
        </class>
      </classes>
    </package>
  </packages>
</coverage>

file: test-results.xml

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="Test costo_amortizado_ca" timestamp="2021-02-10T13:10:54Z" hostname="DESKTOP-EKPQGAL" tests="3" skipped="0" failures="0" errors="0" time="0.52">
    <testcase time="0.48" classname="Test_costo_amortizado_ca" name="generateDatesArray_test"/>
    <testcase time="0.02" classname="Test_costo_amortizado_ca" name="generateDatesArray_test"/>
    <testcase time="0.0199999999999998" classname="Test_costo_amortizado_ca" name="generateDatesArray_test"/>
  </testsuite>
</testsuites>

juparog avatar Feb 10 '21 15:02 juparog

So finally I have found some time to look at this. I am sorry for delay. I found out that SonarQube is able to consume "generic" coverage data: https://docs.sonarqube.org/latest/analysis/generic-test/

And covr is able to generate that format easily:

cov <- covr::package_coverage(quiet=FALSE)
covr::to_sonarqube(cov, filename = "covr_sonarqube.xml")

Then it is necessary to add configuration for SonarQube scanner:

sonar.coverageReportPaths=covr_sonarqube.xml

It works nicely if there are "modules" but it does not work for my sample project because R code generates XML with file paths containing "module" name at the beginning and it cannot be turned off. Is it the same case for you? Could you try it?

kmoco2am avatar May 26 '21 12:05 kmoco2am

So, I have added code coverage into sample project. I had to add a piece of R code to remove module name which is included by to_sonarqube function and it causes that SonarQube is not able to match filenames: https://github.com/Merck/sonar-r-plugin/blob/master/sample-project/run_cov.R

I am not sure if it is the right solution but it can be used as a workaround until there is valid fix.

kmoco2am avatar Aug 23 '21 14:08 kmoco2am