aboutsummaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/common
diff options
context:
space:
mode:
authorJ08nY2018-01-09 13:46:29 +0100
committerJ08nY2018-01-09 13:46:29 +0100
commit94e441b522069d3fed4b88a4823b91c1593bac68 (patch)
tree6b8ebc96c50b7a16acdc71c74a34daa7669187a9 /src/cz/crcs/ectester/common
parentd19d8ad062a3c0053789eae5f7c9662399f781e0 (diff)
downloadECTester-94e441b522069d3fed4b88a4823b91c1593bac68.tar.gz
ECTester-94e441b522069d3fed4b88a4823b91c1593bac68.tar.zst
ECTester-94e441b522069d3fed4b88a4823b91c1593bac68.zip
Simplify test suites.
Diffstat (limited to 'src/cz/crcs/ectester/common')
-rw-r--r--src/cz/crcs/ectester/common/cli/TreeParser.java8
-rw-r--r--src/cz/crcs/ectester/common/test/BaseRunnable.java31
-rw-r--r--src/cz/crcs/ectester/common/test/Runnable.java18
-rw-r--r--src/cz/crcs/ectester/common/test/TestRunner.java29
-rw-r--r--src/cz/crcs/ectester/common/test/TestSuite.java35
-rw-r--r--src/cz/crcs/ectester/common/test/Testable.java13
6 files changed, 43 insertions, 91 deletions
diff --git a/src/cz/crcs/ectester/common/cli/TreeParser.java b/src/cz/crcs/ectester/common/cli/TreeParser.java
index 77cce30..f1a1980 100644
--- a/src/cz/crcs/ectester/common/cli/TreeParser.java
+++ b/src/cz/crcs/ectester/common/cli/TreeParser.java
@@ -86,6 +86,7 @@ public class TreeParser implements CommandLineParser {
}
}
+ int maxArgs = args.size();
long requiredArgs = args.stream().filter(Argument::isRequired).count();
String reqArgs = String.join(" ", args.stream().filter(Argument::isRequired).map(Argument::getName).collect(Collectors.toList()));
@@ -99,6 +100,8 @@ public class TreeParser implements CommandLineParser {
if (lastCli.getArgs().length < requiredArgs) {
throw new MissingArgumentException("Not enough arguments: " + reqArgs);
+ } else if (lastCli.getArgs().length > maxArgs) {
+ throw new MissingArgumentException("Too many arguments.");
}
subTreeCli.setName(sub);
@@ -106,6 +109,8 @@ public class TreeParser implements CommandLineParser {
} else if (subCli != null) {
if (subCli.getArgs().length < requiredArgs) {
throw new MissingArgumentException("Not enough arguments: " + reqArgs);
+ } else if (subCli.getArgs().length > maxArgs) {
+ throw new MissingArgumentException("Too many arguments.");
}
TreeCommandLine subTreeCli = new TreeCommandLine(sub, subCli, null);
@@ -113,7 +118,10 @@ public class TreeParser implements CommandLineParser {
} else {
if (cliArgs.length < requiredArgs) {
throw new MissingArgumentException("Not enough arguments: " + reqArgs);
+ } else if (cliArgs.length > maxArgs) {
+ throw new MissingArgumentException("Too many arguments.");
}
+
return new TreeCommandLine(cli, null);
}
}
diff --git a/src/cz/crcs/ectester/common/test/BaseRunnable.java b/src/cz/crcs/ectester/common/test/BaseRunnable.java
deleted file mode 100644
index 3e18208..0000000
--- a/src/cz/crcs/ectester/common/test/BaseRunnable.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package cz.crcs.ectester.common.test;
-
-/**
- * @author Jan Jancar johny@neuromancer.sk
- */
-public class BaseRunnable implements Runnable {
- private boolean hasRun = false;
- private Func runImplicit;
-
- public BaseRunnable(Func runImplicit) {
- this.runImplicit = runImplicit;
- }
-
- @Override
- public boolean hasRun() {
- return hasRun;
- }
-
- @Override
- public void run() throws TestException {
- if (!hasRun) {
- runImplicit.run();
- }
- hasRun = true;
- }
-
- @FunctionalInterface
- public interface Func {
- void run() throws TestException;
- }
-}
diff --git a/src/cz/crcs/ectester/common/test/Runnable.java b/src/cz/crcs/ectester/common/test/Runnable.java
deleted file mode 100644
index 6f0efb0..0000000
--- a/src/cz/crcs/ectester/common/test/Runnable.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package cz.crcs.ectester.common.test;
-
-/**
- * @author Jan Jancar johny@neuromancer.sk
- */
-public interface Runnable {
- /**
- * @return Whether this runnable was run.
- */
- boolean hasRun();
-
- /**
- * Run this Runnable.
- *
- * @throws TestException
- */
- void run() throws TestException;
-}
diff --git a/src/cz/crcs/ectester/common/test/TestRunner.java b/src/cz/crcs/ectester/common/test/TestRunner.java
deleted file mode 100644
index cd71bcd..0000000
--- a/src/cz/crcs/ectester/common/test/TestRunner.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package cz.crcs.ectester.common.test;
-
-import cz.crcs.ectester.common.output.TestWriter;
-
-/**
- * @author Jan Jancar johny@neuromancer.sk
- */
-public class TestRunner {
- private TestSuite suite;
- private TestWriter writer;
-
- public TestRunner(TestSuite suite, TestWriter writer) {
- this.suite = suite;
- this.writer = writer;
- }
-
- public void run() throws TestException {
- writer.begin(suite);
- for (Runnable t : suite.getRunnables()) {
- if (!t.hasRun()) {
- t.run();
- if (t instanceof Test) {
- writer.outputTest((Test) t);
- }
- }
- }
- writer.end();
- }
-}
diff --git a/src/cz/crcs/ectester/common/test/TestSuite.java b/src/cz/crcs/ectester/common/test/TestSuite.java
index 1a7c914..f4f30ee 100644
--- a/src/cz/crcs/ectester/common/test/TestSuite.java
+++ b/src/cz/crcs/ectester/common/test/TestSuite.java
@@ -1,5 +1,6 @@
package cz.crcs.ectester.common.test;
+import cz.crcs.ectester.common.output.TestWriter;
import cz.crcs.ectester.data.EC_Store;
import java.util.Collections;
@@ -13,27 +14,37 @@ import java.util.stream.Collectors;
public abstract class TestSuite {
protected String name;
protected String description;
- protected List<Runnable> run = new LinkedList<>();
- protected EC_Store dataStore;
+ protected TestWriter writer;
- public TestSuite(EC_Store dataStore, String name, String description) {
- this.dataStore = dataStore;
+ public TestSuite(TestWriter writer, String name, String description) {
+ this.writer = writer;
this.name = name;
this.description = description;
}
- public List<Runnable> getRunnables() {
- return Collections.unmodifiableList(run);
+ public void run() throws TestException {
+ writer.begin(this);
+ try {
+ runTests();
+ } catch (Exception e) {
+ throw new TestException(e);
+ }
+ writer.end();
}
- @SuppressWarnings("unchecked")
- public List<Test> getTests() {
- return Collections.unmodifiableList((List<Test>)(List<?>) run
- .stream()
- .filter(runnable -> (runnable instanceof Test))
- .collect(Collectors.toList()));
+ protected Test runTest(Test t) throws TestException {
+ t.run();
+ return t;
}
+ protected Test doTest(Test t) throws TestException {
+ t.run();
+ writer.outputTest(t);
+ return t;
+ }
+
+ protected abstract void runTests() throws Exception;
+
public String getName() {
return name;
}
diff --git a/src/cz/crcs/ectester/common/test/Testable.java b/src/cz/crcs/ectester/common/test/Testable.java
index cc7a5de..3627075 100644
--- a/src/cz/crcs/ectester/common/test/Testable.java
+++ b/src/cz/crcs/ectester/common/test/Testable.java
@@ -3,7 +3,7 @@ package cz.crcs.ectester.common.test;
/**
* @author Jan Jancar johny@neuromancer.sk
*/
-public interface Testable extends Runnable {
+public interface Testable {
/**
* @return Whether this Testable was OK.
*/
@@ -13,4 +13,15 @@ public interface Testable extends Runnable {
* @return Whether an error happened.
*/
boolean error();
+ /**
+ * @return Whether this runnable was run.
+ */
+ boolean hasRun();
+
+ /**
+ * Run this Runnable.
+ *
+ * @throws TestException
+ */
+ void run() throws TestException;
}