aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-03-09 22:17:08 +0000
committerMichael Williamson <mike@zwobble.org>2025-03-09 22:27:03 +0000
commit2bd3bd067b0f2f1e6e3b849ab1a7cc2a8357334a (patch)
treed65a5eee6ba5b48a82bec01688df2c6568138ae7 /src/test/java
parentd1f8d0cc3a947d0c637d24be0491085823feb847 (diff)
Extract notion of an example set
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/backends/ExampleSet.java38
-rw-r--r--src/test/java/org/shedlang/compiler/backends/ExampleTests.java17
-rw-r--r--src/test/java/org/shedlang/compiler/backends/Examples.java20
3 files changed, 45 insertions, 30 deletions
diff --git a/src/test/java/org/shedlang/compiler/backends/ExampleSet.java b/src/test/java/org/shedlang/compiler/backends/ExampleSet.java
new file mode 100644
index 00000000..52f46e63
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/backends/ExampleSet.java
@@ -0,0 +1,38 @@
+package org.shedlang.compiler.backends;
+
+import org.shedlang.compiler.filesystem.ShedCompilerFiles;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.stream.Stream;
+
+public class ExampleSet {
+ public static Stream<ExampleSet> exampleSets() {
+ return exampleSetDirectories()
+ .map(exampleDirectory -> new ExampleSet(exampleDirectory.toPath()));
+ }
+
+ /// The directory of each example set.
+ private static Stream<File> exampleSetDirectories() {
+ var examplesRoot = ShedCompilerFiles.getRoot().resolve("examples");
+
+ return Arrays.stream(examplesRoot.toFile()
+ .listFiles(file -> file.isDirectory()));
+ }
+
+ private final Path path;
+
+ private ExampleSet(Path path) {
+ this.path = path;
+ }
+
+ public String name() {
+ return this.path.getFileName().toString();
+ }
+
+ public ExamplesConfig readConfig() throws IOException {
+ return ExamplesConfig.read(this.path);
+ }
+}
diff --git a/src/test/java/org/shedlang/compiler/backends/ExampleTests.java b/src/test/java/org/shedlang/compiler/backends/ExampleTests.java
index 7e939696..b63fd5a4 100644
--- a/src/test/java/org/shedlang/compiler/backends/ExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/ExampleTests.java
@@ -7,14 +7,11 @@ import org.junit.jupiter.api.TestFactory;
import org.shedlang.compiler.ShedCompiler;
import org.shedlang.compiler.backends.paths.TargetDir;
import org.shedlang.compiler.errors.CompilerError;
-import org.shedlang.compiler.filesystem.ShedCompilerFiles;
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;
import java.util.Optional;
import java.util.stream.Stream;
@@ -25,22 +22,22 @@ import static org.zwobble.precisely.Matchers.equalTo;
public abstract class ExampleTests {
@TestFactory
public Stream<DynamicTest> tests() {
- return Examples.exampleDirectories()
- .map(exampleDirectory -> DynamicTest.dynamicTest(
- exampleDirectory.getName(),
- () -> runTest(exampleDirectory)
+ return ExampleSet.exampleSets()
+ .map(exampleSet -> DynamicTest.dynamicTest(
+ exampleSet.name(),
+ () -> runTest(exampleSet)
));
}
- private void runTest(File exampleDirectory) throws IOException, InterruptedException {
- var isWipTest = isDisabled(exampleDirectory.getName());
+ private void runTest(ExampleSet exampleSet) throws IOException, InterruptedException {
+ var isWipTest = isDisabled(exampleSet.name());
var includeWipTests = includeWipTests();
Assumptions.assumeFalse(isWipTest && !includeWipTests);
var backend = backend();
var compiler = new ShedCompiler();
- var config = ExamplesConfig.read(exampleDirectory.toPath());
+ var config = exampleSet.readConfig();
for (var example : config.examples()) {
TargetDir targetDir;
try {
diff --git a/src/test/java/org/shedlang/compiler/backends/Examples.java b/src/test/java/org/shedlang/compiler/backends/Examples.java
deleted file mode 100644
index f5b93fd6..00000000
--- a/src/test/java/org/shedlang/compiler/backends/Examples.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.shedlang.compiler.backends;
-
-import org.shedlang.compiler.filesystem.ShedCompilerFiles;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.stream.Stream;
-
-public class Examples {
- private Examples() {
- }
-
- /// The directory of each example.
- public static Stream<File> exampleDirectories() {
- var examplesRoot = ShedCompilerFiles.getRoot().resolve("examples");
-
- return Arrays.stream(examplesRoot.toFile()
- .listFiles(file -> file.isDirectory()));
- }
-}