Fix concurrent modification exception in ounit, when new modules are loaded in test

This commit is contained in:
aNNiMON 2023-09-09 21:05:17 +03:00 committed by Victor Melnik
parent 99bdd1c953
commit 90db2b0aa3

View File

@ -88,8 +88,10 @@ public final class ounit implements Module {
@Override @Override
public Value execute(Value[] args) { public Value execute(Value[] args) {
List<TestInfo> tests = Functions.getFunctions().entrySet().stream() final var testFunctions = ScopeHandler.functions().entrySet().stream()
.filter(e -> e.getKey().toLowerCase().startsWith("test")) .filter(e -> e.getKey().toLowerCase().startsWith("test"))
.toList();
List<TestInfo> tests = testFunctions.stream()
.map(e -> runTest(e.getKey(), e.getValue())) .map(e -> runTest(e.getKey(), e.getValue()))
.toList(); .toList();
@ -133,19 +135,12 @@ public final class ounit implements Module {
} }
} }
private static class TestInfo { private record TestInfo(
final String name; String name,
final boolean isPassed; boolean isPassed,
final String failureDescription; String failureDescription,
final long elapsedTimeInMicros; long elapsedTimeInMicros
) {
public TestInfo(String name, boolean isPassed, String failureDescription, long elapsedTimeInMicros) {
this.name = name;
this.isPassed = isPassed;
this.failureDescription = failureDescription;
this.elapsedTimeInMicros = elapsedTimeInMicros;
}
public String info() { public String info() {
return String.format("%s [%s]\n%sElapsed: %s\n", return String.format("%s [%s]\n%sElapsed: %s\n",
name, name,