Skip to content

Commit 005ac87

Browse files
committed
Add a test that local variables aren't shared between interactive and non-interactive sources
1 parent 017c844 commit 005ac87

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/test/java/org/truffleruby/PolyglotInteropTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,22 @@ public void testLocalVariablesSharedBetweenInteractiveEvalChangesParsing() {
189189
}
190190
}
191191

192+
@Test
193+
public void testLocalVariablesAreNotSharedBetweenInteractiveAndNonInteractive() {
194+
try (Context polyglot = Context.newBuilder()
195+
.option(OptionsCatalog.HOME.getName(), System.getProperty("user.dir"))
196+
.allowAllAccess(true)
197+
.build()) {
198+
polyglot.eval(Source.newBuilder("ruby", "a = 14", "test").interactive(false).buildLiteral());
199+
polyglot.eval(Source.newBuilder("ruby", "b = 2", "test").interactive(true).buildLiteral());
200+
assertTrue(polyglot.eval(Source.newBuilder("ruby", "defined?(a).nil?", "test").interactive(true).buildLiteral()).asBoolean());
201+
assertTrue(polyglot.eval(Source.newBuilder("ruby", "defined?(b).nil?", "test").interactive(false).buildLiteral()).asBoolean());
202+
assertFalse(polyglot.eval(Source.newBuilder("ruby", "defined?(b).nil?", "test").interactive(true).buildLiteral()).asBoolean());
203+
assertTrue(polyglot.eval(Source.newBuilder("ruby", "TOPLEVEL_BINDING.eval('defined?(a).nil?')", "test").interactive(false).buildLiteral()).asBoolean());
204+
assertTrue(polyglot.eval(Source.newBuilder("ruby", "TOPLEVEL_BINDING.eval('defined?(b).nil?')", "test").interactive(false).buildLiteral()).asBoolean());
205+
assertTrue(polyglot.eval(Source.newBuilder("ruby", "TOPLEVEL_BINDING.eval('defined?(a).nil?')", "test").interactive(true).buildLiteral()).asBoolean());
206+
assertTrue(polyglot.eval(Source.newBuilder("ruby", "TOPLEVEL_BINDING.eval('defined?(b).nil?')", "test").interactive(true).buildLiteral()).asBoolean());
207+
}
208+
}
209+
192210
}

0 commit comments

Comments
 (0)