Search in sources :

Example 1 with CaptureOutput

use of com.oracle.truffle.llvm.tests.pipe.CaptureOutput in project graal by oracle.

the class ToolchainAPITest method testCC.

@Test
public void testCC() throws IOException, InterruptedException {
    File src = File.createTempFile(ToolchainAPITest.class.getSimpleName(), ".c");
    src.deleteOnExit();
    File dst = File.createTempFile(ToolchainAPITest.class.getSimpleName(), ".out");
    dst.deleteOnExit();
    write(src, HELLO_WORLD_C);
    int compileResult = compile("CC", src, dst);
    Assert.assertEquals("compiler result", 0, compileResult);
    try (CaptureOutput out = new CaptureNativeOutput()) {
        int runResult = load(dst).execute().asInt();
        Assert.assertEquals("run result", 0, runResult);
        Assert.assertEquals("Hello World!", out.getStdOut());
    }
}
Also used : CaptureOutput(com.oracle.truffle.llvm.tests.pipe.CaptureOutput) CaptureNativeOutput(com.oracle.truffle.llvm.tests.pipe.CaptureNativeOutput) TruffleFile(com.oracle.truffle.api.TruffleFile) File(java.io.File) Test(org.junit.Test)

Example 2 with CaptureOutput

use of com.oracle.truffle.llvm.tests.pipe.CaptureOutput in project graal by oracle.

the class ToolchainAPITest method testCXX.

@Test
public void testCXX() throws IOException, InterruptedException {
    File src = File.createTempFile(ToolchainAPITest.class.getSimpleName(), ".cpp");
    src.deleteOnExit();
    File dst = File.createTempFile(ToolchainAPITest.class.getSimpleName(), ".out");
    dst.deleteOnExit();
    write(src, HELLO_WORLD_CXX);
    int compileResult = compile("CXX", src, dst);
    Assert.assertEquals("compiler result", 0, compileResult);
    try (CaptureOutput out = new CaptureNativeOutput()) {
        int runResult = load(dst).execute().asInt();
        Assert.assertEquals("run result", 0, runResult);
        Assert.assertEquals("Hello World!", out.getStdOut());
    }
}
Also used : CaptureOutput(com.oracle.truffle.llvm.tests.pipe.CaptureOutput) CaptureNativeOutput(com.oracle.truffle.llvm.tests.pipe.CaptureNativeOutput) TruffleFile(com.oracle.truffle.api.TruffleFile) File(java.io.File) Test(org.junit.Test)

Example 3 with CaptureOutput

use of com.oracle.truffle.llvm.tests.pipe.CaptureOutput in project graal by oracle.

the class CaptureOutputTest method testOutputCapturing.

@Test
public void testOutputCapturing() throws IOException {
    String string = "Testoutput";
    String captured;
    try (CaptureOutput out = new CaptureNativeOutput()) {
        System.out.print(string);
        captured = out.getStdOut();
    }
    System.out.println("MUST NOT BE IN CAPTURE");
    assertEquals(string, captured);
}
Also used : CaptureOutput(com.oracle.truffle.llvm.tests.pipe.CaptureOutput) CaptureNativeOutput(com.oracle.truffle.llvm.tests.pipe.CaptureNativeOutput) Test(org.junit.Test)

Example 4 with CaptureOutput

use of com.oracle.truffle.llvm.tests.pipe.CaptureOutput in project graal by oracle.

the class CaptureOutputTest method testBigOutput.

@Test
public void testBigOutput() throws IOException {
    StringBuilder result = new StringBuilder();
    String capture;
    try (CaptureOutput out = new CaptureNativeOutput()) {
        for (int i = 0; i < 9000; i++) {
            String line = String.format("line %04d\n", i);
            System.out.print(line);
            result.append(line);
        }
        capture = out.getStdOut();
    }
    assertEquals(result.toString(), capture);
}
Also used : CaptureOutput(com.oracle.truffle.llvm.tests.pipe.CaptureOutput) CaptureNativeOutput(com.oracle.truffle.llvm.tests.pipe.CaptureNativeOutput) Test(org.junit.Test)

Example 5 with CaptureOutput

use of com.oracle.truffle.llvm.tests.pipe.CaptureOutput in project graal by oracle.

the class PolyglotToolchainTest method testLDLibraryPath.

@Test
public void testLDLibraryPath() throws IOException {
    try (CaptureOutput out = new CaptureNativeOutput()) {
        testLibrary.getMember("print_ld_library_path").execute();
        Assert.assertEquals(String.format("LD_LIBRARY_PATH=%s\n", getToolchain().getPaths("LD_LIBRARY_PATH").stream().map(TruffleFile::toString).collect(Collectors.joining(":"))), out.getStdOut());
    }
}
Also used : CaptureOutput(com.oracle.truffle.llvm.tests.pipe.CaptureOutput) CaptureNativeOutput(com.oracle.truffle.llvm.tests.pipe.CaptureNativeOutput) Test(org.junit.Test)

Aggregations

CaptureOutput (com.oracle.truffle.llvm.tests.pipe.CaptureOutput)11 CaptureNativeOutput (com.oracle.truffle.llvm.tests.pipe.CaptureNativeOutput)10 Test (org.junit.Test)10 TruffleFile (com.oracle.truffle.api.TruffleFile)2 File (java.io.File)2 LLVMLinkerException (com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)1 Context (org.graalvm.polyglot.Context)1 Builder (org.graalvm.polyglot.Context.Builder)1 Value (org.graalvm.polyglot.Value)1