aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-03-09 21:52:45 +0000
committerMichael Williamson <mike@zwobble.org>2025-03-09 21:52:45 +0000
commit564a2a7f4feb6f53b5aeff38a73f30dc275d4437 (patch)
tree8315e706744b44869f974444254e4a7b0558f767 /src/test/java
parent596b1c1fde6b94326c7cc1ee35c81586fa04ab72 (diff)
Remove duplication of path to binary
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/backends/ExampleTests.java16
-rw-r--r--src/test/java/org/shedlang/compiler/backends/llvm/Amd64ExampleTests.java4
-rw-r--r--src/test/java/org/shedlang/compiler/backends/llvm/I686ExampleTests.java4
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/Wasm32ExampleTests.java4
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/Wasm64ExampleTests.java4
5 files changed, 14 insertions, 18 deletions
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.<String>vector()
.plusAll(binaryRunner())
- .plus(executableName(binary));
+ .plus(binary);
return TestProcessRunner.runCaptureOutput(fullCommand);
}
@@ -90,7 +86,7 @@ public abstract class ExampleTests {
protected abstract List<String> 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<String> 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<String> 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<String> 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<String> DISABLED = Set.of(