aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-11-07 23:20:05 +0000
committerMichael Williamson <mike@zwobble.org>2015-11-07 23:20:05 +0000
commitf398933835e7fa7a80b0abd7feda6790370804c8 (patch)
treed65c7b28e60f114379e0f5ca9e834f78f31433a2 /src/test
parent22f699108050535e74e4b43fc42d0b4f7cfe9353 (diff)
Extract Frontend interface from JavaFrontend
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java b/src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java
index d844360..271c529 100644
--- a/src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java
+++ b/src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java
@@ -10,7 +10,6 @@ import java.util.List;
import org.junit.Test;
import org.zwobble.couscous.CouscousCompiler;
-import org.zwobble.couscous.ast.ClassNode;
import org.zwobble.couscous.ast.TypeName;
import org.zwobble.couscous.backends.python.PythonBackend;
import org.zwobble.couscous.frontends.java.JavaFrontend;
@@ -52,27 +51,41 @@ public class JavaToPythonTests {
public void recursiveFactorial() throws Exception {
assertEquals(
value(720),
- execProgram(
+ execTestProgram(
"recursive-factorial",
TypeName.of("com.example.RecursiveFactorial"),
"factorial",
asList(value(6))));
}
- private PrimitiveValue execProgram(
- String directory,
+ private PrimitiveValue execTestProgram(
+ String directoryName,
TypeName type,
String methodName,
List<PrimitiveValue> arguments) throws IOException, InterruptedException {
Path path = pathForResource(
- "/java/" + directory + "/" + type.getQualifiedName().replace(".", "/") + ".java");
+ "/java/" + directoryName + "/" + type.getQualifiedName().replace(".", "/") + ".java");
+
+ return execProgram(
+ directoryName(path, type.getQualifiedName().split(".").length),
+ type,
+ methodName,
+ arguments);
+ }
+
+ private PrimitiveValue execProgram(
+ Path directory,
+ TypeName type,
+ String methodName,
+ List<PrimitiveValue> arguments) throws IOException, InterruptedException {
Path directoryPath = Files.createTempDirectory(null);
try {
CouscousCompiler compiler = new CouscousCompiler(
+ new JavaFrontend(),
new PythonBackend(directoryPath, "couscous"));
- compiler.compileDirectory(directoryName(path, type.getQualifiedName().split(".").length));
+ compiler.compileDirectory(directory);
return PythonMethodRunner.runFunction(directoryPath, type, methodName, arguments);
} finally {
deleteRecursively(directoryPath.toFile());
@@ -97,8 +110,11 @@ public class JavaToPythonTests {
try {
Files.createDirectories(directoryPath.resolve("com/example"));
Files.write(directoryPath.resolve("com/example/Example.java"), asList(javaClass));
- List<ClassNode> classNodes = JavaFrontend.readSourceDirectory(directoryPath);
- return new PythonMethodRunner().runMethod(classNodes, TypeName.of("com.example.Example"), "main", asList());
+ return execProgram(
+ directoryPath,
+ TypeName.of("com.example.Example"),
+ "main",
+ asList());
} finally {
deleteRecursively(directoryPath.toFile());
}