Skip to content

Commit

Permalink
Anonymous functions in Scala should not be filtered out (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin authored and marchof committed Jul 28, 2019
1 parent 7a32ae3 commit 81ba87b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
@@ -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);
}

}
@@ -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()
})

}

}
Expand Up @@ -56,6 +56,17 @@ public void testLambda() {
assertIgnored();
}

@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,
Expand Down
Expand Up @@ -29,6 +29,10 @@ public void filter(final MethodNode methodNode,
return;
}

if (methodNode.name.startsWith("$anonfun$")) {
return;
}

if (KotlinGeneratedFilter.isKotlinClass(context)) {
if (KotlinDefaultArgumentsFilter
.isDefaultArgumentsMethod(methodNode)) {
Expand Down
3 changes: 3 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Expand Up @@ -40,6 +40,9 @@ <h3>Fixed bugs</h3>
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>
Expand Down

0 comments on commit 81ba87b

Please sign in to comment.