Skip to content

Commit

Permalink
Merge pull request #1078 from hcoles/feature/new_extension_points
Browse files Browse the repository at this point in the history
make feature settings available to config updaters
  • Loading branch information
hcoles committed Aug 22, 2022
2 parents 17e1eec + f6da752 commit b2b365d
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.pitest.mutationtest.config.ConfigurationUpdater;
import org.pitest.mutationtest.config.ReportOptions;
import org.pitest.plugin.Feature;
import org.pitest.plugin.FeatureSetting;
import org.pitest.util.Log;

import java.util.logging.Logger;
Expand All @@ -23,7 +24,7 @@ public class AutoSetThreads implements ConfigurationUpdater {
private static final Logger LOG = Log.getLogger();

@Override
public void updateConfig(ReportOptions toModify) {
public void updateConfig(FeatureSetting conf, ReportOptions toModify) {
// this will be wrong in some environments, feature best used
// only for local dev
int cores = getCores();
Expand Down Expand Up @@ -58,4 +59,5 @@ public String description() {
int getCores() {
return Runtime.getRuntime().availableProcessors();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;

Expand All @@ -13,7 +14,7 @@
public class KeepMacOsFocus implements ConfigurationUpdater {

@Override
public void updateConfig(ReportOptions toModify) {
public void updateConfig(FeatureSetting conf, ReportOptions toModify) {
toModify.addChildJVMArgs(singletonList("-Djava.awt.headless=true"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public CompoundConfigurationUpdater(List<FeatureSetting> features,
}

@Override
public void updateConfig(ReportOptions toModify) {
public void updateConfig(FeatureSetting unused, ReportOptions toModify) {
for (ConfigurationUpdater each : features.getActiveFeatures() ) {
each.updateConfig(toModify);
each.updateConfig(features.getSettingForFeature(each.provides().name()), toModify);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.pitest.mutationtest.config;

import org.pitest.plugin.FeatureSetting;
import org.pitest.plugin.ProvidesFeature;
import org.pitest.plugin.ToolClasspathPlugin;

public interface ConfigurationUpdater extends ToolClasspathPlugin, ProvidesFeature {
void updateConfig(ReportOptions toModify);
void updateConfig(FeatureSetting conf, ReportOptions toModify);

}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private List<String> createJvmArgs(ReportOptions data) {
}

private void updateData(ReportOptions data, SettingsFactory settings) {
settings.createUpdater().updateConfig(data);
settings.createUpdater().updateConfig(null, data);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.Test;
import org.pitest.mutationtest.config.ReportOptions;
import org.pitest.plugin.FeatureSetting;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -26,7 +27,7 @@ public void leavesNumberOfThreadsAs1IfOnly1Available() {
ReportOptions data = new ReportOptions();
reportedCores = 1;
data.setNumberOfThreads(1);
underTest.updateConfig(data);
underTest.updateConfig(unused(), data);
assertThat(data.getNumberOfThreads()).isEqualTo(1);
}

Expand All @@ -35,7 +36,7 @@ public void usesThreeThreadsWhen4CoresAvailable() {
ReportOptions data = new ReportOptions();
reportedCores = 4;
data.setNumberOfThreads(1);
underTest.updateConfig(data);
underTest.updateConfig(unused(), data);
assertThat(data.getNumberOfThreads()).isEqualTo(3);
}

Expand All @@ -44,7 +45,7 @@ public void usesFiveThreadsWhen8CoresAvailable() {
ReportOptions data = new ReportOptions();
reportedCores = 8;
data.setNumberOfThreads(1);
underTest.updateConfig(data);
underTest.updateConfig(unused(), data);
assertThat(data.getNumberOfThreads()).isEqualTo(5);
}

Expand All @@ -53,8 +54,12 @@ public void uses8CoresWhen12Available() {
ReportOptions data = new ReportOptions();
reportedCores = 12;
data.setNumberOfThreads(1);
underTest.updateConfig(data);
underTest.updateConfig(unused(), data);
assertThat(data.getNumberOfThreads()).isEqualTo(8);
}


private FeatureSetting unused() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.Test;
import org.pitest.mutationtest.config.ReportOptions;
import org.pitest.plugin.FeatureSetting;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -12,7 +13,7 @@ public class KeepMacOsFocusTest {
public void addsHeadlessTrueToJvmArgs() {
ReportOptions data = new ReportOptions();

underTest.updateConfig(data);
underTest.updateConfig(null, data);
assertThat(data.getJvmArgs()).contains("-Djava.awt.headless=true");
}

Expand Down
5 changes: 5 additions & 0 deletions pitest/src/main/java/org/pitest/plugin/FeatureSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public List<String> getList(String key) {
return this.settings.get(key);
}

public Optional<Integer> getInteger(String key) {
Optional<String> val = this.getString(key);
return val.map(Integer::parseInt);
}

}
12 changes: 9 additions & 3 deletions pitest/src/test/java/org/pitest/plugin/FeatureParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,20 @@ public void shouldParseFeatureNameWhenEmptyConfig() {
@Test
public void shouldParseSingleConfigValues() {
final FeatureSetting actual = parse("+BAR(name[hello])");
assertThat(actual.getString("name")).isEqualTo(Optional.ofNullable("hello"));
assertThat(actual.getString("name")).contains("hello");
}

@Test
public void shouldParseSingleIntegerConfigValues() {
final FeatureSetting actual = parse("+BAR(size[42])");
assertThat(actual.getInteger("size")).contains(42);
}

@Test
public void shouldParseMultipleConfigValues() {
final FeatureSetting actual = parse("+BAR(name[hello]size[42])");
assertThat(actual.getString("name")).isEqualTo(Optional.ofNullable("hello"));
assertThat(actual.getString("size")).isEqualTo(Optional.ofNullable("42"));
assertThat(actual.getString("name")).contains("hello");
assertThat(actual.getString("size")).contains("42");
}


Expand Down

0 comments on commit b2b365d

Please sign in to comment.