aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-25 12:11:31 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-25 12:11:31 +0000
commit74df9e0559c20f4aed570f80f7584a36b5c5f39a (patch)
treec73ea0fc3005476ddc05e58c7ae7241a0cc12b7d /src/test/java
parentec22ab606ae09307f878ae0b3eab3bac3d726c90 (diff)
Extract ExampleTests::runTest()
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/backends/ExampleTests.java47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/test/java/org/shedlang/compiler/backends/ExampleTests.java b/src/test/java/org/shedlang/compiler/backends/ExampleTests.java
index fd807447..60c047da 100644
--- a/src/test/java/org/shedlang/compiler/backends/ExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/ExampleTests.java
@@ -11,6 +11,7 @@ import org.shedlang.compiler.testing.ExecutionResult;
import org.shedlang.compiler.testing.TestProcessRunner;
import org.shedlang.compiler.util.P;
+import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@@ -27,31 +28,33 @@ public abstract class ExampleTests {
.listFiles(file -> file.isDirectory()))
.map(exampleDirectory -> DynamicTest.dynamicTest(
exampleDirectory.getName(),
- () -> {
- Assumptions.assumeFalse(isDisabled(exampleDirectory.getName()));
- var backend = backend();
- var compiler = new ShedCompiler();
-
- var config = ProjectConfig.read(exampleDirectory.toPath());
- for (var example : config.examples()) {
- try {
- compiler.compile(exampleDirectory.toPath(), backend);
- } catch (CompilerError error) {
- if (example.expectedError().isPresent()) {
- assertThat(error.getMessage(), equalTo(example.expectedError().get()));
- return;
- }
+ () -> runTest(exampleDirectory)
+ ));
+ }
- System.err.println(error.source().describe());
- throw error;
- }
+ private void runTest(File exampleDirectory) throws IOException, InterruptedException {
+ Assumptions.assumeFalse(isDisabled(exampleDirectory.getName()));
+ var backend = backend();
+ var compiler = new ShedCompiler();
- var binPath = config.targetDir().resolve(backend.targetName()).resolve(example.bin()).toString();
- var result = runExampleBinary(binPath).throwOnError();
- assertThat(result.stdout(), equalTo(example.expectedOutput().orElseThrow()));
- }
+ var config = ProjectConfig.read(exampleDirectory.toPath());
+ for (var example : config.examples()) {
+ try {
+ compiler.compile(exampleDirectory.toPath(), backend);
+ } catch (CompilerError error) {
+ if (example.expectedError().isPresent()) {
+ assertThat(error.getMessage(), equalTo(example.expectedError().get()));
+ return;
}
- ));
+
+ System.err.println(error.source().describe());
+ throw error;
+ }
+
+ var binPath = config.targetDir().resolve(backend.targetName()).resolve(example.bin()).toString();
+ var result = runExampleBinary(binPath).throwOnError();
+ assertThat(result.stdout(), equalTo(example.expectedOutput().orElseThrow()));
+ }
}
private ExecutionResult runExampleBinary(String binary) throws IOException, InterruptedException {