Skip to content

Commit

Permalink
auto set -ea for #1322
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoles committed Apr 8, 2024
1 parent a6a4eec commit 8d9b041
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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";
}

}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.pitest.mutationtest.autoconfig.KeepMacOsFocus
org.pitest.mutationtest.autoconfig.AutoSetThreads
org.pitest.mutationtest.autoconfig.AutoSetThreads
org.pitest.mutationtest.autoconfig.EnableAssertions
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 8d9b041

Please sign in to comment.