From 8d9b041c4befa00352d7d3df4bc2c818fe5b058b Mon Sep 17 00:00:00 2001 From: Henry Coles Date: Mon, 8 Apr 2024 12:36:52 +0100 Subject: [PATCH] auto set -ea for #1322 --- .../autoconfig/EnableAssertions.java | 34 +++++++++++++++++++ ...t.mutationtest.config.ConfigurationUpdater | 3 +- .../autoconfig/EnableAssertionsTest.java | 28 +++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 pitest-entry/src/main/java/org/pitest/mutationtest/autoconfig/EnableAssertions.java create mode 100644 pitest-entry/src/test/java/org/pitest/mutationtest/autoconfig/EnableAssertionsTest.java diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/autoconfig/EnableAssertions.java b/pitest-entry/src/main/java/org/pitest/mutationtest/autoconfig/EnableAssertions.java new file mode 100644 index 000000000..596b62654 --- /dev/null +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/autoconfig/EnableAssertions.java @@ -0,0 +1,34 @@ +package org.pitest.mutationtest.autoconfig; + +import org.pitest.mutationtest.config.ConfigurationUpdater; +import org.pitest.mutationtest.config.ReportOptions; +import org.pitest.plugin.Feature; +import org.pitest.plugin.FeatureSetting; + +import static java.util.Collections.singletonList; + +/** + * Gradle and maven both now automatically set the -ea flag to + * enable assertions when running tests. Pitest must therefore + * do it too. + */ +public class EnableAssertions implements ConfigurationUpdater { + + @Override + public void updateConfig(FeatureSetting conf, ReportOptions toModify) { + toModify.addChildJVMArgs(singletonList("-ea")); + } + + @Override + public Feature provides() { + return Feature.named("AUTO_ASSERTIONS") + .withOnByDefault(true) + .withDescription(description()); + } + + @Override + public String description() { + return "Automatically add -ea to launch args to enable assertions"; + } + +} \ No newline at end of file diff --git a/pitest-entry/src/main/resources/META-INF/services/org.pitest.mutationtest.config.ConfigurationUpdater b/pitest-entry/src/main/resources/META-INF/services/org.pitest.mutationtest.config.ConfigurationUpdater index 0779405dc..730d7debd 100644 --- a/pitest-entry/src/main/resources/META-INF/services/org.pitest.mutationtest.config.ConfigurationUpdater +++ b/pitest-entry/src/main/resources/META-INF/services/org.pitest.mutationtest.config.ConfigurationUpdater @@ -1,2 +1,3 @@ org.pitest.mutationtest.autoconfig.KeepMacOsFocus -org.pitest.mutationtest.autoconfig.AutoSetThreads \ No newline at end of file +org.pitest.mutationtest.autoconfig.AutoSetThreads +org.pitest.mutationtest.autoconfig.EnableAssertions \ No newline at end of file diff --git a/pitest-entry/src/test/java/org/pitest/mutationtest/autoconfig/EnableAssertionsTest.java b/pitest-entry/src/test/java/org/pitest/mutationtest/autoconfig/EnableAssertionsTest.java new file mode 100644 index 000000000..0b5564a20 --- /dev/null +++ b/pitest-entry/src/test/java/org/pitest/mutationtest/autoconfig/EnableAssertionsTest.java @@ -0,0 +1,28 @@ +package org.pitest.mutationtest.autoconfig; + +import org.junit.Test; +import org.pitest.mutationtest.config.ReportOptions; + +import static org.assertj.core.api.Assertions.assertThat; + +public class EnableAssertionsTest { + EnableAssertions underTest = new EnableAssertions(); + + @Test + public void addsEAFlag() { + ReportOptions data = new ReportOptions(); + + underTest.updateConfig(null, data); + assertThat(data.getJvmArgs()).contains("-ea"); + } + + @Test + public void featureIsNamedAutoAssertions() { + assertThat(underTest.provides().name()).isEqualTo("auto_assertions"); + } + + @Test + public void featureIsOnByDefault() { + assertThat(underTest.provides().isOnByDefault()).isTrue(); + } +} \ No newline at end of file