Skip to content

Commit

Permalink
Refactor: Log failing test when using JacocoCoverageExecutor instead …
Browse files Browse the repository at this point in the history
…of suddenly crash (#244)
  • Loading branch information
danglotb authored Nov 8, 2017
1 parent 0a54ded commit 9fb2967
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions dspot/src/main/java/fr/inria/stamp/coverage/JacocoExecutor.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -131,8 +138,12 @@ public Map<String, CoverageResults> 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);
Expand Down

0 comments on commit 9fb2967

Please sign in to comment.