aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Mandrikov <138671+Godin@users.noreply.github.com>2019-07-28 21:30:00 +0200
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2019-07-28 21:30:00 +0200
commit81ba87bbfa01233608a5fe771017e1015c16fdae (patch)
tree6381591b37a505b34d3b6bb656e3f9b940ca86cc
parent7a32ae362997d20141f59ceb119563287c2485e9 (diff)
downloadjacoco-81ba87bbfa01233608a5fe771017e1015c16fdae.tar.gz
Anonymous functions in Scala should not be filtered out (#912)
-rw-r--r--org.jacoco.core.test.validation.scala/src/org/jacoco/core/test/validation/scala/ScalaAnonymousFunctionTest.java26
-rw-r--r--org.jacoco.core.test.validation.scala/src/org/jacoco/core/test/validation/scala/targets/ScalaAnonymousFunctionTarget.scala33
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java11
-rw-r--r--org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/SyntheticFilter.java4
-rw-r--r--org.jacoco.doc/docroot/doc/changes.html3
5 files changed, 77 insertions, 0 deletions
diff --git a/org.jacoco.core.test.validation.scala/src/org/jacoco/core/test/validation/scala/ScalaAnonymousFunctionTest.java b/org.jacoco.core.test.validation.scala/src/org/jacoco/core/test/validation/scala/ScalaAnonymousFunctionTest.java
new file mode 100644
index 00000000..676e3d99
--- /dev/null
+++ b/org.jacoco.core.test.validation.scala/src/org/jacoco/core/test/validation/scala/ScalaAnonymousFunctionTest.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Evgeny Mandrikov - initial API and implementation
+ *
+ *******************************************************************************/
+package org.jacoco.core.test.validation.scala;
+
+import org.jacoco.core.test.validation.ValidationTestBase;
+import org.jacoco.core.test.validation.scala.targets.ScalaAnonymousFunctionTarget;
+
+/**
+ * Test of anonymous functions.
+ */
+public class ScalaAnonymousFunctionTest extends ValidationTestBase {
+
+ public ScalaAnonymousFunctionTest() {
+ super(ScalaAnonymousFunctionTarget.class);
+ }
+
+}
diff --git a/org.jacoco.core.test.validation.scala/src/org/jacoco/core/test/validation/scala/targets/ScalaAnonymousFunctionTarget.scala b/org.jacoco.core.test.validation.scala/src/org/jacoco/core/test/validation/scala/targets/ScalaAnonymousFunctionTarget.scala
new file mode 100644
index 00000000..02fefc52
--- /dev/null
+++ b/org.jacoco.core.test.validation.scala/src/org/jacoco/core/test/validation/scala/targets/ScalaAnonymousFunctionTarget.scala
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Evgeny Mandrikov - initial API and implementation
+ *
+ *******************************************************************************/
+package org.jacoco.core.test.validation.scala.targets
+
+import org.jacoco.core.test.validation.targets.Stubs.{exec, noexec, nop}
+
+/**
+ * Test target for anonymous functions.
+ */
+object ScalaAnonymousFunctionTarget {
+
+ def main(args: Array[String]): Unit = {
+
+ exec(() => {
+ nop() // assertFullyCovered()
+ })
+
+ noexec(() => {
+ nop() // assertNotCovered()
+ })
+
+ }
+
+}
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java
index 5b0a30ba..01b074ef 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java
@@ -57,6 +57,17 @@ public class SyntheticFilterTest extends FilterTestBase {
}
@Test
+ public void should_not_filter_Scala_anonymous_functions() {
+ final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
+ Opcodes.ACC_SYNTHETIC, "$anonfun$main$1", "()V", null, null);
+ m.visitInsn(Opcodes.RETURN);
+
+ filter.filter(m, context, output);
+
+ assertIgnored();
+ }
+
+ @Test
public void should_not_filter_method_with_suffix_default_in_kotlin_classes() {
final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
Opcodes.ACC_SYNTHETIC | Opcodes.ACC_BRIDGE, "example$default",
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/SyntheticFilter.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/SyntheticFilter.java
index 46d4e6eb..87dde91a 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/SyntheticFilter.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/SyntheticFilter.java
@@ -29,6 +29,10 @@ public final class SyntheticFilter implements IFilter {
return;
}
+ if (methodNode.name.startsWith("$anonfun$")) {
+ return;
+ }
+
if (KotlinGeneratedFilter.isKotlinClass(context)) {
if (KotlinDefaultArgumentsFilter
.isDefaultArgumentsMethod(methodNode)) {
diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html
index a8e69ce1..acc114f2 100644
--- a/org.jacoco.doc/docroot/doc/changes.html
+++ b/org.jacoco.doc/docroot/doc/changes.html
@@ -40,6 +40,9 @@
and containing arguments of type <code>long</code> or <code>double</code>
should be filtered out during generation of report
(GitHub <a href="https://github.com/jacoco/jacoco/issues/908">#908</a>).</li>
+ <li><code>synthetic</code> methods that contain bodies of anonymous functions
+ in Scala should not be ignored
+ (GitHub <a href="https://github.com/jacoco/jacoco/issues/912">#921</a>).</li>
</ul>
<h2>Release 0.8.4 (2019/05/08)</h2>