Bachmann1234 / diff_cover

Automatically find diff lines that need test coverage.
Apache License 2.0
710 stars 191 forks source link

excute: diff-cover jacoco.xml --html-report report.html ;eroor #123

Open xA11en opened 5 years ago

xA11en commented 5 years ago

excute result message : Diff Coverage Diff: origin/master...HEAD, staged and unstaged changes

No lines with coverage information in this diff.

why ??? path i am sure it is right

YellRiv commented 4 years ago

hi ,do you solve ?

wozhangdale commented 4 years ago

i have same question,but i cold not find answer

jacksonpradolima commented 4 years ago

+1

Bachmann1234 commented 4 years ago

I have nothing to go on with this bug. I would need some details or an example project that reproduces this behavior to solve it.

jacksonpradolima commented 4 years ago

Hi @Bachmann1234

I applied the diff-cover in the alibaba/druid repository after to run the JaCoCo version 0.8.5 in the last commit (hash f95f1c6436e45b9237b76972b879ef3bb28d8758).

To reproduce the problem, you can run the following commands:

1) Clone the repository:

git clone https://github.com/alibaba/druid.git

2) Run JaCoCo to get the coverage:

mvn -DargLine="-javaagent:/path/to/jacocoagent.jar" test

3) Prepare the report:

java -jar /path/to/jacococli.jar report /path/to/druid/jacoco.exec --classfiles /path/to/druid/target/classes/ --sourcefiles /path/to/druid/src/ --xml jacoco_coverage.xml

4) Using diff-cover:

diff-cover jacoco_coverage.xml 

5) Output received:

-------------
Diff Coverage
Diff: origin/master...HEAD, staged and unstaged changes
-------------
No lines with coverage information in this diff.
-------------

Thanks for your time

Bachmann1234 commented 4 years ago

@jacksonpradolima

Im getting build failures. However, if you send me a generated jacoco_coverage.xml file I can work with that.

That being said, this is a java project. I suspect the paths in the xml are not lining up with the src in the repo. I bet you just need to set a source root with --src-roots

 [INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  45.377 s
[INFO] Finished at: 2020-05-21T21:27:07-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project druid: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/bachmann/Desktop/druid/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd /Users/bachmann/Desktop/druid && /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/bin/java -javaagent:/path/to/jacocoagent.jar -jar /Users/bachmann/Desktop/druid/target/surefire/surefirebooter1276384889884421659.jar /Users/bachmann/Desktop/druid/target/surefire 2020-05-21T21-27-06_745-jvmRun1 surefire7104149109938258917tmp surefire_04740071354666419643tmp
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd /Users/bachmann/Desktop/druid && /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/bin/java -javaagent:/path/to/jacocoagent.jar -jar /Users/bachmann/Desktop/druid/target/surefire/surefirebooter1276384889884421659.jar /Users/bachmann/Desktop/druid/target/surefire 2020-05-21T21-27-06_745-jvmRun1 surefire7104149109938258917tmp surefire_04740071354666419643tmp
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
jacksonpradolima commented 4 years ago

@Bachmann1234

This is a part from entire file and it allows to reproduce the output. I don't know if you need the entire file.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE report
  PUBLIC '-//JACOCO//DTD Report 1.1//EN'
  'report.dtd'>
<report name="JaCoCo Coverage Report">
    <sessioninfo dump="1590081345069" id="node-0.tcpci.ch-geni-net.instageni.utc.edu-7a01ebe1" start="1590081268802"/>
    <package name="com/alibaba/druid/support/jconsole">
        <class name="com/alibaba/druid/support/jconsole/DruidDataSourcePanel" sourcefilename="DruidDataSourcePanel.java">
            <method desc="()V" line="70" name="&lt;init&gt;">
                <counter covered="0" missed="6" type="INSTRUCTION"/>
                <counter covered="0" missed="3" type="LINE"/>
                <counter covered="0" missed="1" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <method desc="(Lcom/alibaba/druid/support/jconsole/util/TableDataProcessor$ColumnData;)V" line="76" name="addTable">
                <counter covered="0" missed="80" type="INSTRUCTION"/>
                <counter covered="0" missed="2" type="BRANCH"/>
                <counter covered="0" missed="17" type="LINE"/>
                <counter covered="0" missed="2" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <method desc="(Ljava/util/ArrayList;)V" line="101" name="tableDataProcess">
                <counter covered="0" missed="23" type="INSTRUCTION"/>
                <counter covered="0" missed="5" type="LINE"/>
                <counter covered="0" missed="1" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <counter covered="0" missed="109" type="INSTRUCTION"/>
            <counter covered="0" missed="2" type="BRANCH"/>
            <counter covered="0" missed="25" type="LINE"/>
            <counter covered="0" missed="4" type="COMPLEXITY"/>
            <counter covered="0" missed="3" type="METHOD"/>
            <counter covered="0" missed="1" type="CLASS"/>
        </class>
        <class name="com/alibaba/druid/support/jconsole/DruidPlugin$1" sourcefilename="DruidPlugin.java">
            <method desc="(Lcom/alibaba/druid/support/jconsole/DruidPlugin;)V" line="43" name="&lt;init&gt;">
                <counter covered="0" missed="6" type="INSTRUCTION"/>
                <counter covered="0" missed="1" type="LINE"/>
                <counter covered="0" missed="1" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <method desc="()Ljava/lang/Object;" line="47" name="doInBackground">
                <counter covered="0" missed="4" type="INSTRUCTION"/>
                <counter covered="0" missed="1" type="LINE"/>
                <counter covered="0" missed="1" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <counter covered="0" missed="10" type="INSTRUCTION"/>
            <counter covered="0" missed="2" type="LINE"/>
            <counter covered="0" missed="2" type="COMPLEXITY"/>
            <counter covered="0" missed="2" type="METHOD"/>
            <counter covered="0" missed="1" type="CLASS"/>
        </class>
        <class name="com/alibaba/druid/support/jconsole/DruidPlugin" sourcefilename="DruidPlugin.java">
            <method desc="()V" line="28" name="&lt;init&gt;">
                <counter covered="0" missed="32" type="INSTRUCTION"/>
                <counter covered="0" missed="6" type="LINE"/>
                <counter covered="0" missed="1" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <method desc="()Ljava/util/Map;" line="38" name="getTabs">
                <counter covered="0" missed="3" type="INSTRUCTION"/>
                <counter covered="0" missed="1" type="LINE"/>
                <counter covered="0" missed="1" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <method desc="()Ljavax/swing/SwingWorker;" line="43" name="newSwingWorker">
                <counter covered="0" missed="7" type="INSTRUCTION"/>
                <counter covered="0" missed="2" type="LINE"/>
                <counter covered="0" missed="1" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <method desc="()Ljava/lang/Object;" line="55" name="doInBackground">
                <counter covered="0" missed="21" type="INSTRUCTION"/>
                <counter covered="0" missed="2" type="BRANCH"/>
                <counter covered="0" missed="4" type="LINE"/>
                <counter covered="0" missed="2" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <counter covered="0" missed="63" type="INSTRUCTION"/>
            <counter covered="0" missed="2" type="BRANCH"/>
            <counter covered="0" missed="13" type="LINE"/>
            <counter covered="0" missed="5" type="COMPLEXITY"/>
            <counter covered="0" missed="4" type="METHOD"/>
            <counter covered="0" missed="1" type="CLASS"/>
        </class>
        <class name="com/alibaba/druid/support/jconsole/DruidPanel" sourcefilename="DruidPanel.java">
            <method desc="(J)V" line="76" name="&lt;init&gt;">
                <counter covered="0" missed="6" type="INSTRUCTION"/>
                <counter covered="0" missed="3" type="LINE"/>
                <counter covered="0" missed="1" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <method desc="()V" line="83" name="&lt;init&gt;">
                <counter covered="0" missed="6" type="INSTRUCTION"/>
                <counter covered="0" missed="3" type="LINE"/>
                <counter covered="0" missed="1" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <method desc="(Ljava/lang/String;)V" line="105" name="addOrRefreshTable">
                <counter covered="0" missed="143" type="INSTRUCTION"/>
                <counter covered="0" missed="10" type="BRANCH"/>
                <counter covered="0" missed="32" type="LINE"/>
                <counter covered="0" missed="6" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <method desc="(Lcom/sun/tools/jconsole/JConsoleContext;)Ljava/lang/Object;" line="175" name="doInBackground">
                <counter covered="0" missed="6" type="INSTRUCTION"/>
                <counter covered="0" missed="2" type="LINE"/>
                <counter covered="0" missed="1" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <method desc="(Ljavax/management/MBeanServerConnection;)V" line="181" name="doInBackground">
                <counter covered="0" missed="20" type="INSTRUCTION"/>
                <counter covered="0" missed="2" type="BRANCH"/>
                <counter covered="0" missed="9" type="LINE"/>
                <counter covered="0" missed="2" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <method desc="()V" line="69" name="&lt;clinit&gt;">
                <counter covered="0" missed="4" type="INSTRUCTION"/>
                <counter covered="0" missed="1" type="LINE"/>
                <counter covered="0" missed="1" type="COMPLEXITY"/>
                <counter covered="0" missed="1" type="METHOD"/>
            </method>
            <counter covered="0" missed="185" type="INSTRUCTION"/>
            <counter covered="0" missed="12" type="BRANCH"/>
            <counter covered="0" missed="50" type="LINE"/>
            <counter covered="0" missed="12" type="COMPLEXITY"/>
            <counter covered="0" missed="6" type="METHOD"/>
            <counter covered="0" missed="1" type="CLASS"/>
        </class>
    </package>
    <counter covered="258966" missed="90893" type="INSTRUCTION"/>
    <counter covered="26780" missed="15686" type="BRANCH"/>
    <counter covered="68260" missed="22768" type="LINE"/>
    <counter covered="23887" missed="16345" type="COMPLEXITY"/>
    <counter covered="13830" missed="4988" type="METHOD"/>
    <counter covered="995" missed="128" type="CLASS"/>
</report>
Bachmann1234 commented 4 years ago

Hmm, it looks like diff cover is not parsing the xml correctly. Im not 100% sure what the fix is. I wonder if @peterg79 is around. He wrote the PR around this and may have better insight.

peterg79 commented 4 years ago

@jacksonpradolima diff-cover needs you to be on a branch which actually differs from master. Otherwise there will be no diff, so diff-cover's output will be empty (even if the coverage file is successfully parsed). If you're on a branch, please attach the diff. The best would be if you can point me to a pull request.

hurenjie2019 commented 3 years ago

+1, I have same question , could not solve this

peterg79 commented 3 years ago

@hurenjie2019 Please attach the output of diff-cover, the output of git diff, and jacoco_coverage.xml. In most cases this happens if you run diff-cover on master branch - eventually, it will not find any differences.

hurenjie2019 commented 3 years ago

Hi, @peterg79

  1. diff-cover report/index.html --html-report report.html --compare-branch=origin/master

    Diff Coverage Diff: origin/master...HEAD, staged and unstaged changes

    No lines with coverage information in this diff.

  2. git diff origin/master diff --git a/**.css b/**.css index ee1c9c82c0..3a05064201 100644 --- a/.css +++ b/**.css @@ -143,7 +143,7 @@ body.pageOneSpecial { transform: translate(0, -50%); / }

... really a lot of diff. and I am sure the current branch is test branch.

  1. jacoco_coverage.xml is normal.

Origin file is not allowed to be shared due to company policy. Thanks a lot.

hdw868 commented 2 years ago

same issue here

peterg79 commented 2 years ago

@hurenjie2019 there's no code coverage implemented for css files, as they are style sheets, not program code.

@hdw868 please attach some files: the coverage xml file, and the git diff (if your company policy does not let you attach, you can do git diff --name-only).

Most of the cases it simply means the coverage data and the diff is mutually exclusive. E.g. you measure coverage for your *.java source files, but you changed a lot of other file types (.xml, .css, *.html, ...).

hdw868 commented 2 years ago

@peterg79 the coverage.xml: it's exceeding 65535 characters and I can not paste it here. maybe I can paste only part of the content based on the below info? git diff --name-only:

src/oceanus2/datacenter/cdn/data_common.go
src/oceanus2/datacenter/cdn/data_common_test.go
src/oceanus2/model/cdn/cell.go
src/oceanus2/model/cdn/station.go
peterg79 commented 2 years ago

@hdw868 please add the output of the following commands: xmllint --format coverage.xml | head xmllint --format coverage.xml | grep 'source\|src'

hdw868 commented 2 years ago

@peterg79 output of xmllint --format coverage.xml | head:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage line-rate="0.2408197" branch-rate="0" lines-covered="1751" lines-valid="7271" branches-covered="0" branches-valid="0" complexity="0" version="" timestamp="1638777063916">
        <packages>
                <package name="oceanus2/base/dumper" line-rate="0.023323616" branch-rate="0" complexity="0" line-count="686" line-hits="16">
                        <classes>
                                <class name="DnsMappingDumperConf" filename="src/oceanus2/base/dumper/dns_mapping_dumper.go" line-rate="0" branch-rate="0" complexity="0" line-count="17" line-hits="0">
                                        <methods>
                                                <method name="Valid" signature="" line-rate="0" branch-rate="0" complexity="0" line-count="0" line-hits="0">
                                                        <lines>

for output of xmllint --format coverage.xml | grep 'source\|src', as the result will be too sensitive to post here, could you tell me what kind of data are you looking for? I can see none of the files listed for the output of git diff --name-only could be found here.

Bachmann1234 commented 2 years ago

I mean, ideally some thing someone here could use to reproduce the issue ourselves.

In the past I've made small repos demonstrating the issue. Really makes it easier to pin down whats happening.

peterg79 commented 2 years ago

First I want to see that the list of files changed, and the list of files having coverage information overlaps. If they do, I'd like to see the line numbers.

If your data is too sensitive you cannot share, then you'll need to be more involved. Either by demonstrating the issue with a small, public repository, or do the debugging yourself: validate if there's overlapping file/line pairs in the diff and coverage data.

The output "No lines with coverage information in this diff." practically means that the two sets of data is mutually exclusive, in which case the tool cannot give you any information.

So far 100% of the cases I've seen at my workplace, were closed as a non-issue, as there was no overlap. Some of them was caused by partial or stale coverage data file. Some were due to people were running diff cover against the unmodified master branch, which resulted (eventually) an empty git diff report.

It can also happen that you use an older version of the coverage tool, or the file path extracted from your coverage file is wrong. It can happen if your coverage is generated from a subdirectory; like your git diff lists the following files:

src/oceanus2/datacenter/cdn/data_common.go
src/oceanus2/datacenter/cdn/data_common_test.go
src/oceanus2/model/cdn/cell.go
src/oceanus2/model/cdn/station.go

and your coverage file references them as follows:

oceanus2/datacenter/cdn/data_common.go
oceanus2/datacenter/cdn/data_common_test.go
oceanus2/model/cdn/cell.go
oceanus2/model/cdn/station.go

In your case @hdw868 , my suspect is the former (git diff and coverage data is mutually exclusive), as I see the top of the coverage report and file paths seem to be correct.

@Bachmann1234 maybe there should be some debug options to the tool to dump basic information, like list of files from the diff and the coverage report.

hdw868 commented 2 years ago

@peterg79 thanks for the detailed response! One thing not clear to me is that: The output "No lines with coverage information in this diff." practically means that the two sets of data are mutually exclusive, in which case the tool cannot give you any information.

If no lines with coverage information in this diff, should not the coverage result be 0%? Is it because that even no unit test is written for the src file, the coverage information should still be collected? Any document explains the underlying mechanism of diff coverage, I may try to debug on my own.

peterg79 commented 2 years ago

The coverage file has coverage info for your whole repository, so the overall coverage can be any percentage.

e.g. if you have 100% coverage for sole of your files, like src1.go and src2.go, and you add a new file called src3.go but your coverage data is unchanged, this is what you'll have: git diff --name-only:

src3.go

coverage.xml:


<coverage>
  <packages>
    <package name=".">
      <classes>
        <class name="src1" filename="src1.go" line-rate="100">
        <class name="src2" filename="src1.go" line-rate="100">
      </classes>
    </package>
  </packages>
 </coverage>

most coverage tools would automatically pick up the new file and report it with 0 coverage, but it may be platform dependent. It could also happen that a file is an empty skeleton, and the file is there, but coverage tool did not identify any source lines there. One case could be if you remove an unused java import. It's hard to have any meaningful guesses without more visibility into your data.