From 9fb2967b9e47edbd781496ebf6e2c0e3ef72d1d9 Mon Sep 17 00:00:00 2001 From: Benjamin DANGLOT Date: Wed, 8 Nov 2017 14:17:56 +0100 Subject: [PATCH] Refactor: Log failing test when using JacocoCoverageExecutor instead of suddenly crash (#244) --- .../inria/stamp/coverage/JacocoExecutor.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/dspot/src/main/java/fr/inria/stamp/coverage/JacocoExecutor.java b/dspot/src/main/java/fr/inria/stamp/coverage/JacocoExecutor.java index dbb20c463..5801aa24f 100644 --- a/dspot/src/main/java/fr/inria/stamp/coverage/JacocoExecutor.java +++ b/dspot/src/main/java/fr/inria/stamp/coverage/JacocoExecutor.java @@ -1,5 +1,6 @@ package fr.inria.stamp.coverage; +import fr.inria.diversify.utils.AmplificationHelper; import fr.inria.diversify.utils.sosiefier.InputConfiguration; import fr.inria.diversify.utils.sosiefier.InputProgram; import fr.inria.stamp.test.launcher.TestLauncher; @@ -14,6 +15,7 @@ import org.jacoco.core.runtime.IRuntime; import org.jacoco.core.runtime.LoggerRuntime; import org.jacoco.core.runtime.RuntimeData; +import org.junit.runner.notification.Failure; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import spoon.reflect.declaration.CtType; @@ -26,6 +28,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.Map; +import java.util.stream.Collectors; import static java.util.ResourceBundle.clearCache; @@ -97,8 +100,12 @@ public CoverageResults executeJacoco(CtType testClass) { runtime.startup(data); final TestListener listener = TestLauncher.run(this.configuration, this.internalClassLoader, testClass); if (!listener.getFailingTests().isEmpty()) { - listener.getFailingTests().forEach(System.out::println); - throw new RuntimeException("Error: some test fail when computing the coverage."); + LOGGER.warn("Some test(s) failed during computation of coverage:" + AmplificationHelper.LINE_SEPARATOR + + listener.getFailingTests() + .stream() + .map(Failure::toString) + .collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR)) + ); } data.collect(executionData, sessionInfos, false); runtime.shutdown(); @@ -131,8 +138,12 @@ public Map executeJacoco(CtType testClass, Collectio final JacocoListener jacocoListener = new JacocoListener(data, classesDirectory); final TestListener listener = TestLauncher.run(this.configuration, this.internalClassLoader, testClass, methodNames, jacocoListener); if (!listener.getFailingTests().isEmpty()) { - listener.getFailingTests().forEach(System.out::println); - throw new RuntimeException("Error: some test fail when computing the coverage."); + LOGGER.warn("Some test(s) failed during computation of coverage:" + AmplificationHelper.LINE_SEPARATOR + + listener.getFailingTests() + .stream() + .map(Failure::toString) + .collect(Collectors.joining(AmplificationHelper.LINE_SEPARATOR)) + ); } this.runtime.shutdown(); clearCache(this.internalClassLoader);