From 9cddeda15e3f142cdf2374a20533c7bf8ba80f58 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 31 Jan 2020 09:07:52 +0100 Subject: [PATCH 1/4] (WIP) add validation test --- .../kotlin/KotlinDelegatesTest.java | 27 +++++++++++++++++++ .../kotlin/targets/KotlinDelegatesTarget.kt | 27 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinDelegatesTest.java create mode 100644 org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDelegatesTarget.kt diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinDelegatesTest.java b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinDelegatesTest.java new file mode 100644 index 0000000000..895bf89b50 --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/KotlinDelegatesTest.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2009, 2020 Mountainminds GmbH & Co. KG and Contributors + * This program and the accompanying materials are made available under + * the terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin; + +import org.jacoco.core.test.validation.ValidationTestBase; +import org.jacoco.core.test.validation.kotlin.targets.KotlinDelegatesTarget; + +/** + * Test of code coverage in {@link KotlinDelegatesTarget}. + */ +public class KotlinDelegatesTest extends ValidationTestBase { + + public KotlinDelegatesTest() { + super(KotlinDelegatesTarget.class); + } + +} diff --git a/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDelegatesTarget.kt b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDelegatesTarget.kt new file mode 100644 index 0000000000..f61a808e1d --- /dev/null +++ b/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinDelegatesTarget.kt @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2009, 2020 Mountainminds GmbH & Co. KG and Contributors + * This program and the accompanying materials are made available under + * the terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.test.validation.kotlin.targets + +/** + * This test target contains different delegates. + */ +object KotlinDelegatesTarget { + + class DelegatedList : List by ArrayList() // assertFullyCovered() + + @JvmStatic + fun main(args: Array) { + DelegatedList() + } + +} From 8a0976eb90003c6728ab750f4d06ed05619445e5 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 31 Jan 2020 09:23:38 +0100 Subject: [PATCH 2/4] (WIP) add unit test --- .../analysis/filter/BridgeFilterTest.java | 49 +++++++++++++++++++ .../analysis/filter/BridgeFilter.java | 27 ++++++++++ 2 files changed, 76 insertions(+) create mode 100644 org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/BridgeFilterTest.java create mode 100644 org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/BridgeFilter.java diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/BridgeFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/BridgeFilterTest.java new file mode 100644 index 0000000000..b0dd1adc9a --- /dev/null +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/BridgeFilterTest.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2009, 2020 Mountainminds GmbH & Co. KG and Contributors + * This program and the accompanying materials are made available under + * the terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.internal.analysis.filter; + +import org.jacoco.core.internal.instr.InstrSupport; +import org.junit.Test; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.MethodNode; + +/** + * Unit tests for {@link BridgeFilter}. + */ +public class BridgeFilterTest extends FilterTestBase { + + private final BridgeFilter filter = new BridgeFilter(); + + @Test + public void should_filter_bridge_methods() { + final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, + Opcodes.ACC_BRIDGE, "m", "()Ljava/lang/Object;", null, null); + m.visitInsn(Opcodes.NOP); + + filter.filter(m, context, output); + + assertMethodIgnored(m); + } + + @Test + public void should_not_filter_non_bridge_methods() { + final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, + "m", "()Ljava/lang/Object;", null, null); + m.visitInsn(Opcodes.NOP); + + filter.filter(m, context, output); + + assertIgnored(); + } + +} diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/BridgeFilter.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/BridgeFilter.java new file mode 100644 index 0000000000..b823a5797c --- /dev/null +++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/BridgeFilter.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2009, 2020 Mountainminds GmbH & Co. KG and Contributors + * This program and the accompanying materials are made available under + * the terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Evgeny Mandrikov - initial API and implementation + * + *******************************************************************************/ +package org.jacoco.core.internal.analysis.filter; + +import org.objectweb.asm.tree.MethodNode; + +/** + * Filters bridge methods. + */ +final class BridgeFilter implements IFilter { + + public void filter(final MethodNode methodNode, + final IFilterContext context, final IFilterOutput output) { + // TODO + } + +} From c590a9281499ec6a726f160eb282d02896c91431 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 31 Jan 2020 09:24:09 +0100 Subject: [PATCH 3/4] (WIP) implement --- .../jacoco/core/internal/analysis/filter/BridgeFilter.java | 7 ++++++- .../org/jacoco/core/internal/analysis/filter/Filters.java | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/BridgeFilter.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/BridgeFilter.java index b823a5797c..78fe5ad66f 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/BridgeFilter.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/BridgeFilter.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.jacoco.core.internal.analysis.filter; +import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.MethodNode; /** @@ -21,7 +22,11 @@ final class BridgeFilter implements IFilter { public void filter(final MethodNode methodNode, final IFilterContext context, final IFilterOutput output) { - // TODO + if ((methodNode.access & Opcodes.ACC_BRIDGE) == 0) { + return; + } + output.ignore(methodNode.instructions.getFirst(), + methodNode.instructions.getLast()); } } diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/Filters.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/Filters.java index 3ceff7bfa0..bbe041f6f8 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/Filters.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/filter/Filters.java @@ -33,7 +33,8 @@ public final class Filters implements IFilter { */ public static IFilter all() { return new Filters(new EnumFilter(), new SyntheticFilter(), - new SynchronizedFilter(), new TryWithResourcesJavac11Filter(), + new BridgeFilter(), new SynchronizedFilter(), + new TryWithResourcesJavac11Filter(), new TryWithResourcesJavacFilter(), new TryWithResourcesEcjFilter(), new FinallyFilter(), new PrivateEmptyNoArgConstructorFilter(), From 78d03acad979cf8c2fc39f8cac160fffcf8c47c8 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Sat, 1 Feb 2020 08:12:42 +0100 Subject: [PATCH 4/4] (WIP) update changelog --- org.jacoco.doc/docroot/doc/changes.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html index 8049067ac3..da3817fc35 100644 --- a/org.jacoco.doc/docroot/doc/changes.html +++ b/org.jacoco.doc/docroot/doc/changes.html @@ -27,6 +27,8 @@

New Features

  • Methods toString, hashCode and equals generated by compiler for records are filtered out during generation of report (GitHub #990).
  • +
  • Bridge methods are filtered out during generation of report + (GitHub #1010).
  • Non-functional Changes