summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/testing/TestProcessRunner.java28
1 files changed, 18 insertions, 10 deletions
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;
+ }
}
}
}