From 157675d122e806bb1dd9f655135f1b856090bbbd Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 2 Aug 2026 13:08:20 +0100 Subject: Handle exception properly --- .../compiler/testing/TestProcessRunner.java | 28 ++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/testing/TestProcessRunner.java b/src/test/java/org/zwobble/hobgoblin/compiler/testing/TestProcessRunner.java index 882519c..73117a1 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/testing/TestProcessRunner.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/testing/TestProcessRunner.java @@ -43,34 +43,42 @@ public class TestProcessRunner { } private static class ThreadReader { + private static class ReadResult { + String output; + IOException exception; + } + public static ThreadReader start(Reader reader) { var lock = new Object(); - var output = new String[1]; + var readResult = new ReadResult(); Thread.startVirtualThread(() -> { synchronized (lock) { try (reader) { - output[0] = reader.readAllAsString(); + readResult.output = reader.readAllAsString(); } catch (IOException exception) { - // TODO: handle this more elegantly. - throw new RuntimeException(exception); + readResult.exception = exception; } } }); - return new ThreadReader(lock, output); + return new ThreadReader(lock, readResult); } private final Object lock; - private final String[] output; + private final ReadResult readResult; - public ThreadReader(Object lock, String[] output) { + public ThreadReader(Object lock, ReadResult readResult) { this.lock = lock; - this.output = output; + this.readResult = readResult; } - public String waitForString() { + public String waitForString() throws IOException { synchronized (this.lock) { - return this.output[0]; + if (this.readResult.exception != null) { + throw this.readResult.exception; + } else { + return this.readResult.output; + } } } } -- cgit v1.2.3