Skip to content
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
16 changes: 2 additions & 14 deletions src/checkers/inference/InferenceLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,7 @@ protected void initInferenceOptions(String[] args) {
public void launch(String[] args) {
initInferenceOptions(args);

Mode mode = null;
try {
mode = Mode.valueOf(InferenceOptions.mode);

} catch (IllegalArgumentException iexc) {
outStream.println(
"Could not recognize mode: "
+ InferenceOptions.mode
+ "\n"
+ "valid modes: "
+ StringsPlume.join(", ", Mode.values()));
System.exit(1);
}
Mode mode = InferenceOptions.mode;

switch (mode) {
case TYPECHECK:
Expand Down Expand Up @@ -221,7 +209,7 @@ public void infer() {

addIfTrue("--hacks", InferenceOptions.hacks, argList);

Mode mode = Mode.valueOf(InferenceOptions.mode);
Mode mode = InferenceOptions.mode;
if (InferenceOptions.makeDefaultsExplicit
&& (mode == Mode.ROUNDTRIP || mode == Mode.ROUNDTRIP_TYPECHECK)) {
// Two conditions have to be met to make defaults explicit:
Expand Down
20 changes: 2 additions & 18 deletions src/checkers/inference/InferenceOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ public class InferenceOptions {
// ------------------------------------------------------

@OptionGroup("General Options")

// TODO: The mode variable should be an enum rather than a string.
@Option(value = "-m Modes of operation: TYPECHECK, INFER, ROUNDTRIP, ROUNDTRIP_TYPECHECK")
public static String mode;
public static Mode mode;

@Option("Should we log certain exceptions rather than crash")
public static boolean hacks;
Expand Down Expand Up @@ -185,21 +183,7 @@ public static InitStatus init(String[] args, boolean requireMode) {
}

} else {
mode = mode.toUpperCase();

Mode modeEnum = null;
try {
modeEnum = Mode.valueOf(InferenceOptions.mode);

} catch (IllegalArgumentException iexc) {
System.out.println(
"Could not recognize mode: "
+ InferenceOptions.mode
+ "\n"
+ "valid modes: "
+ StringsPlume.join(", ", Mode.values()));
System.exit(1);
}
Mode modeEnum = InferenceOptions.mode;

if (modeEnum != Mode.TYPECHECK) {
if (solver == null) {
Expand Down
84 changes: 84 additions & 0 deletions tests/checkers/inference/InferenceOptionsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package checkers.inference;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;

import checkers.inference.InferenceLauncher.Mode;

public class InferenceOptionsTest {

@Before
public void resetOptions() {
InferenceOptions.mode = null;
InferenceOptions.hacks = false;
InferenceOptions.typesystem = null;
InferenceOptions.jaifFile = InferenceOptions.DEFAULT_JAIF;
InferenceOptions.checker = null;
InferenceOptions.solver = null;
InferenceOptions.targetclasspath = ".";
InferenceOptions.solverArgs = null;
InferenceOptions.cfArgs = null;
InferenceOptions.jsonFile = null;
InferenceOptions.pathToAfuScripts = null;
InferenceOptions.afuOutputDir = null;
InferenceOptions.inPlace = false;
InferenceOptions.afuOptions = null;
InferenceOptions.makeDefaultsExplicit = false;
InferenceOptions.version = false;
InferenceOptions.help = false;
InferenceOptions.logLevel = null;
InferenceOptions.printCommands = false;
InferenceOptions.debug = null;
InferenceOptions.javacOptions = new ArrayList<String>();
InferenceOptions.javaFiles = new String[0];
}

@Test
public void parsesUppercaseMode() {
InferenceOptions.InitStatus status =
InferenceOptions.init(
new String[] {
"--mode=TYPECHECK", "--checker", ostrusted.OsTrustedChecker.class.getName()
},
true);

assertTrue(status.errors.toString(), status.errors.isEmpty());
assertEquals(Mode.TYPECHECK, InferenceOptions.mode);
}

@Test
public void parsesLowercaseMode() {
InferenceOptions.InitStatus status =
InferenceOptions.init(
new String[] {
"--mode=typecheck", "--checker", ostrusted.OsTrustedChecker.class.getName()
},
true);

assertTrue(status.errors.toString(), status.errors.isEmpty());
assertEquals(Mode.TYPECHECK, InferenceOptions.mode);
}

@Test
public void parsesHyphenatedMode() {
InferenceOptions.InitStatus status =
InferenceOptions.init(
new String[] {
"--mode=roundtrip-typecheck",
"--checker",
ostrusted.OsTrustedChecker.class.getName(),
"--jsonFile",
"constraints.json",
"--inPlace"
},
true);

assertTrue(status.errors.toString(), status.errors.isEmpty());
assertEquals(Mode.ROUNDTRIP_TYPECHECK, InferenceOptions.mode);
}
}
Loading