blob: f482d115343115542393259d4aa5f0c798992786 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package org.zwobble.couscous.tests;
import org.zwobble.couscous.CouscousCompiler;
import org.zwobble.couscous.types.ScalarType;
import org.zwobble.couscous.backends.python.PythonBackend;
import org.zwobble.couscous.frontends.java.JavaFrontend;
import org.zwobble.couscous.tests.backends.python.PythonMethodRunner;
import org.zwobble.couscous.values.PrimitiveValue;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.zwobble.couscous.tests.util.ExtraFiles.deleteRecursively;
import static org.zwobble.couscous.util.ExtraLists.list;
public class JavaToPythonTests extends CompilerTests {
protected PrimitiveValue execProgram(
Path directory,
ScalarType type,
String methodName,
List<PrimitiveValue> arguments,
ScalarType returnType) throws IOException, InterruptedException {
Path directoryPath = Files.createTempDirectory(null);
try {
CouscousCompiler compiler = new CouscousCompiler(
new JavaFrontend(),
new PythonBackend(directoryPath, "couscous"));
compiler.compileDirectory(list(directory), directory);
return PythonMethodRunner.runFunction(directoryPath, type, methodName, arguments, returnType);
} finally {
deleteRecursively(directoryPath.toFile());
}
}
}
|