blob: d2d62b199446bf2e08e624071fa89b12877f3953 (
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
38
|
package org.zwobble.couscous.tests;
import com.google.common.collect.ImmutableList;
import org.junit.Test;
import org.zwobble.couscous.CouscousCompiler;
import org.zwobble.couscous.ast.TypeName;
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.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.zwobble.couscous.tests.util.ExtraFiles.deleteRecursively;
public class JavaToPythonTests extends CompilerTests {
protected 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(ImmutableList.of(directory), directory);
return PythonMethodRunner.runFunction(directoryPath, type, methodName, arguments);
} finally {
deleteRecursively(directoryPath.toFile());
}
}
}
|