Search in sources :

Example 11 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class SourceBuilderTest method jarURLGetsAName.

@Test
public void jarURLGetsAName() throws IOException {
    File sample = File.createTempFile("sample", ".jar");
    sample.deleteOnExit();
    JarOutputStream os = new JarOutputStream(new FileOutputStream(sample));
    os.putNextEntry(new ZipEntry("x.js"));
    os.write("Hi!".getBytes("UTF-8"));
    os.closeEntry();
    os.close();
    URL resource = new URL("jar:" + sample.toURI() + "!/x.js");
    assertNotNull("Resource found", resource);
    assertEquals("JAR protocol", "jar", resource.getProtocol());
    Source s = Source.newBuilder(resource).build();
    assertEquals("Hi!", s.getCharacters());
    assertEquals("x.js", s.getName());
    sample.delete();
}
Also used : FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream) File(java.io.File) URL(java.net.URL) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 12 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class InitializationTest method checkPostInitializationInRunMethod.

@Test
public void checkPostInitializationInRunMethod() throws Exception {
    vm = PolyglotEngine.newBuilder().build();
    Source source = Source.newBuilder("accessProbeForAbstractLanguage text").mimeType("application/x-abstrlang").name("sample.txt").build();
    assertEquals("Properly evaluated", 42, vm.eval(source).get());
    Object global = vm.findGlobalSymbol("MyEnv").get();
    assertNotNull(global);
    assertTrue(global instanceof MyEnv);
    MyEnv env = (MyEnv) global;
    assertEquals("Post initialization hook called", 1, env.cnt);
}
Also used : Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 13 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class InteractiveEvalTest method testDefaultInteractiveLanguageDirectly.

@Test
public void testDefaultInteractiveLanguageDirectly() throws UnsupportedEncodingException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PolyglotEngine engine = PolyglotEngine.newBuilder().setOut(out).build();
    Source s = Source.newBuilder("").mimeType("application/x-test-definteract").name("definteract").interactive().build();
    PolyglotEngine.Value value = engine.getLanguages().get("application/x-test-definteract").eval(s);
    Assert.assertEquals("42", value.get());
    String strOutput = out.toString(StandardCharsets.UTF_8.name());
    Assert.assertEquals("42" + System.getProperty("line.separator"), strOutput);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 14 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class InteractiveEvalTest method testSpecialInteractiveLanguage.

@Test
public void testSpecialInteractiveLanguage() throws UnsupportedEncodingException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PolyglotEngine engine = PolyglotEngine.newBuilder().setOut(out).build();
    Source s = Source.newBuilder("").mimeType("application/x-test-specinteract").name("specinteract").interactive().build();
    PolyglotEngine.Value value = engine.eval(s);
    Assert.assertEquals("42", value.get());
    String strOutput = out.toString(StandardCharsets.UTF_8.name());
    Assert.assertEquals("\"42\"", strOutput);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Example 15 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class InteractiveEvalTest method testSpecialNoninteractiveLanguage.

@Test
public void testSpecialNoninteractiveLanguage() throws UnsupportedEncodingException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    PolyglotEngine engine = PolyglotEngine.newBuilder().setOut(out).build();
    Source s = Source.newBuilder("").mimeType("application/x-test-specinteract").name("specnoninteract").build();
    PolyglotEngine.Value value = engine.eval(s);
    Assert.assertEquals("42", value.get());
    String strOutput = out.toString(StandardCharsets.UTF_8.name());
    Assert.assertTrue(strOutput.isEmpty());
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Source(com.oracle.truffle.api.source.Source) Test(org.junit.Test)

Aggregations

Source (com.oracle.truffle.api.source.Source)113 Test (org.junit.Test)65 RootNode (com.oracle.truffle.api.nodes.RootNode)23 File (java.io.File)20 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)16 Node (com.oracle.truffle.api.nodes.Node)16 SourceSection (com.oracle.truffle.api.source.SourceSection)16 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)15 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)11 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 CallTarget (com.oracle.truffle.api.CallTarget)5 FileWriter (java.io.FileWriter)5 RootCallTarget (com.oracle.truffle.api.RootCallTarget)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)3 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)3 Script (com.oracle.truffle.tools.chromeinspector.types.Script)3