Skip to content

Commit

Permalink
Show messages in HTML report when class has no debug information (baz…
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin authored Jan 6, 2019
1 parent 3718bd9 commit c7d70c7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
2 changes: 2 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ <h3>New Features</h3>
<a href="https://github.com/jacoco/jacoco/issues/809">#809</a>).</li>
<li>HTML report shows message when source file can't be found
(GitHub <a href="https://github.com/jacoco/jacoco/issues/801">#801</a>).</li>
<li>HTML report shows message when class has no debug information
(GitHub <a href="https://github.com/jacoco/jacoco/issues/818">#818</a>).</li>
</ul>

<h3>Fixed Bugs</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.jacoco.core.analysis.IClassCoverage;
import org.jacoco.core.internal.analysis.ClassCoverageImpl;
import org.jacoco.core.internal.analysis.CounterImpl;
import org.jacoco.core.internal.analysis.MethodCoverageImpl;
import org.jacoco.report.internal.ReportOutputFolder;
import org.jacoco.report.internal.html.ILinkable;
Expand All @@ -37,8 +38,10 @@ public class ClassPageTest extends PageTestBase {
@Override
public void setup() throws Exception {
super.setup();
final MethodCoverageImpl m = new MethodCoverageImpl("a", "()V", null);
m.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 42);
node = new ClassCoverageImpl("org/jacoco/example/Foo", 123, false);
node.addMethod(new MethodCoverageImpl("a", "()V", null));
node.addMethod(m);
node.addMethod(new MethodCoverageImpl("b", "()V", null));
node.addMethod(new MethodCoverageImpl("c", "()V", null));
}
Expand All @@ -61,13 +64,15 @@ public void testContents() throws Exception {
}

@Test
public void should_not_generate_message_when_SourceFileName_not_present()
public void should_generate_message_when_SourceFileName_not_present()
throws Exception {
page = new ClassPage(node, null, null, rootFolder, context);
page.render();

final Document doc = support.parse(output.getFile("Foo.html"));
assertEquals("", support.findStr(doc, "/html/body/p[1]"));
assertEquals(
"Class files must be compiled with debug information to link with source files.",
support.findStr(doc, "/html/body/p[1]"));
}

@Test
Expand All @@ -87,8 +92,10 @@ public void should_generate_message_when_SourceFileName_present_but_no_SourceFil
@Test
public void should_generate_message_with_default_package_when_SourceFileName_present_but_no_SourceFilePage()
throws Exception {
final MethodCoverageImpl m = new MethodCoverageImpl("a", "()V", null);
m.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 42);
node = new ClassCoverageImpl("Foo", 123, false);
node.addMethod(new MethodCoverageImpl("a", "()V", null));
node.addMethod(m);
node.setSourceFileName("Foo.java");

page = new ClassPage(node, null, null, rootFolder, context);
Expand All @@ -112,6 +119,20 @@ public void should_not_generate_message_when_SourceFileName_and_SourceFilePage_p
assertEquals("", support.findStr(doc, "/html/body/p[1]"));
}

@Test
public void should_generate_message_when_no_lines() throws Exception {
node = new ClassCoverageImpl("Foo", 123, false);
node.addMethod(new MethodCoverageImpl("m", "()V", null));

page = new ClassPage(node, null, new SourceLink(), rootFolder, context);
page.render();

final Document doc = support.parse(output.getFile("Foo.html"));
assertEquals(
"Class files must be compiled with debug information to show line coverage.",
support.findStr(doc, "/html/body/p[1]"));
}

private class SourceLink implements ILinkable {

public String getLink(final ReportOutputFolder base) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,22 @@ public String getLinkLabel() {

@Override
protected void content(HTMLElement body) throws IOException {
if (getNode().getSourceFileName() != null && sourcePage == null) {
if (getNode().getLineCounter().getTotalCount() == 0) {
body.p().text(
"Class files must be compiled with debug information to show line coverage.");
}

final String sourceFileName = getNode().getSourceFileName();
if (sourceFileName == null) {
body.p().text(
"Class files must be compiled with debug information to link with source files.");

} else if (sourcePage == null) {
final String sourcePath;
if (getNode().getPackageName().length() != 0) {
sourcePath = getNode().getPackageName() + "/" + getNode().getSourceFileName();
sourcePath = getNode().getPackageName() + "/" + sourceFileName;
} else {
sourcePath = getNode().getSourceFileName();
sourcePath = sourceFileName;
}
body.p().text("Source file \"" + sourcePath
+ "\" was not found during generation of report.");
Expand Down

0 comments on commit c7d70c7

Please sign in to comment.