From 04f9e60d0157900a753d56b8ba5e47a7db3e8102 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 6 Oct 2022 01:03:37 +0200 Subject: [PATCH] Remove most skips on TruffleRuby (#817) * 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 --- .github/workflows/CI.yml | 2 +- Rakefile | 4 --- lib/oj/state.rb | 2 +- test/json_gem/json_generator_test.rb | 7 ++--- test/json_gem/json_parser_test.rb | 4 +-- test/test_custom.rb | 8 ----- test/test_file.rb | 13 ++------ test/test_gc.rb | 2 -- test/test_object.rb | 44 ++-------------------------- test/test_scp.rb | 6 ++-- test/test_various.rb | 5 ++-- 11 files changed, 16 insertions(+), 81 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index def02cc7..13179f73 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -83,7 +83,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: [ '22.2.0' ] + ruby: [ 'head' ] env: BUNDLE_GEMFILE: gemfiles/no_rails.gemfile diff --git a/Rakefile b/Rakefile index 1bfe5b9e..bf5fe986 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/lib/oj/state.rb b/lib/oj/state.rb index c5bb7746..c191cf6e 100644 --- a/lib/oj/state.rb +++ b/lib/oj/state.rb @@ -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) diff --git a/test/json_gem/json_generator_test.rb b/test/json_gem/json_generator_test.rb index 1d4d28d0..0c16ed68 100644 --- a/test/json_gem/json_generator_test.rb +++ b/test/json_gem/json_generator_test.rb @@ -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 @@ -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 diff --git a/test/json_gem/json_parser_test.rb b/test/json_gem/json_parser_test.rb index fc4bbe22..23311fcf 100644 --- a/test/json_gem/json_parser_test.rb +++ b/test/json_gem/json_parser_test.rb @@ -24,8 +24,6 @@ def test_argument_encoding end if defined?(Encoding::UTF_16) def test_error_message_encoding - omit 'TruffleRuby causes NameError()' if RUBY_ENGINE == 'truffleruby' - bug10705 = '[ruby-core:67386] [Bug #10705]' json = ".\"\xE2\x88\x9A\"".force_encoding(Encoding::UTF_8) e = assert_raise(JSON::ParserError) { @@ -33,7 +31,7 @@ def test_error_message_encoding } 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"') diff --git a/test/test_custom.rb b/test/test_custom.rb index 352181e4..ba680b1f 100755 --- a/test/test_custom.rb +++ b/test/test_custom.rb @@ -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) @@ -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 @@ -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 diff --git a/test/test_file.rb b/test/test_file.rb index 84b41707..6c3ed102 100755 --- a/test/test_file.rb +++ b/test/test_file.rb @@ -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 } @@ -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) diff --git a/test/test_gc.rb b/test/test_gc.rb index 60ed5043..c9c95eb6 100755 --- a/test/test_gc.rb +++ b/test/test_gc.rb @@ -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) diff --git a/test/test_object.rb b/test/test_object.rb index 5d6dd336..5ac65ec2 100755 --- a/test/test_object.rb +++ b/test/test_object.rb @@ -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 @@ -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 @@ -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) @@ -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(%{{ @@ -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(%{{ @@ -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(%{{ @@ -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(%{{ @@ -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') @@ -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 @@ -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) @@ -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) @@ -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) @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/test/test_scp.rb b/test/test_scp.rb index 43bb655c..218f669a 100755 --- a/test/test_scp.rb +++ b/test/test_scp.rb @@ -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}} @@ -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| diff --git a/test/test_various.rb b/test/test_various.rb index d6bea7b6..f73263e0 100755 --- a/test/test_various.rb +++ b/test/test_various.rb @@ -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| @@ -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