Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anonymous functions in Scala should not be filtered out #912

Merged
merged 4 commits into from Jul 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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