mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 08:55:05 -04:00
adds a new testing CLI option, closes #479
This commit is contained in:
commit
6c8bc65d7c
@ -34,6 +34,7 @@ public class CommandLineTester {
|
||||
private final CircuitLoader circuitLoader;
|
||||
private ArrayList<TestCase> testCases;
|
||||
private int testsPassed;
|
||||
private boolean allowMissingInputs;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
@ -91,7 +92,9 @@ public class CommandLineTester {
|
||||
|
||||
try {
|
||||
Model model = circuitLoader.createModel();
|
||||
TestExecutor te = new TestExecutor(t.getTestCaseDescription()).create(model);
|
||||
TestExecutor te = new TestExecutor(t.getTestCaseDescription())
|
||||
.setAllowMissingInputs(allowMissingInputs)
|
||||
.create(model);
|
||||
|
||||
if (te.allPassed()) {
|
||||
out.println(label + ": passed");
|
||||
@ -134,12 +137,18 @@ public class CommandLineTester {
|
||||
}
|
||||
}
|
||||
|
||||
private CommandLineTester setAllowMissingInputs(boolean allowMissingInputs) {
|
||||
this.allowMissingInputs = allowMissingInputs;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The test command
|
||||
*/
|
||||
public static class TestCommand extends BasicCommand {
|
||||
private final Argument<String> circ;
|
||||
private final Argument<String> tests;
|
||||
private final Argument<Boolean> allowMissingInputs;
|
||||
private int testsPassed;
|
||||
|
||||
/**
|
||||
@ -149,12 +158,13 @@ public class CommandLineTester {
|
||||
super("test");
|
||||
circ = addArgument(new Argument<>("circ", "", false));
|
||||
tests = addArgument(new Argument<>("tests", "", true));
|
||||
allowMissingInputs = addArgument(new Argument<>("allowMissingInputs", false, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute() throws CLIException {
|
||||
try {
|
||||
CommandLineTester clt = new CommandLineTester(new File(circ.get()));
|
||||
CommandLineTester clt = new CommandLineTester(new File(circ.get())).setAllowMissingInputs(allowMissingInputs.get());
|
||||
if (tests.isSet())
|
||||
clt.useTestCasesFrom(new File(tests.get()));
|
||||
int errors = clt.execute(System.out);
|
||||
|
@ -36,6 +36,7 @@ public class TestExecutor {
|
||||
private ArrayList<TestSignal> inputs;
|
||||
private ArrayList<TestSignal> outputs;
|
||||
private int visibleRows;
|
||||
private boolean allowMissingInputs;
|
||||
|
||||
/**
|
||||
* Creates a new testing result
|
||||
@ -100,7 +101,10 @@ public class TestExecutor {
|
||||
|
||||
for (String name : names)
|
||||
if (!usedSignals.contains(name))
|
||||
throw new TestingDataException(Lang.get("err_testSignal_N_notFound", name));
|
||||
if (allowMissingInputs)
|
||||
inputs.add(new TestSignal(getIndexOf(name), null));
|
||||
else
|
||||
throw new TestingDataException(Lang.get("err_testSignal_N_notFound", name));
|
||||
|
||||
if (inputs.size() == 0)
|
||||
throw new TestingDataException(Lang.get("err_noTestInputSignalsDefined"));
|
||||
@ -129,7 +133,8 @@ public class TestExecutor {
|
||||
// set all values except the clocks
|
||||
for (TestSignal in : inputs) {
|
||||
if (values[in.index].getType() != Value.Type.CLOCK) {
|
||||
values[in.index].copyTo(in.value);
|
||||
if (in.value != null)
|
||||
values[in.index].copyTo(in.value);
|
||||
} else {
|
||||
clockIsUsed = true;
|
||||
}
|
||||
@ -235,6 +240,17 @@ public class TestExecutor {
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow missing inputs
|
||||
*
|
||||
* @param allowMissingInputs if true, missing inputs are allowed
|
||||
* @return this for chained calls
|
||||
*/
|
||||
public TestExecutor setAllowMissingInputs(boolean allowMissingInputs) {
|
||||
this.allowMissingInputs = allowMissingInputs;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A test signal
|
||||
*/
|
||||
|
@ -1545,7 +1545,7 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
|
||||
<string name="cli_nonOptionalArgumentMissing_N">Es fehlt das nicht optionale Argument {0}.</string>
|
||||
<string name="cli_notABool_N">Der Wert {0} ist kein bool.</string>
|
||||
<string name="cli_notANumber_N">Der Wert {0} ist keine Zahl.</string>
|
||||
<string name="cli_noArgument_N_available">Das Argument {0} fehlt.</string>
|
||||
<string name="cli_noArgument_N_available">Das Argument {0} ist nicht definiert.</string>
|
||||
<string name="cli_notEnoughArgumentsGiven">Es sind nicht genug Argumente vorhanden.</string>
|
||||
<string name="cli_toMuchArguments">Es gibt zu viele Argumente.</string>
|
||||
<string name="cli_invalidType_N">Ungültiger Typ.</string>
|
||||
@ -1558,6 +1558,10 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
|
||||
</string>
|
||||
<string name="cli_help_test_circ">Name der zu testenden Datei.</string>
|
||||
<string name="cli_help_test_tests">Name einer Datei mit Testfällen.</string>
|
||||
<string name="cli_help_test_allowMissingInputs">Erlaubt das Fehlen von Eingängen in der Schaltung die im
|
||||
Testfall definiert sind. Dies kann sinnvoll sein, wenn es mehrere mögliche Lösungen gibt, die von
|
||||
verschiedenen Eingängen abhängig sein können.
|
||||
</string>
|
||||
<string name="cli_thereAreTestFailures">Es sind Tests fehlgeschlagen.</string>
|
||||
<string name="cli_errorExecutingTests">Es ist ein Fehler bei der Ausführung der Tests aufgetreten.</string>
|
||||
|
||||
|
@ -1509,7 +1509,7 @@
|
||||
<string name="cli_nonOptionalArgumentMissing_N">The non-optional argument {0} is missing.</string>
|
||||
<string name="cli_notABool_N">The value {0} is no bool.</string>
|
||||
<string name="cli_notANumber_N">The value {0} is not a number.</string>
|
||||
<string name="cli_noArgument_N_available">The argument {0} is missing.</string>
|
||||
<string name="cli_noArgument_N_available">The argument {0} is not defined.</string>
|
||||
<string name="cli_notEnoughArgumentsGiven">There are not enough arguments.</string>
|
||||
<string name="cli_toMuchArguments">There are too many arguments.</string>
|
||||
<string name="cli_invalidType_N">Invalid type.</string>
|
||||
@ -1522,6 +1522,10 @@
|
||||
</string>
|
||||
<string name="cli_help_test_circ">Name of the file to be tested.</string>
|
||||
<string name="cli_help_test_tests">Name of a file with test cases.</string>
|
||||
<string name="cli_help_test_allowMissingInputs">Allows the missing of inputs in the circuit which are
|
||||
defined in the test case. This can be useful if there are several possible solutions which may
|
||||
depend on different inputs.
|
||||
</string>
|
||||
<string name="cli_thereAreTestFailures">Tests have failed.</string>
|
||||
<string name="cli_errorExecutingTests">An error has occurred during the execution of the tests.</string>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user