-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shared engine is used in two different contexts to demonstrate code/d…
…ata corruptions
- Loading branch information
1 parent
cbc3568
commit 567f802
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
engine/runtime/src/test/java/org/enso/interpreter/test/SharedEngineTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.enso.interpreter.test; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.nio.file.Paths; | ||
|
||
import org.enso.polyglot.RuntimeOptions; | ||
import org.graalvm.polyglot.Context; | ||
import org.graalvm.polyglot.Engine; | ||
import org.graalvm.polyglot.Source; | ||
import static org.junit.Assert.assertEquals; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class SharedEngineTest extends TestBase { | ||
private static Engine sharedEngine; | ||
private Context ctx; | ||
|
||
@BeforeClass | ||
public static void initializeSharedEngine() { | ||
var out = new ByteArrayOutputStream(); | ||
sharedEngine = Engine.newBuilder() | ||
.allowExperimentalOptions(true) | ||
.logHandler(out) | ||
.option(RuntimeOptions.STRICT_ERRORS, "true") | ||
.option( | ||
RuntimeOptions.LANGUAGE_HOME_OVERRIDE, | ||
Paths.get("../../test/micro-distribution/component").toFile().getAbsolutePath() | ||
).build(); | ||
} | ||
|
||
@Before | ||
public void initializeContext() { | ||
this.ctx = Context.newBuilder(). | ||
allowAllAccess(true). | ||
engine(sharedEngine). | ||
build(); | ||
} | ||
|
||
private final Source typeCase = Source.newBuilder("enso", """ | ||
from Standard.Base import Vector, Text, Number | ||
check x = case x of | ||
_ : Vector -> 1 | ||
_ : Text -> 2 | ||
_ : Number -> 3 | ||
_ -> 4 | ||
""", | ||
"type_case.enso" | ||
).buildLiteral(); | ||
|
||
@Test | ||
public void typeCaseFirstRun() { | ||
var fn = this.ctx.eval(typeCase).invokeMember("eval_expression", "check"); | ||
var r = fn.execute("Hi"); | ||
assertEquals(2, r.asInt()); | ||
} | ||
|
||
@Test | ||
public void typeCaseSecondRun() { | ||
typeCaseFirstRun(); | ||
} | ||
} |