summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/-ext-/debug/test_debug.rb49
-rw-r--r--test/-ext-/thread_fd/test_thread_fd_close.rb24
-rw-r--r--test/json/json_ext_parser_test.rb31
-rwxr-xr-xtest/json/json_generator_test.rb8
-rw-r--r--test/json/json_parser_test.rb12
-rw-r--r--test/psych/test_stringio.rb14
-rw-r--r--test/ruby/test_class.rb8
-rw-r--r--test/ruby/test_hash.rb8
-rw-r--r--test/ruby/test_io.rb2
-rw-r--r--test/ruby/test_object_id.rb5
-rw-r--r--test/ruby/test_shapes.rb2
-rw-r--r--test/rubygems/test_gem_safe_marshal.rb2
-rw-r--r--test/rubygems/test_gem_specification.rb2
-rw-r--r--test/stringio/test_stringio.rb7
14 files changed, 119 insertions, 55 deletions
diff --git a/test/-ext-/debug/test_debug.rb b/test/-ext-/debug/test_debug.rb
index 2229859801..c9263d76fa 100644
--- a/test/-ext-/debug/test_debug.rb
+++ b/test/-ext-/debug/test_debug.rb
@@ -75,19 +75,58 @@ class TestDebug < Test::Unit::TestCase
end
assert_equal true, x, '[Bug #15105]'
end
+end
+
+# This is a YJIT test, but we can't test this without a C extension that calls
+# rb_debug_inspector_open(), so we're testing it using "-test-/debug" here.
+class TestDebugWithYJIT < Test::Unit::TestCase
+ class LocalSetArray
+ def to_a
+ Bug::Debug.inspector.each do |_, binding,|
+ binding.local_variable_set(:local, :ok) if binding
+ end
+ [:ok]
+ end
+ end
+
+ class DebugArray
+ def to_a
+ Bug::Debug.inspector
+ [:ok]
+ end
+ end
+
+ def test_yjit_invalidates_getlocal_after_splatarray
+ val = getlocal_after_splatarray(LocalSetArray.new)
+ assert_equal [:ok, :ok], val
+ end
- # This is a YJIT test, but we can't test this without a C extension that calls
- # rb_debug_inspector_open(), so we're testing it using "-test-/debug" here.
- def test_yjit_invalidates_setlocal_after_inspector_call
+ def test_yjit_invalidates_setlocal_after_splatarray
+ val = setlocal_after_splatarray(DebugArray.new)
+ assert_equal [:ok], val
+ end
+
+ def test_yjit_invalidates_setlocal_after_proc_call
val = setlocal_after_proc_call(proc { Bug::Debug.inspector; :ok })
assert_equal :ok, val
- end if defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?
+ end
private
+ def getlocal_after_splatarray(array)
+ local = 1
+ [*array, local]
+ end
+
+ def setlocal_after_splatarray(array)
+ local = *array # setlocal followed by splatarray
+ itself # split a block using a C call
+ local # getlocal
+ end
+
def setlocal_after_proc_call(block)
local = block.call # setlocal followed by OPTIMIZED_METHOD_TYPE_CALL
itself # split a block using a C call
local # getlocal
end
-end
+end if defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?
diff --git a/test/-ext-/thread_fd/test_thread_fd_close.rb b/test/-ext-/thread_fd/test_thread_fd_close.rb
deleted file mode 100644
index 1d2ef63635..0000000000
--- a/test/-ext-/thread_fd/test_thread_fd_close.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-require 'test/unit'
-require '-test-/thread_fd'
-
-class TestThreadFdClose < Test::Unit::TestCase
-
- def test_thread_fd_close
- IO.pipe do |r, w|
- th = Thread.new do
- begin
- assert_raise(IOError) {
- r.read(4)
- }
- ensure
- w.syswrite('done')
- end
- end
- Thread.pass until th.stop?
- IO.thread_fd_close(r.fileno)
- assert_equal 'done', r.read(4)
- th.join
- end
- end
-end
diff --git a/test/json/json_ext_parser_test.rb b/test/json/json_ext_parser_test.rb
index 8aa626257e..e610f642f1 100644
--- a/test/json/json_ext_parser_test.rb
+++ b/test/json/json_ext_parser_test.rb
@@ -14,16 +14,35 @@ class JSONExtParserTest < Test::Unit::TestCase
end
def test_error_messages
- ex = assert_raise(ParserError) { parse('Infinity') }
- assert_equal "unexpected token at 'Infinity'", ex.message
+ ex = assert_raise(ParserError) { parse('Infinity something') }
+ unless RUBY_PLATFORM =~ /java/
+ assert_equal "unexpected token 'Infinity' at line 1 column 1", ex.message
+ end
+ ex = assert_raise(ParserError) { parse('foo bar') }
unless RUBY_PLATFORM =~ /java/
- ex = assert_raise(ParserError) { parse('-Infinity') }
- assert_equal "unexpected token at '-Infinity'", ex.message
+ assert_equal "unexpected token 'foo' at line 1 column 1", ex.message
end
- ex = assert_raise(ParserError) { parse('NaN') }
- assert_equal "unexpected token at 'NaN'", ex.message
+ ex = assert_raise(ParserError) { parse('-Infinity something') }
+ unless RUBY_PLATFORM =~ /java/
+ assert_equal "unexpected token '-Infinity' at line 1 column 1", ex.message
+ end
+
+ ex = assert_raise(ParserError) { parse('NaN something') }
+ unless RUBY_PLATFORM =~ /java/
+ assert_equal "unexpected token 'NaN' at line 1 column 1", ex.message
+ end
+
+ ex = assert_raise(ParserError) { parse(' ') }
+ unless RUBY_PLATFORM =~ /java/
+ assert_equal "unexpected end of input at line 1 column 4", ex.message
+ end
+
+ ex = assert_raise(ParserError) { parse('{ ') }
+ unless RUBY_PLATFORM =~ /java/
+ assert_equal "expected object key, got EOF at line 1 column 5", ex.message
+ end
end
if GC.respond_to?(:stress=)
diff --git a/test/json/json_generator_test.rb b/test/json/json_generator_test.rb
index 3192b555a3..55a3065ae5 100755
--- a/test/json/json_generator_test.rb
+++ b/test/json/json_generator_test.rb
@@ -771,6 +771,14 @@ class JSONGeneratorTest < Test::Unit::TestCase
values = [-1.0, 1.0, 0.0, 12.2, 7.5 / 3.2, 12.0, 100.0, 1000.0]
expecteds = ["-1.0", "1.0", "0.0", "12.2", "2.34375", "12.0", "100.0", "1000.0"]
+ if RUBY_ENGINE == "jruby"
+ values << 1746861937.7842371
+ expecteds << "1.7468619377842371E9"
+ else
+ values << 1746861937.7842371
+ expecteds << "1746861937.7842371"
+ end
+
values.zip(expecteds).each do |value, expected|
assert_equal expected, value.to_json
end
diff --git a/test/json/json_parser_test.rb b/test/json/json_parser_test.rb
index 87b78fb0ca..befc80c958 100644
--- a/test/json/json_parser_test.rb
+++ b/test/json/json_parser_test.rb
@@ -638,7 +638,7 @@ class JSONParserTest < Test::Unit::TestCase
error = assert_raise(JSON::ParserError) do
JSON.parse('{"foo": ' + ('A' * 500) + '}')
end
- assert_operator 60, :>, error.message.bytesize
+ assert_operator 80, :>, error.message.bytesize
end
def test_parse_error_incomplete_hash
@@ -646,7 +646,7 @@ class JSONParserTest < Test::Unit::TestCase
JSON.parse('{"input":{"firstName":"Bob","lastName":"Mob","email":"[email protected]"}')
end
if RUBY_ENGINE == "ruby"
- assert_equal %(expected ',' or '}' after object value, got: ''), error.message
+ assert_equal %(expected ',' or '}' after object value, got: EOF at line 1 column 72), error.message
end
end
@@ -654,16 +654,16 @@ class JSONParserTest < Test::Unit::TestCase
omit "C ext only test" unless RUBY_ENGINE == "ruby"
error = assert_raise(JSON::ParserError) { JSON.parse("あああああああああああああああああああああああ") }
- assert_equal "unexpected character: 'ああああああああああ'", error.message
+ assert_equal "unexpected character: 'ああああああああああ' at line 1 column 1", error.message
error = assert_raise(JSON::ParserError) { JSON.parse("aあああああああああああああああああああああああ") }
- assert_equal "unexpected character: 'aああああああああああ'", error.message
+ assert_equal "unexpected character: 'aああああああああああ' at line 1 column 1", error.message
error = assert_raise(JSON::ParserError) { JSON.parse("abあああああああああああああああああああああああ") }
- assert_equal "unexpected character: 'abあああああああああ'", error.message
+ assert_equal "unexpected character: 'abあああああああああ' at line 1 column 1", error.message
error = assert_raise(JSON::ParserError) { JSON.parse("abcあああああああああああああああああああああああ") }
- assert_equal "unexpected character: 'abcあああああああああ'", error.message
+ assert_equal "unexpected character: 'abcあああああああああ' at line 1 column 1", error.message
end
def test_parse_leading_slash
diff --git a/test/psych/test_stringio.rb b/test/psych/test_stringio.rb
new file mode 100644
index 0000000000..7fef1402a0
--- /dev/null
+++ b/test/psych/test_stringio.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+require_relative 'helper'
+
+module Psych
+ class TestStringIO < TestCase
+ # The superclass of StringIO before Ruby 3.0 was `Data`,
+ # which can interfere with the Ruby 3.2+ `Data` dumping.
+ def test_stringio
+ assert_nothing_raised do
+ Psych.dump(StringIO.new("foo"))
+ end
+ end
+ end
+end
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb
index 6fc461ed08..9a34a81334 100644
--- a/test/ruby/test_class.rb
+++ b/test/ruby/test_class.rb
@@ -283,12 +283,8 @@ class TestClass < Test::Unit::TestCase
assert_raise(TypeError, bug6863) { Class.new(Class.allocate) }
allocator = Class.instance_method(:allocate)
- assert_raise_with_message(TypeError, /prohibited/) {
- allocator.bind(Rational).call
- }
- assert_raise_with_message(TypeError, /prohibited/) {
- allocator.bind_call(Rational)
- }
+ assert_nothing_raised { allocator.bind(Rational).call }
+ assert_nothing_raised { allocator.bind_call(Rational) }
end
def test_nonascii_name
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index b6c18ea958..76af5b6183 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -1853,6 +1853,14 @@ class TestHash < Test::Unit::TestCase
end
end
assert_equal(@cls[a: 2, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10], x)
+
+ x = (1..1337).to_h {|k| [k, k]}
+ assert_raise_with_message(RuntimeError, /rehash during iteration/) do
+ x.transform_values! {|v|
+ x.rehash if v == 1337
+ v * 2
+ }
+ end
end
def hrec h, n, &b
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 32d7519bdf..a81d689355 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -3826,7 +3826,7 @@ __END__
end
tempfiles = []
- (0..fd_setsize+1).map {|i|
+ (0...fd_setsize).map {|i|
tempfiles << Tempfile.create("test_io_select_with_many_files")
}
diff --git a/test/ruby/test_object_id.rb b/test/ruby/test_object_id.rb
index 2277bba634..97ed70d839 100644
--- a/test/ruby/test_object_id.rb
+++ b/test/ruby/test_object_id.rb
@@ -1,4 +1,5 @@
require 'test/unit'
+require "securerandom"
class TestObjectId < Test::Unit::TestCase
def setup
@@ -159,14 +160,14 @@ class TestObjectIdTooComplexClass < TestObjectId
@obj = TooComplex.new
- @obj.instance_variable_set("@___#{rand(100_000)}", 1)
+ @obj.instance_variable_set("@___#{SecureRandom.hex}", 1)
8.times do |i|
@obj.instance_variable_set("@TestObjectIdTooComplexClass#{i}", 1)
@obj.remove_instance_variable("@TestObjectIdTooComplexClass#{i}")
end
- @obj.instance_variable_set("@___#{rand(100_000)}", 1)
+ @obj.instance_variable_set("@test", 1)
if defined?(RubyVM::Shape)
assert_predicate(RubyVM::Shape.of(@obj), :too_complex?)
diff --git a/test/ruby/test_shapes.rb b/test/ruby/test_shapes.rb
index 94670a4055..0458b3235b 100644
--- a/test/ruby/test_shapes.rb
+++ b/test/ruby/test_shapes.rb
@@ -681,8 +681,8 @@ class TestShapes < Test::Unit::TestCase
id_shape = RubyVM::Shape.of(tc)
refute_equal frozen_shape.id, id_shape.id
assert_predicate id_shape, :too_complex?
- assert_predicate id_shape, :shape_frozen?
assert_predicate id_shape, :has_object_id?
+ assert_predicate id_shape, :shape_frozen?
assert_equal 3, tc.very_unique
assert_equal 3, Ractor.make_shareable(tc).very_unique
diff --git a/test/rubygems/test_gem_safe_marshal.rb b/test/rubygems/test_gem_safe_marshal.rb
index deeb8205bc..bd15f4f796 100644
--- a/test/rubygems/test_gem_safe_marshal.rb
+++ b/test/rubygems/test_gem_safe_marshal.rb
@@ -234,8 +234,6 @@ class TestGemSafeMarshal < Gem::TestCase
end
def test_link_after_float
- pend "Marshal.load of links and floats is broken on truffleruby, see https://github.com/oracle/truffleruby/issues/3747" if RUBY_ENGINE == "truffleruby"
-
a = []
a << a
assert_safe_load_as [0.0, a, 1.0, a]
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index 3f8d921467..7cb7ee1605 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -3664,8 +3664,6 @@ Did you mean 'Ruby'?
end
def test__load_fixes_Date_objects
- pend "Marshal.load of links and floats is broken on truffleruby, see https://github.com/oracle/truffleruby/issues/3747" if RUBY_ENGINE == "truffleruby"
-
spec = util_spec "a", 1
spec.instance_variable_set :@date, Date.today
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index 570b3d7ad6..002b946b6f 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -1057,6 +1057,13 @@ class TestStringIO < Test::Unit::TestCase
assert_equal("test", io.string)
assert_same(chilled_string, io.string)
end
+
+ def test_chilled_string_set_enocoding
+ chilled_string = eval(%{""})
+ io = StringIO.new(chilled_string)
+ assert_warning("") { io.set_encoding(Encoding::BINARY) }
+ assert_same(chilled_string, io.string)
+ end
end
private