Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add makeDefaultsExplicit option for running unit test #417

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/checkers/inference/InferenceLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void infer() {

Mode mode = Mode.valueOf(InferenceOptions.mode);
if (InferenceOptions.makeDefaultsExplicit
&& (mode == Mode.ROUNDTRIP || mode == Mode.ROUNDTRIP_TYPECHECK)) {
&& (mode == Mode.ROUNDTRIP || mode == Mode.ROUNDTRIP_TYPECHECK || mode == Mode.INFER)) {
// Two conditions have to be met to make defaults explicit:
// 1. the command-line flag `makeDefaultsExplicit` is provided
// 2. the inference solution will be written back to the source code (roundtrip `mode`)
Expand Down
7 changes: 6 additions & 1 deletion tests/checkers/inference/test/CFInferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public boolean useHacks() {
return SystemUtil.getBooleanSystemProperty("use.hacks");
}

public boolean makeDefaultsExplicit() {
return false;
}

public abstract Pair<String, List<String>> getSolverNameAndOptions();

public List<String> getAdditionalInferenceOptions() {
Expand All @@ -54,7 +58,8 @@ public void run() {

InferenceTestConfiguration config = InferenceTestConfigurationBuilder.buildDefaultConfiguration(testDir,
testFile, testDataDir, checker, checkerOptions, getAdditionalInferenceOptions(), solverArgs.first,
solverArgs.second, useHacks(), shouldEmitDebugInfo, getPathToAfuScripts(), getPathToInferenceScript());
solverArgs.second, useHacks(), makeDefaultsExplicit(), shouldEmitDebugInfo, getPathToAfuScripts(),
getPathToInferenceScript());

InferenceTestResult testResult = new InferenceTestExecutor().runTest(config);
InferenceTestUtilities.assertResultsAreValid(testResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ public class ImmutableInferenceTestConfiguration implements InferenceTestConfigu
private final String solver;
private final Map<String, String> solverArgs;
private final boolean shouldUseHacks;
private final boolean makeDefaultsExplicit;
private final String pathToAfuScripts;
private final String pathToInferenceScript;
private final TestConfiguration initialConfig;

public ImmutableInferenceTestConfiguration(File outputJaif, File testDataDir, File annotatedSourceDir,
Map<String, String> inferenceJavacArgs, String solver,
Map<String, String> solverArgs, boolean shouldUseHacks, String pathToAfuScripts,
Map<String, String> solverArgs, boolean shouldUseHacks,
boolean makeDefaultsExplicit, String pathToAfuScripts,
String pathToInferenceScript, TestConfiguration initialConfig) {
this.outputJaif = outputJaif;
this.testDataDir = testDataDir;
Expand All @@ -31,6 +33,7 @@ public ImmutableInferenceTestConfiguration(File outputJaif, File testDataDir, Fi
this.solver = solver;
this.solverArgs = solverArgs;
this.shouldUseHacks = shouldUseHacks;
this.makeDefaultsExplicit = makeDefaultsExplicit;
this.pathToAfuScripts = pathToAfuScripts;
this.initialConfig = initialConfig;
this.pathToInferenceScript = pathToInferenceScript;
Expand Down Expand Up @@ -69,6 +72,10 @@ public boolean shouldUseHacks() {
return shouldUseHacks;
}

public boolean makeDefaultsExplicit() {
return makeDefaultsExplicit;
}

public String getPathToAfuScripts() {
return pathToAfuScripts;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface InferenceTestConfiguration {
List<String> getFlatSolverArgs();

boolean shouldUseHacks();
boolean makeDefaultsExplicit();
String getPathToAfuScripts();
String getPathToInferenceScript();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class InferenceTestConfigurationBuilder {
private File testDataDir = null;
private String solver = null;
private boolean shouldUseHacks;
private boolean makeDefaultsExplicit;
private String pathToAfuScripts="";
private String pathToInferenceScript="";

Expand Down Expand Up @@ -60,6 +61,11 @@ public InferenceTestConfigurationBuilder setShouldUseHacks(boolean shouldUseHack
return this;
}

public InferenceTestConfigurationBuilder setMakeDefaultsExplicit(boolean makeDefaultsExplicit) {
this.makeDefaultsExplicit = makeDefaultsExplicit;
return this;
}

public InferenceTestConfigurationBuilder setPathToAfuScripts(String pathToAfuScripts) {
this.pathToAfuScripts = pathToAfuScripts;
return this;
Expand Down Expand Up @@ -156,8 +162,8 @@ public List<String> validate() {
public InferenceTestConfiguration build() {
return new ImmutableInferenceTestConfiguration(outputJaif, testDataDir,
annotatedSourceDir, new LinkedHashMap<>(inferenceJavacArgs.getOptions()),
solver, new LinkedHashMap<>(solverArgs.getOptions()), shouldUseHacks,pathToAfuScripts,
pathToInferenceScript, initialConfiguration);
solver, new LinkedHashMap<>(solverArgs.getOptions()), shouldUseHacks, makeDefaultsExplicit,
pathToAfuScripts, pathToInferenceScript, initialConfiguration);
}

public InferenceTestConfiguration validateThenBuild() {
Expand All @@ -175,7 +181,8 @@ public InferenceTestConfiguration validateThenBuild() {
public static InferenceTestConfiguration buildDefaultConfiguration(
String testSourcePath, File testFile, File testDataRoot, Class<?> checker, List<String> typecheckOptions,
List<String> inferenceOptions, String solverName, List<String> solverOptions,
boolean shouldUseHacks, boolean shouldEmitDebugInfo, String pathToAfuScripts, String pathToInferenceScript) {
boolean shouldUseHacks, boolean makeDefaultsExplicit, boolean shouldEmitDebugInfo, String pathToAfuScripts,
String pathToInferenceScript) {

final File defaultInferenceOutDir = new File("testdata/tmp");
final File defaultOutputJaif = new File(defaultInferenceOutDir, "default.jaif");
Expand All @@ -192,6 +199,7 @@ public static InferenceTestConfiguration buildDefaultConfiguration(
.setAnnotatedSourceDir(defaultAnnotatedSourceDir)
.setSolver(solverName)
.setShouldUseHacks(shouldUseHacks)
.setMakeDefaultsExplicit(makeDefaultsExplicit)
.setPathToAfuScripts(pathToAfuScripts)
.setPathToInferenceScript(pathToInferenceScript);

Expand Down
3 changes: 3 additions & 0 deletions tests/checkers/inference/test/InferenceTestExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public static InferenceResult infer(InferenceTestConfiguration configuration) {
if (configuration.shouldUseHacks()) {
options.add("--hacks");
}
if (configuration.makeDefaultsExplicit()) {
options.add("--makeDefaultsExplicit");
}

options.add("--jaifFile=" + configuration.getOutputJaif().getAbsolutePath());

Expand Down
Loading