Skip to content

Commit a9fe845

Browse files
authored
Merge pull request #3008 from ruby/claude/practical-mendel-hnqws8-4
Run the test suite on JRuby (JRuby support, step 4)
2 parents 5021db6 + 432c6ac commit a9fe845

13 files changed

Lines changed: 55 additions & 15 deletions

.github/workflows/jruby.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ on:
1010
- "include/**"
1111
- "src/**"
1212
- "wasm/**"
13-
- "lib/rbs/wasm/**"
14-
- "lib/rbs.rb"
13+
- "lib/**"
14+
- "sig/**"
15+
- "core/**"
16+
- "stdlib/**"
17+
- "test/**"
1518
- "Rakefile"
19+
- "rbs.gemspec"
1620

1721
permissions:
1822
contents: read
@@ -58,8 +62,6 @@ jobs:
5862
ruby-version: jruby
5963
bundler: none
6064
- name: Install runtime and test gems
61-
run: gem install prism test-unit --no-document
62-
- name: Run RBS's parser on JRuby
63-
run: |
64-
jruby -Ilib -Itest test/rbs/wasm/jruby_parser_test.rb
65-
jruby -Ilib -Itest test/rbs/parser_test.rb
65+
run: gem install prism rake rake-compiler test-unit rdoc rspec minitest json-schema pry --no-document
66+
- name: Run the test suite on JRuby
67+
run: jruby -S rake test

Rakefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ test_config = lambda do |t|
3333
end
3434
end
3535

36-
Rake::TestTask.new(test: :compile, &test_config)
36+
if RUBY_ENGINE == "jruby"
37+
# JRuby runs the parser in WebAssembly instead of the C extension, so there is
38+
# nothing to compile. The wasm runtime must be assembled first with
39+
# `rake wasm:jruby_setup` (which needs CRuby + the WASI SDK).
40+
Rake::TestTask.new(:test, &test_config)
41+
else
42+
Rake::TestTask.new(test: :compile, &test_config)
43+
end
3744

3845
multitask :default => [:test, :stdlib_test, :typecheck_test, :rubocop, :validate, :test_doc]
3946

lib/rbs.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
require "set"
66
require "json"
7-
require "pathname" unless defined?(Pathname)
7+
# Always require pathname: `Pathname()` (Kernel#Pathname) is only defined once
8+
# pathname is loaded. Guarding on `defined?(Pathname)` is wrong because another
9+
# library (e.g. Bundler) can define the Pathname constant without that method,
10+
# which left RBS::EnvironmentLoader's `Pathname(...)` undefined on JRuby.
11+
require "pathname"
812
require "pp"
913
require "logger"
1014
require "tsort"

lib/rbs/wasm/location.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def [](name)
5555
return range && Location.new(@buffer, range[0], range[1])
5656
end
5757

58-
nil
58+
raise "Unknown child name given: #{name}"
5959
end
6060
end
6161
end

rbs.gemspec

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,17 @@ Gem::Specification.new do |spec|
3636
end
3737
end
3838

39-
# JRuby cannot load the MRI C extension. The `java` platform gem ships the
40-
# prebuilt WebAssembly parser and the Chicory jars instead (assembled by
41-
# `rake wasm:jruby_setup`), and RBS loads the WebAssembly-backed parser.
42-
if ENV["RBS_PLATFORM"] == "java" || (defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby")
43-
spec.platform = "java"
39+
# JRuby cannot load the MRI C extension. On JRuby (and in the `java` platform
40+
# gem, built with RBS_PLATFORM=java) RBS runs the WebAssembly-backed parser, so
41+
# ship the prebuilt parser and the Chicory jars (assembled by
42+
# `rake wasm:jruby_setup`) and skip the C extension.
43+
building_java_gem = ENV["RBS_PLATFORM"] == "java"
44+
on_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
45+
46+
if building_java_gem || on_jruby
47+
# Only stamp the platform when building the release gem; leave it unset for
48+
# local development on JRuby so it still matches a `ruby` platform lockfile.
49+
spec.platform = "java" if building_java_gem
4450
spec.files += Dir.chdir(File.expand_path('..', __FILE__)) do
4551
Dir.glob("lib/rbs/wasm/rbs_parser.wasm") + Dir.glob("lib/rbs/wasm/jars/*.jar")
4652
end

test/rbs/ast/ruby/comment_block_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def test__buffer__multi_line_prefix_header_line
6161

6262
def test_build
6363
omit_on_truffle_ruby! "`Prism::Location#start_line_slice` returns `nil` on TruffleRuby's prism"
64+
omit_on_jruby! "`Prism::Location#start_line_slice` returns `nil` on JRuby's prism"
6465

6566
buffer, comments = parse_comments(<<~RUBY)
6667
# Comment1
@@ -191,6 +192,7 @@ def test_each_paragraph_colon
191192

192193
def test_trailing_annotation
193194
omit_on_truffle_ruby! "`Prism::Location#start_line_slice` returns `nil` on TruffleRuby's prism"
195+
omit_on_jruby! "`Prism::Location#start_line_slice` returns `nil` on JRuby's prism"
194196

195197
buffer, comments = parse_comments(<<~RUBY)
196198
foo #: String
@@ -223,6 +225,7 @@ def test_trailing_annotation
223225

224226
def test_trailing_annotation_type_application
225227
omit_on_truffle_ruby! "`Prism::Location#start_line_slice` returns `nil` on TruffleRuby's prism"
228+
omit_on_jruby! "`Prism::Location#start_line_slice` returns `nil` on JRuby's prism"
226229

227230
buffer, comments = parse_comments(<<~RUBY)
228231
foo #[String]

test/rbs/cli_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ def test_parse_method_type
892892

893893
def test_prototype_no_parser
894894
omit_on_truffle_ruby! "`rbs prototype` requires `RubyVM::AbstractSyntaxTree`, which is not available on TruffleRuby"
895+
omit_on_jruby! "`rbs prototype` requires `RubyVM::AbstractSyntaxTree`, which is not available on JRuby"
895896

896897
Dir.mktmpdir do |dir|
897898
with_cli do |cli|
@@ -910,6 +911,7 @@ def cli.has_parser?
910911

911912
def test_prototype_batch
912913
omit_on_truffle_ruby! "`rbs prototype` requires `RubyVM::AbstractSyntaxTree`, which is not available on TruffleRuby"
914+
omit_on_jruby! "`rbs prototype` requires `RubyVM::AbstractSyntaxTree`, which is not available on JRuby"
913915

914916
Dir.mktmpdir do |dir|
915917
dir = Pathname(dir)
@@ -973,6 +975,7 @@ module C
973975

974976
def test_prototype_batch_outer
975977
omit_on_truffle_ruby! "`rbs prototype` requires `RubyVM::AbstractSyntaxTree`, which is not available on TruffleRuby"
978+
omit_on_jruby! "`rbs prototype` requires `RubyVM::AbstractSyntaxTree`, which is not available on JRuby"
976979

977980
Dir.mktmpdir do |dir|
978981
dir = Pathname(dir)
@@ -1001,6 +1004,7 @@ module A
10011004

10021005
def test_prototype_batch_syntax_error
10031006
omit_on_truffle_ruby! "`rbs prototype` requires `RubyVM::AbstractSyntaxTree`, which is not available on TruffleRuby"
1007+
omit_on_jruby! "`rbs prototype` requires `RubyVM::AbstractSyntaxTree`, which is not available on JRuby"
10041008

10051009
Dir.mktmpdir do |dir|
10061010
dir = Pathname(dir)
@@ -1051,6 +1055,7 @@ def test_prototype__runtime__todo
10511055

10521056
def test_test
10531057
omit_on_truffle_ruby! "`rbs test` relies on `TracePoint` `:end` event, which is not supported on TruffleRuby"
1058+
omit_on_jruby! "`rbs test` relies on `TracePoint` `:end` event, which is not supported on JRuby"
10541059

10551060
Dir.mktmpdir do |dir|
10561061
dir = Pathname(dir)
@@ -1078,6 +1083,8 @@ def foo: () -> void
10781083
end
10791084

10801085
def test_collection_install
1086+
omit_on_jruby! "`rbs collection install` runs `bundle install`, which builds native gem extensions that do not compile on JRuby"
1087+
10811088
Dir.mktmpdir do |dir|
10821089
Dir.chdir(dir) do
10831090
dir = Pathname(dir)
@@ -1144,6 +1151,8 @@ def test_collection_install_frozen
11441151
end
11451152

11461153
def test_collection_update
1154+
omit_on_jruby! "`rbs collection update` runs `bundle install`, which builds native gem extensions that do not compile on JRuby"
1155+
11471156
Dir.mktmpdir do |dir|
11481157
Dir.chdir(dir) do
11491158
dir = Pathname(dir)
@@ -1167,6 +1176,8 @@ def test_collection_update
11671176
end
11681177

11691178
def test_collection_install_gemspec
1179+
omit_on_jruby! "`rbs collection install` runs `bundle install`, which builds native gem extensions that do not compile on JRuby"
1180+
11701181
Dir.mktmpdir do |dir|
11711182
Dir.chdir(dir) do
11721183
dir = Pathname(dir)

test/rbs/node_usage_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def parse(string)
99

1010
def test_conditional
1111
omit_on_truffle_ruby! "`RubyVM::AbstractSyntaxTree` is not available on TruffleRuby"
12+
omit_on_jruby! "`RubyVM::AbstractSyntaxTree` is not available on JRuby"
1213

1314
NodeUsage.new(parse(<<~RB))
1415
def block

test/rbs/rb_prototype_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class RBS::RbPrototypeTest < Test::Unit::TestCase
44
omit_on_truffle_ruby! "`RubyVM::AbstractSyntaxTree` is not available on TruffleRuby"
5+
omit_on_jruby! "`RubyVM::AbstractSyntaxTree` is not available on JRuby"
56

67
RB = RBS::Prototype::RB
78

test/rbs/rbi_prototype_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class RBS::RbiPrototypeTest < Test::Unit::TestCase
44
omit_on_truffle_ruby! "`RubyVM::AbstractSyntaxTree` is not available on TruffleRuby"
5+
omit_on_jruby! "`RubyVM::AbstractSyntaxTree` is not available on JRuby"
56

67
RBI = RBS::Prototype::RBI
78

0 commit comments

Comments
 (0)