From 564a2a7f4feb6f53b5aeff38a73f30dc275d4437 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 9 Mar 2025 21:52:45 +0000 Subject: Remove duplication of path to binary --- .../org/shedlang/compiler/backends/ExampleTests.java | 16 ++++++---------- .../compiler/backends/llvm/Amd64ExampleTests.java | 4 ++-- .../compiler/backends/llvm/I686ExampleTests.java | 4 ++-- .../compiler/backends/wasm/Wasm32ExampleTests.java | 4 ++-- .../compiler/backends/wasm/Wasm64ExampleTests.java | 4 ++-- 5 files changed, 14 insertions(+), 18 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/backends/ExampleTests.java b/src/test/java/org/shedlang/compiler/backends/ExampleTests.java index 03ff3065..f7d8f055 100644 --- a/src/test/java/org/shedlang/compiler/backends/ExampleTests.java +++ b/src/test/java/org/shedlang/compiler/backends/ExampleTests.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; import org.shedlang.compiler.ShedCompiler; -import org.shedlang.compiler.config.ProfileConfig; +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; @@ -44,8 +44,9 @@ public abstract class ExampleTests { var config = ExamplesConfig.read(exampleDirectory.toPath()); for (var example : config.examples()) { + TargetDir targetDir; try { - compiler.compile(example.projectPath(), backend, Optional.empty()); + targetDir = compiler.compile(example.projectPath(), backend, Optional.empty()); } catch (CompilerError error) { if (example.expectedError().isPresent()) { assertThat(error.getMessage(), equalTo(example.expectedError().get())); @@ -56,12 +57,7 @@ public abstract class ExampleTests { throw error; } - // TODO: remove duplicated generation of target binary path - var binPath = example.projectPath() - .resolve("target") - .resolve(backend.targetName()) - .resolve(ProfileConfig.DEFAULT.name()) - .resolve(example.bin()) + var binPath = targetDir.topLevel(example.bin() + this.executableExtension()) .toString(); var result = runExampleBinary(binPath); assertThat(result.exitCode(), equalTo((int)example.expectedExitCode().orElse(0))); @@ -81,7 +77,7 @@ public abstract class ExampleTests { private ExecutionResult runExampleBinary(String binary) throws IOException, InterruptedException { var fullCommand = P.vector() .plusAll(binaryRunner()) - .plus(executableName(binary)); + .plus(binary); return TestProcessRunner.runCaptureOutput(fullCommand); } @@ -90,7 +86,7 @@ public abstract class ExampleTests { protected abstract List binaryRunner(); - protected abstract String executableName(String binary); + protected abstract String executableExtension(); protected abstract boolean isDisabled(String testName); } diff --git a/src/test/java/org/shedlang/compiler/backends/llvm/Amd64ExampleTests.java b/src/test/java/org/shedlang/compiler/backends/llvm/Amd64ExampleTests.java index 2fbe9f4b..40a7b436 100644 --- a/src/test/java/org/shedlang/compiler/backends/llvm/Amd64ExampleTests.java +++ b/src/test/java/org/shedlang/compiler/backends/llvm/Amd64ExampleTests.java @@ -18,8 +18,8 @@ public class Amd64ExampleTests extends ExampleTests { } @Override - protected String executableName(String binary) { - return binary; + protected String executableExtension() { + return ""; } private static final Set DISABLED = Set.of( diff --git a/src/test/java/org/shedlang/compiler/backends/llvm/I686ExampleTests.java b/src/test/java/org/shedlang/compiler/backends/llvm/I686ExampleTests.java index 07240512..66c08371 100644 --- a/src/test/java/org/shedlang/compiler/backends/llvm/I686ExampleTests.java +++ b/src/test/java/org/shedlang/compiler/backends/llvm/I686ExampleTests.java @@ -18,8 +18,8 @@ public class I686ExampleTests extends ExampleTests { } @Override - protected String executableName(String binary) { - return binary; + protected String executableExtension() { + return ""; } private static final Set DISABLED = Set.of( diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/Wasm32ExampleTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/Wasm32ExampleTests.java index 7b0ab151..85662b0c 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/Wasm32ExampleTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/Wasm32ExampleTests.java @@ -18,8 +18,8 @@ public class Wasm32ExampleTests extends ExampleTests { } @Override - protected String executableName(String binary) { - return binary + ".wasm"; + protected String executableExtension() { + return ".wasm"; } private static final Set DISABLED = Set.of( diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/Wasm64ExampleTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/Wasm64ExampleTests.java index 71d5f17b..e1c59bd7 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/Wasm64ExampleTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/Wasm64ExampleTests.java @@ -18,8 +18,8 @@ public class Wasm64ExampleTests extends ExampleTests { } @Override - protected String executableName(String binary) { - return binary + ".wasm"; + protected String executableExtension() { + return ".wasm"; } private static final Set DISABLED = Set.of( -- cgit v1.2.3