aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/couscous/tests/JavaToPythonTests.java
blob: ed66c77d33ecbe8c6d23531bf5e3f59fa21d0eba (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
39
40
41
42
43
44
45
package org.zwobble.couscous.tests;

import org.junit.Ignore;
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.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 {
    @Test
    @Ignore("WIP")
    public void canImplementUserDefinedInterface() {

    }

    protected PrimitiveValue execProgram(
            Path directory,
            TypeName type,
            String methodName,
            List<PrimitiveValue> arguments,
            TypeName 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());
        }
    }
}