aboutsummaryrefslogtreecommitdiffgithub
diff options
context:
space:
mode:
authorAustin Adams <git@austinjadams.com>2018-09-03 15:24:26 -0400
committerAustin Adams <git@austinjadams.com>2018-09-03 16:46:55 -0400
commit17e7834950f0c8fd8bc3cacdb65e0c9ef10fe9c0 (patch)
treec381e0ca5e8d36253b9f8fe3c88652430d47fedf
parent95b12b30565ae2f2e913c55da842acaaae44bde7 (diff)
downloadcircuitsim-grader-template-17e7834950f0c8fd8bc3cacdb65e0c9ef10fe9c0.tar.gz
circuitsim-grader-template-17e7834950f0c8fd8bc3cacdb65e0c9ef10fe9c0.tar.xz
Abbreviate Zucchini results
To prevent the Zucchini results json from becoming massive, include counts for failed tests and then the first 8 failure descriptions.
-rw-r--r--src/main/java/edu/gatech/cs2110/circuitsim/launcher/TesterLauncher.java2
-rw-r--r--src/main/java/edu/gatech/cs2110/circuitsim/launcher/ZucchiniJson.java71
2 files changed, 53 insertions, 20 deletions
diff --git a/src/main/java/edu/gatech/cs2110/circuitsim/launcher/TesterLauncher.java b/src/main/java/edu/gatech/cs2110/circuitsim/launcher/TesterLauncher.java
index 7515c4e..cb806ef 100644
--- a/src/main/java/edu/gatech/cs2110/circuitsim/launcher/TesterLauncher.java
+++ b/src/main/java/edu/gatech/cs2110/circuitsim/launcher/TesterLauncher.java
@@ -126,7 +126,7 @@ public class TesterLauncher {
public void printZucchiniJsonSummary() {
// Only ran one class so should be just one TestClassResult
TestClassResult classResult = results.stream().findFirst().get();
- new ZucchiniJson().printResultsAsJson(classResult, out);
+ new ZucchiniJson(MAX_FAILURES).printResultsAsJson(classResult, out);
}
private boolean wasSuccessful() {
diff --git a/src/main/java/edu/gatech/cs2110/circuitsim/launcher/ZucchiniJson.java b/src/main/java/edu/gatech/cs2110/circuitsim/launcher/ZucchiniJson.java
index 636def6..dc1cb1b 100644
--- a/src/main/java/edu/gatech/cs2110/circuitsim/launcher/ZucchiniJson.java
+++ b/src/main/java/edu/gatech/cs2110/circuitsim/launcher/ZucchiniJson.java
@@ -11,10 +11,12 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class ZucchiniJson {
+ private int maxFailuresPerTest;
private Gson gson;
- public ZucchiniJson() {
- gson = new GsonBuilder().setPrettyPrinting().create();
+ public ZucchiniJson(int maxFailuresPerTest) {
+ this.maxFailuresPerTest = maxFailuresPerTest;
+ this.gson = new GsonBuilder().setPrettyPrinting().create();
}
public void printResultsAsJson(TestClassResult classResult, Appendable out) {
@@ -24,10 +26,8 @@ public class ZucchiniJson {
// Zucchini treats an error as a 0, so don't bother writing test
// results unless there were no errors.
if (success) {
- root = new ZucchiniJsonRoot(
- classResult.getMethodResults().stream()
- .map(ZucchiniJsonMethod::fromMethodResult)
- .collect(Collectors.toList()));
+ root = new ZucchiniJsonRoot(collapseMethodResults(
+ classResult.getMethodResults()));
} else {
root = new ZucchiniJsonRoot(
classResult.getResult().getThrowable().get().getMessage());
@@ -36,6 +36,32 @@ public class ZucchiniJson {
gson.toJson(root, out);
}
+ // Assumes results is sorted by method name
+ private List<ZucchiniJsonMethod> collapseMethodResults(
+ Collection<TestMethodResult> results) {
+ List<ZucchiniJsonMethod> collapsed = new LinkedList<>();
+
+ for (TestMethodResult result : results) {
+ String methodName = result.getSource().getMethodName();
+ ZucchiniJsonMethod tail;
+ if (collapsed.isEmpty() ||
+ !(tail = collapsed.get(collapsed.size() - 1)).methodName
+ .equals(methodName)) {
+ // Time to start a new methodresult
+ collapsed.add(tail = new ZucchiniJsonMethod(methodName));
+ }
+
+ tail.total++;
+ if (result.getResult().getStatus() != SUCCESSFUL &&
+ ++tail.failed <= maxFailuresPerTest) {
+ tail.partialFailures.add(
+ ZucchiniJsonMethodFailure.fromMethodResult(result));
+ }
+ }
+
+ return collapsed;
+ }
+
private static class ZucchiniJsonRoot {
private String error;
private List<ZucchiniJsonMethod> tests;
@@ -54,26 +80,33 @@ public class ZucchiniJson {
}
private static class ZucchiniJsonMethod {
- private String displayName;
private String methodName;
- private boolean passed;
+ private int failed;
+ private int total;
+ private List<ZucchiniJsonMethodFailure> partialFailures;
+
+ public ZucchiniJsonMethod(String methodName) {
+ this.methodName = methodName;
+ this.failed = 0;
+ this.total = 0;
+ this.partialFailures = new LinkedList<>();
+ }
+ }
+
+ private static class ZucchiniJsonMethodFailure {
+ private String displayName;
private String message;
- public ZucchiniJsonMethod(String displayName, String methodName,
- boolean passed, String message) {
+ public ZucchiniJsonMethodFailure(String displayName, String message) {
this.displayName = displayName;
- this.methodName = methodName;
- this.passed = passed;
this.message = message;
}
- public static ZucchiniJsonMethod fromMethodResult(TestMethodResult methodResult) {
- boolean passed = methodResult.getResult().getStatus() == SUCCESSFUL;
- String message = methodResult.getResult().getThrowable().map(err -> err.getMessage())
- .orElse(null);
- return new ZucchiniJsonMethod(methodResult.getId().getDisplayName(),
- methodResult.getSource().getMethodName(),
- passed, message);
+ public static ZucchiniJsonMethodFailure fromMethodResult(TestMethodResult result) {
+ String displayName = result.getId().getDisplayName();
+ String message = result.getResult().getThrowable().map(err -> err.getMessage())
+ .orElse(null);
+ return new ZucchiniJsonMethodFailure(displayName, message);
}
}
}