aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Mandrikov <138671+Godin@users.noreply.github.com>2019-01-06 13:42:49 +0100
committerGitHub <noreply@github.com>2019-01-06 13:42:49 +0100
commitc7d70c7b0be325e84b9c98203e3e99946ac8bfcd (patch)
tree7d605325b0641f4841b137b8a120e76f1ad0c700
parent3718bd939efb0bb0d7b8729b1f05aac65b4333d6 (diff)
downloadplatform_external_jacoco-c7d70c7b0be325e84b9c98203e3e99946ac8bfcd.tar.gz
platform_external_jacoco-c7d70c7b0be325e84b9c98203e3e99946ac8bfcd.tar.bz2
platform_external_jacoco-c7d70c7b0be325e84b9c98203e3e99946ac8bfcd.zip
Show messages in HTML report when class has no debug information (#818)
-rw-r--r--org.jacoco.doc/docroot/doc/changes.html2
-rw-r--r--org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ClassPageTest.java29
-rw-r--r--org.jacoco.report/src/org/jacoco/report/internal/html/page/ClassPage.java16
3 files changed, 40 insertions, 7 deletions
diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html
index 59de7915..36acc8b6 100644
--- a/org.jacoco.doc/docroot/doc/changes.html
+++ b/org.jacoco.doc/docroot/doc/changes.html
@@ -37,6 +37,8 @@
<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>
diff --git a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ClassPageTest.java b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ClassPageTest.java
index 7126f93e..b174fb29 100644
--- a/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ClassPageTest.java
+++ b/org.jacoco.report.test/src/org/jacoco/report/internal/html/page/ClassPageTest.java
@@ -17,6 +17,7 @@ import java.io.IOException;
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;
@@ -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));
}
@@ -61,13 +64,15 @@ public class ClassPageTest extends PageTestBase {
}
@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
@@ -87,8 +92,10 @@ public class ClassPageTest extends PageTestBase {
@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);
@@ -112,6 +119,20 @@ public class ClassPageTest extends PageTestBase {
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) {
diff --git a/org.jacoco.report/src/org/jacoco/report/internal/html/page/ClassPage.java b/org.jacoco.report/src/org/jacoco/report/internal/html/page/ClassPage.java
index 2c35a11b..f297daa4 100644
--- a/org.jacoco.report/src/org/jacoco/report/internal/html/page/ClassPage.java
+++ b/org.jacoco.report/src/org/jacoco/report/internal/html/page/ClassPage.java
@@ -83,12 +83,22 @@ public class ClassPage extends TablePage<IClassCoverage> {
@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.");