Skip to content

Commit

Permalink
Fix broken Zucchini result JSONs being generated, resulting in failed…
Browse files Browse the repository at this point in the history
… tests yielding passes in Gradescope in some cases
  • Loading branch information
endorpersand committed Feb 1, 2025
1 parent 5bf9711 commit b5f500a
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import static org.junit.platform.engine.TestExecutionResult.Status.SUCCESSFUL;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down Expand Up @@ -38,27 +42,24 @@ public void printResultsAsJson(TestClassResult classResult, Appendable out) {
// Assumes results is sorted by method name
private List<ZucchiniJsonMethod> collapseMethodResults(
Collection<TestMethodResult> results) {
List<ZucchiniJsonMethod> collapsed = new LinkedList<>();
Map<String, ZucchiniJsonMethod> collapsed = new HashMap<>();

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));
}
ZucchiniJsonMethod method = collapsed.computeIfAbsent(methodName, ZucchiniJsonMethod::new);

tail.total++;
method.total++;
if (result.getResult().getStatus() != SUCCESSFUL &&
++tail.failed <= maxFailuresPerTest) {
tail.partialFailures.add(
++method.failed <= maxFailuresPerTest) {
method.partialFailures.add(
ZucchiniJsonMethodFailure.fromMethodResult(result));
}
}

return collapsed;
List<ZucchiniJsonMethod> objects = new ArrayList<>(collapsed.values());
objects.sort(Comparator.comparing(m -> m.methodName));

return objects;
}

private static class ZucchiniJsonRoot {
Expand Down

0 comments on commit b5f500a

Please sign in to comment.