From f398933835e7fa7a80b0abd7feda6790370804c8 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 7 Nov 2015 23:20:05 +0000 Subject: Extract Frontend interface from JavaFrontend --- .../zwobble/couscous/tests/JavaToPythonTests.java | 32 ++++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'src/test/java/org') 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 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 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 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()); } -- cgit v1.2.3