Skip to content

Commit abb6f9a

Browse files
authored
Show message in HTML report when analyzed class does not match executed (bazel-contrib#819)
1 parent c7d70c7 commit abb6f9a

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

org.jacoco.doc/docroot/doc/changes.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ <h3>New Features</h3>
3939
(GitHub <a href="https://github.com/jacoco/jacoco/issues/801">#801</a>).</li>
4040
<li>HTML report shows message when class has no debug information
4141
(GitHub <a href="https://github.com/jacoco/jacoco/issues/818">#818</a>).</li>
42+
<li>HTML report shows message when analyzed class does not match executed
43+
(GitHub <a href="https://github.com/jacoco/jacoco/issues/819">#819</a>).</li>
4244
</ul>
4345

4446
<h3>Fixed Bugs</h3>

org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ClassPageTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,20 @@ public void should_generate_message_when_no_lines() throws Exception {
133133
support.findStr(doc, "/html/body/p[1]"));
134134
}
135135

136+
@Test
137+
public void should_generate_message_when_class_id_mismatch()
138+
throws Exception {
139+
node = new ClassCoverageImpl("Foo", 123, true);
140+
node.addMethod(new MethodCoverageImpl("m", "()V", null));
141+
142+
page = new ClassPage(node, null, new SourceLink(), rootFolder, context);
143+
page.render();
144+
145+
final Document doc = support.parse(output.getFile("Foo.html"));
146+
assertEquals("A different version of class was executed at runtime.",
147+
support.findStr(doc, "/html/body/p[1]"));
148+
}
149+
136150
private class SourceLink implements ILinkable {
137151

138152
public String getLink(final ReportOutputFolder base) {

org.jacoco.report/src/org/jacoco/report/internal/html/page/ClassPage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ public String getLinkLabel() {
8383

8484
@Override
8585
protected void content(HTMLElement body) throws IOException {
86+
if (getNode().isNoMatch()) {
87+
body.p().text(
88+
"A different version of class was executed at runtime.");
89+
}
90+
8691
if (getNode().getLineCounter().getTotalCount() == 0) {
8792
body.p().text(
8893
"Class files must be compiled with debug information to show line coverage.");

0 commit comments

Comments
 (0)