Skip to content

Commit 278f643

Browse files
committed
Add specs for Truffle::Interop.languages and other_languages?
1 parent 35ebc41 commit 278f643

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fails(GR-24618):Truffle::Interop.other_languages? returns true with --polyglot
2+
slow:Truffle::Interop.languages returns only ruby from the RubyLauncher
3+
slow:Truffle::Interop.other_languages? returns false without --polyglot
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 2.0, or
6+
# GNU General Public License version 2, or
7+
# GNU Lesser General Public License version 2.1.
8+
9+
require_relative '../../ruby/spec_helper'
10+
11+
describe "Truffle::Interop.languages" do
12+
it "returns the public languages" do
13+
Truffle::Interop.languages.should.include?('ruby')
14+
end
15+
16+
guard_not -> { TruffleRuby.native? and Truffle::Boot.was_preinitialized? } do # GR-24618
17+
it "returns only ruby from the RubyLauncher" do
18+
# Use RbConfig.ruby to remove a potential --polyglot option
19+
`#{RbConfig.ruby} -e 'p Truffle::Interop.languages'`.should == "[\"ruby\"]\n"
20+
end
21+
end
22+
end
23+
24+
describe "Truffle::Interop.other_languages?" do
25+
guard_not -> { TruffleRuby.native? } do
26+
it "returns true with --polyglot" do
27+
ruby_exe('p Truffle::Interop.other_languages?', options: '--polyglot').should == "true\n"
28+
end
29+
end
30+
31+
it "returns false without --polyglot" do
32+
# Use RbConfig.ruby to remove a potential --polyglot option
33+
`#{RbConfig.ruby} -e 'p Truffle::Interop.other_languages?'`.should == "false\n"
34+
end
35+
end

src/main/java/org/truffleruby/interop/InteropNodes.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,16 @@ protected DynamicObject languages() {
10561056

10571057
}
10581058

1059+
@CoreMethod(names = "other_languages?", onSingleton = true, required = 0)
1060+
public abstract static class HasOtherLanguagesNode extends CoreMethodArrayArgumentsNode {
1061+
1062+
@Specialization
1063+
protected boolean hasOtherlanguages() {
1064+
return getContext().hasOtherPublicLanguages();
1065+
}
1066+
1067+
}
1068+
10591069
@CoreMethod(names = "eval", onSingleton = true, required = 2)
10601070
@ImportStatic({ StringCachingGuards.class, StringOperations.class })
10611071
@ReportPolymorphism

0 commit comments

Comments
 (0)