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
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"))
.toList();
List<TestInfo> tests = testFunctions.stream()
.map(e -> runTest(e.getKey(), e.getValue()))
.toList();
@ -133,19 +135,12 @@ public final class ounit implements Module {
}
}
private static class TestInfo {
final String name;
final boolean isPassed;
final String failureDescription;
final long elapsedTimeInMicros;
public TestInfo(String name, boolean isPassed, String failureDescription, long elapsedTimeInMicros) {
this.name = name;
this.isPassed = isPassed;
this.failureDescription = failureDescription;
this.elapsedTimeInMicros = elapsedTimeInMicros;
}
private record TestInfo(
String name,
boolean isPassed,
String failureDescription,
long elapsedTimeInMicros
) {
public String info() {
return String.format("%s [%s]\n%sElapsed: %s\n",
name,