Skip to content

Commit

Permalink
Remove most skips on TruffleRuby (#817)
Browse files Browse the repository at this point in the history
* rb_ivar_foreach() is implemented now on TruffleRuby

* Remove most skips on TruffleRuby

* Also improve some ruby engine checks.

* respond_to? should take 2 arguments

* CRuby has a warning for this but somehow it seems silenced by the test suite.

* Test truffleruby-head until 22.3.0 is released
  • Loading branch information
eregon authored Oct 5, 2022
1 parent 00f099b commit 04f9e60
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ '22.2.0' ]
ruby: [ 'head' ]

env:
BUNDLE_GEMFILE: gemfiles/no_rails.gemfile
Expand Down
4 changes: 0 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ task :test_all => [:clean, :compile] do
status = 0

cmds = "ruby test/tests.rb -v && ruby test/tests_mimic.rb -v && ruby test/tests_mimic_addition.rb -v"
if RUBY_ENGINE == 'truffleruby'
# FIXME: Seems TruffleRuby doesn't load the library with `Oj.mimic_JSON` properly. Skip tests_mimic so far.
cmds = "ruby test/tests.rb -v"
end

STDOUT.syswrite "\n#{'#'*90}\n#{cmds}\n"
Bundler.with_original_env do
Expand Down
2 changes: 1 addition & 1 deletion lib/oj/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def buffer_initial_length=(len)
# @param [Symbol] m method symbol
# @return [Boolean] true for any method that matches an instance
# variable reader, otherwise false.
def respond_to?(m)
def respond_to?(m, include_all = false)
return true if super
return true if has_key?(key)
return true if has_key?(key.to_s)
Expand Down
7 changes: 3 additions & 4 deletions test/json_gem/json_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ def foo.to_h
assert_equal '2', state.indent
end

if defined?(JSON::Ext::Generator)
if defined?(JSON::Ext::Generator) && Process.respond_to?(:fork)
# forking to avoid modifying core class of a parent process and
# introducing race conditions of tests are run in parallel
def test_broken_bignum # [ruby-core:38867]
pid = fork do
x = 1 << 64
Expand All @@ -311,9 +313,6 @@ def to_s
end
_, status = Process.waitpid2(pid)
assert status.success?
rescue NotImplementedError
# forking to avoid modifying core class of a parent process and
# introducing race conditions of tests are run in parallel
end
end

Expand Down
4 changes: 1 addition & 3 deletions test/json_gem/json_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ def test_argument_encoding
end if defined?(Encoding::UTF_16)

def test_error_message_encoding
omit 'TruffleRuby causes NameError(<uninitialized constant JSON::Ext>)' if RUBY_ENGINE == 'truffleruby'

bug10705 = '[ruby-core:67386] [Bug #10705]'
json = ".\"\xE2\x88\x9A\"".force_encoding(Encoding::UTF_8)
e = assert_raise(JSON::ParserError) {
JSON::Ext::Parser.new(json).parse
}
assert_equal(Encoding::UTF_8, e.message.encoding, bug10705)
assert_include(e.message, json, bug10705)
end if defined?(Encoding::UTF_8)
end if defined?(Encoding::UTF_8) and defined?(JSON::Ext::Parser)

def test_parsing
parser = JSON::Parser.new('"test"')
Expand Down
8 changes: 0 additions & 8 deletions test/test_custom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ def test_bigdecimal
end

def test_object
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

obj = Jeez.new(true, 58)
json = Oj.dump(obj, create_id: "^o", use_to_json: false, use_as_json: false, use_to_hash: false)
assert_equal(%|{"x":true,"y":58,"_z":"true"}|, json)
Expand Down Expand Up @@ -407,15 +405,11 @@ def test_rational
end

def test_range
skip 'TruffleRuby fails this spec' if RUBY_ENGINE == 'truffleruby'

obj = 3..8
dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
end

def test_date
skip 'TruffleRuby causes SEGV' if RUBY_ENGINE == 'truffleruby'

obj = Date.new(2017, 1, 5)
dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
end
Expand Down Expand Up @@ -445,8 +439,6 @@ def test_date_xmlschema
end

def test_datetime
skip 'TruffleRuby causes SEGV' if RUBY_ENGINE == 'truffleruby'

obj = DateTime.new(2017, 1, 5, 10, 20, 30)
dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
end
Expand Down
13 changes: 3 additions & 10 deletions test/test_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,12 @@ def test_symbol_object

# Time
def test_time_object
skip 'TruffleRuby fails this spec' if RUBY_ENGINE == 'truffleruby'

t = Time.now()
Oj.default_options = { :mode => :object, :time_format => :unix_zone }
dump_and_load(t, false)
end
def test_time_object_early
skip 'Windows does not support dates before 1970.' if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
skip 'TruffleRuby fails this spec' if RUBY_ENGINE == 'truffleruby'

t = Time.xmlschema("1954-01-05T00:00:00.123456")
Oj.default_options = { :mode => :object, :time_format => :unix_zone }
Expand Down Expand Up @@ -165,14 +162,10 @@ def test_json_object_compat
def test_range_object
Oj.default_options = { :mode => :object }
json = Oj.dump(1..7, :mode => :object, :indent => 0)
if 'rubinius' == $ruby
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
elsif 'jruby' == $ruby
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
elsif 'truffleruby' == $ruby
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
else
if $ruby == 'ruby'
assert_equal(%{{"^u":["Range",1,7,false]}}, json)
else
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
end
dump_and_load(1..7, false)
dump_and_load(1..1, false)
Expand Down
2 changes: 0 additions & 2 deletions test/test_gc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def test_parse_compat_gc
end

def test_parse_object_gc
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

g = Goo.new(0, nil)
100.times { |i| g = Goo.new(i, g) }
json = Oj.dump(g, :mode => :object)
Expand Down
44 changes: 3 additions & 41 deletions test/test_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ def test_comment
end

def test_json_module_object
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

obj = One::Two::Three::Deep.new()
dump_and_load(obj, false)
end
Expand Down Expand Up @@ -633,15 +631,11 @@ def test_time_unix_zone_utc
end

def test_json_object
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

obj = Jeez.new(true, 58)
dump_and_load(obj, false)
end

def test_json_object_create_deep
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

obj = One::Two::Three::Deep.new()
dump_and_load(obj, false)
end
Expand Down Expand Up @@ -678,8 +672,6 @@ def test_json_struct2
end

def test_json_anonymous_struct
skip 'TruffleRuby fails this spec with `TypeError: allocator undefined for Class`' if RUBY_ENGINE == 'truffleruby'

s = Struct.new(:x, :y)
obj = s.new(1, 2)
json = Oj.dump(obj, :indent => 2, :mode => :object)
Expand All @@ -702,8 +694,6 @@ def test_mixed_hash_object
end

def test_json_object_object
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

obj = Jeez.new(true, 58)
json = Oj.dump(obj, mode: :object, indent: 2, ignore_under: true)
assert(%{{
Expand All @@ -723,8 +713,6 @@ def test_json_object_object
end

def test_to_hash_object_object
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

obj = Jazz.new(true, 58)
json = Oj.dump(obj, :mode => :object, :indent => 2)
assert(%{{
Expand All @@ -744,8 +732,6 @@ def test_to_hash_object_object
end

def test_as_json_object_object
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

obj = Orange.new(true, 58)
json = Oj.dump(obj, :mode => :object, :indent => 2)
assert(%{{
Expand All @@ -765,8 +751,6 @@ def test_as_json_object_object
end

def test_object_object_no_cache
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

obj = Jam.new(true, 58)
json = Oj.dump(obj, :mode => :object, :indent => 2)
assert(%{{
Expand Down Expand Up @@ -795,8 +779,6 @@ def test_ignore
end

def test_exception
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

err = nil
begin
raise StandardError.new('A Message')
Expand Down Expand Up @@ -827,8 +809,6 @@ def initialize
end

def test_exception_subclass
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

err = nil
begin
raise SubX.new
Expand All @@ -848,12 +828,10 @@ def test_exception_subclass
def test_range_object
Oj.default_options = { :mode => :object }
json = Oj.dump(1..7, :mode => :object, :indent => 0)
if 'rubinius' == $ruby
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
elsif 'truffleruby' == $ruby
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
else
if 'ruby' == $ruby
assert_equal(%{{"^u":["Range",1,7,false]}}, json)
else
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
end
dump_and_load(1..7, false)
dump_and_load(1..1, false)
Expand Down Expand Up @@ -917,8 +895,6 @@ def test_circular_hash2
end

def test_circular_object
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

obj = Jeez.new(nil, 58)
obj.x = obj
json = Oj.dump(obj, :mode => :object, :indent => 2, :circular => true)
Expand All @@ -927,8 +903,6 @@ def test_circular_object
end

def test_circular_object2
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

obj = Jam.new(nil, 58)
obj.x = obj
json = Oj.dump(obj, :mode => :object, :indent => 2, :circular => true)
Expand All @@ -951,8 +925,6 @@ def test_circular_object2
end

def test_circular
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

h = { 'a' => 7 }
obj = Jeez.new(h, 58)
obj.x['b'] = obj
Expand All @@ -963,8 +935,6 @@ def test_circular
end

def test_circular2
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

h = { 'a' => 7 }
obj = Jam.new(h, 58)
obj.x['b'] = obj
Expand All @@ -977,8 +947,6 @@ def test_circular2
end

def test_omit_nil
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

jam = Jam.new({'a' => 1, 'b' => nil }, nil)

json = Oj.dump(jam, :omit_nil => true, :mode => :object)
Expand Down Expand Up @@ -1033,22 +1001,16 @@ def test_odd_mod
end

def test_auto_string
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

s = AutoStrung.new("Pete", true)
dump_and_load(s, false)
end

def test_auto_array
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

a = AutoArray.new([1, 'abc', nil], true)
dump_and_load(a, false)
end

def test_auto_hash
skip 'TruffleRuby fails this spec with `RuntimeError: rb_ivar_foreach not implemented`' if RUBY_ENGINE == 'truffleruby'

h = AutoHash.new(nil, true)
h['a'] = 1
h['b'] = 2
Expand Down
6 changes: 2 additions & 4 deletions test/test_scp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ def test_null_string
end

def test_pipe
skip ' Windows does not support fork' if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
skip 'TruffleRuby fails this spec with `NotImplementedError: fork is not available`' if RUBY_ENGINE == 'truffleruby'
skip 'needs fork' unless Process.respond_to?(:fork)

handler = AllHandler.new()
json = %{{"one":true,"two":false}}
Expand Down Expand Up @@ -357,8 +356,7 @@ def test_bad_bignum
end

def test_pipe_close
skip 'Windows does not support fork' if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
skip 'TruffleRuby fails this spec with `NotImplementedError: fork is not available`' if RUBY_ENGINE == 'truffleruby'
skip 'needs fork' unless Process.respond_to?(:fork)

json = %{{"one":true,"two":false}}
IO.pipe do |read_io, write_io|
Expand Down
5 changes: 2 additions & 3 deletions test/test_various.rb
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,6 @@ def test_io_string
end

def test_io_file
# Windows does not support fork
return if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/

src = { 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}
filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
File.open(filename, "w") { |f|
Expand All @@ -574,6 +571,8 @@ def test_io_file
end

def test_io_stream
skip 'needs fork' unless Process.respond_to?(:fork)

IO.pipe do |r, w|
if fork
r.close
Expand Down

0 comments on commit 04f9e60

Please sign in to comment.