Skip to content

Commit

Permalink
CI: Fix failures with Ruby 3.5-dev (#957)
Browse files Browse the repository at this point in the history
* CI: Fix failure in test_allocate

Since ruby/ruby@599fbeaffa, it causes failure in test_allocate

```
=========================================================================================================================================================================================================================================
Failure: test_allocate(JSONExtParserTest):
  [ruby-core:35079].
  <TypeError> exception was expected but none was thrown.
test/json_gem/json_ext_parser_test.rb:14:in 'JSONExtParserTest#test_allocate'
     11:   if defined?(JSON::Ext::Parser)
     12:     def test_allocate
     13:       parser = JSON::Ext::Parser.new("{}")
  => 14:       assert_raise(TypeError, '[ruby-core:35079]') do
     15:         parser.__send__(:initialize, "{}")
     16:       end
     17:       parser = JSON::Ext::Parser.allocate
```

* CI: Fix failure in test_fast_state/test_pretty_state/test_safe_state

Since ruby/ruby@89e316ad06,  it causes failure in test_fast_state/test_pretty_state/test_safe_state
```
=========================================================================================================================================================================================================================================
Failure: test_fast_state(JSONGeneratorTest)
test/json_gem/json_generator_test.rb:191:in 'JSONGeneratorTest#test_fast_state'
     188:     actual.delete(:escape_slash)
     189:     actual.delete(:strict)
     190:     actual.delete(:script_safe)
  => 191:     assert_equal({
     192:       :allow_nan             => false,
     193:       :array_nl              => "",
     194:       :ascii_only            => false,
<[[:allow_nan, false],
 [:array_nl, ""],
 [:ascii_only, false],
 [:buffer_initial_length, 1024],
 [:depth, 0],
 [:indent, ""],
 [:max_nesting, 0],
 [:object_nl, ""],
 [:space, ""],
 [:space_before, ""]]> expected but was
<[[:allow_nan, false],
 [:array_nl, ""],
 [:as_json, false],
 [:ascii_only, false],
 [:buffer_initial_length, 1024],
 [:depth, 0],
 [:indent, ""],
 [:max_nesting, 0],
 [:object_nl, ""],
 [:space, ""],
 [:space_before, ""]]>

diff:
  [[:allow_nan, false],
   [:array_nl, ""],
+  [:as_json, false],
   [:ascii_only, false],
   [:buffer_initial_length, 1024],
   [:depth, 0],
   [:indent, ""],
   [:max_nesting, 0],
   [:object_nl, ""],
   [:space, ""],
   [:space_before, ""]]
=========================================================================================================================================================================================================================================
```
  • Loading branch information
Watson1978 authored Feb 8, 2025
1 parent b61d931 commit 5b65384
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
22 changes: 17 additions & 5 deletions test/json_gem/json_ext_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,25 @@ class JSONExtParserTest < Test::Unit::TestCase
include Test::Unit::TestCaseOmissionSupport

if defined?(JSON::Ext::Parser)
def test_allocate
parser = JSON::Ext::Parser.new("{}")
assert_raise(TypeError, '[ruby-core:35079]') do
if REAL_JSON_GEM && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.5.0')
def test_allocate
parser = JSON::Ext::Parser.new("{}")
parser.__send__(:initialize, "{}")
assert_equal "{}", parser.source

parser = JSON::Ext::Parser.allocate
assert_nil parser.source
end
else
# Ruby 3.4.x or before
def test_allocate
parser = JSON::Ext::Parser.new("{}")
assert_raise(TypeError, '[ruby-core:35079]') do
parser.__send__(:initialize, "{}")
end
parser = JSON::Ext::Parser.allocate
assert_raise(TypeError, '[ruby-core:35079]') { parser.source }
end
parser = JSON::Ext::Parser.allocate
assert_raise(TypeError, '[ruby-core:35079]') { parser.source }
end
end
end
30 changes: 24 additions & 6 deletions test/json_gem/json_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def test_pretty_state
actual.delete(:escape_slash)
actual.delete(:strict)
actual.delete(:script_safe)
assert_equal({

expected = {
:allow_nan => false,
:array_nl => "\n",
:ascii_only => false,
Expand All @@ -155,7 +156,12 @@ def test_pretty_state
:object_nl => "\n",
:space => " ",
:space_before => "",
}.sort_by { |n,| n.to_s }, actual.sort_by { |n,| n.to_s })
}
if REAL_JSON_GEM && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.5.0')
expected[:as_json] = false
end

assert_equal(expected.sort_by { |n,| n.to_s }, actual.sort_by { |n,| n.to_s })
end

def test_safe_state
Expand All @@ -166,7 +172,8 @@ def test_safe_state
actual.delete(:escape_slash)
actual.delete(:strict)
actual.delete(:script_safe)
assert_equal({

expected = {
:allow_nan => false,
:array_nl => "",
:ascii_only => false,
Expand All @@ -177,7 +184,12 @@ def test_safe_state
:object_nl => "",
:space => "",
:space_before => "",
}.sort_by { |n,| n.to_s }, actual.sort_by { |n,| n.to_s })
}
if REAL_JSON_GEM && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.5.0')
expected[:as_json] = false
end

assert_equal(expected.sort_by { |n,| n.to_s }, actual.sort_by { |n,| n.to_s })
end

def test_fast_state
Expand All @@ -188,7 +200,8 @@ def test_fast_state
actual.delete(:escape_slash)
actual.delete(:strict)
actual.delete(:script_safe)
assert_equal({

expected = {
:allow_nan => false,
:array_nl => "",
:ascii_only => false,
Expand All @@ -199,7 +212,12 @@ def test_fast_state
:object_nl => "",
:space => "",
:space_before => "",
}.sort_by { |n,| n.to_s }, actual.sort_by { |n,| n.to_s })
}
if REAL_JSON_GEM && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.5.0')
expected[:as_json] = false
end

assert_equal(expected.sort_by { |n,| n.to_s }, actual.sort_by { |n,| n.to_s })
end

def test_allow_nan
Expand Down

0 comments on commit 5b65384

Please sign in to comment.