From 2bd3bd067b0f2f1e6e3b849ab1a7cc2a8357334a Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 9 Mar 2025 22:17:08 +0000 Subject: Extract notion of an example set --- .../org/shedlang/compiler/backends/ExampleSet.java | 38 ++++++++++++++++++++++ .../shedlang/compiler/backends/ExampleTests.java | 17 ++++------ .../org/shedlang/compiler/backends/Examples.java | 20 ------------ 3 files changed, 45 insertions(+), 30 deletions(-) create mode 100644 src/test/java/org/shedlang/compiler/backends/ExampleSet.java delete mode 100644 src/test/java/org/shedlang/compiler/backends/Examples.java (limited to 'src/test/java') 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 exampleSets() { + return exampleSetDirectories() + .map(exampleDirectory -> new ExampleSet(exampleDirectory.toPath())); + } + + /// The directory of each example set. + private static Stream 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 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 exampleDirectories() { - var examplesRoot = ShedCompilerFiles.getRoot().resolve("examples"); - - return Arrays.stream(examplesRoot.toFile() - .listFiles(file -> file.isDirectory())); - } -} -- cgit v1.2.3