summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_array.rb11
-rw-r--r--test/ruby/test_file.rb4
-rw-r--r--test/ruby/test_fnmatch.rb6
-rw-r--r--test/ruby/test_gc.rb5
-rw-r--r--test/ruby/test_io_m17n.rb10
-rw-r--r--test/ruby/test_marshal.rb32
-rw-r--r--test/ruby/test_method.rb5
-rw-r--r--test/ruby/test_optimization.rb15
-rw-r--r--test/ruby/test_parse.rb6
-rw-r--r--test/ruby/test_proc.rb3
-rw-r--r--test/ruby/test_process.rb8
-rw-r--r--test/ruby/test_refinement.rb32
-rw-r--r--test/ruby/test_regexp.rb6
-rw-r--r--test/ruby/test_string.rb37
-rw-r--r--test/ruby/test_struct.rb4
-rw-r--r--test/ruby/test_syntax.rb29
-rw-r--r--test/ruby/test_time_tz.rb6
17 files changed, 212 insertions, 7 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index abd8d066fd..3212ed3aca 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -1895,6 +1895,17 @@ class TestArray < Test::Unit::TestCase
assert_equal(@cls[@cls[1,2], nil, 'dog', 'cat'], a.unshift(@cls[1, 2]))
end
+ def test_unshift_frozen
+ bug15952 = '[Bug #15952]'
+ assert_raise(FrozenError, bug15952) do
+ a = [1] * 100
+ b = a[4..-1]
+ a.replace([1])
+ b.freeze
+ b.unshift("a")
+ end
+ end
+
def test_OR # '|'
assert_equal(@cls[], @cls[] | @cls[])
assert_equal(@cls[1], @cls[1] | @cls[])
diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb
index ea03b59814..10bfbd9ae0 100644
--- a/test/ruby/test_file.rb
+++ b/test/ruby/test_file.rb
@@ -87,7 +87,7 @@ class TestFile < Test::Unit::TestCase
end
def test_bom_32le
- assert_bom(["\xFF\xFE\0", "\0"], __method__)
+ assert_bom(["\xFF", "\xFE\0\0"], __method__)
end
def test_truncate_wbuf
@@ -298,7 +298,7 @@ class TestFile < Test::Unit::TestCase
assert_predicate(File.realpath(base, dir), :tainted?)
base.untaint
dir.untaint
- assert_not_predicate(File.realpath(base, dir), :tainted?)
+ assert_predicate(File.realpath(base, dir), :tainted?)
assert_predicate(Dir.chdir(dir) {File.realpath(base)}, :tainted?)
}
end
diff --git a/test/ruby/test_fnmatch.rb b/test/ruby/test_fnmatch.rb
index ca01a28698..30250b5a19 100644
--- a/test/ruby/test_fnmatch.rb
+++ b/test/ruby/test_fnmatch.rb
@@ -129,4 +129,10 @@ class TestFnmatch < Test::Unit::TestCase
assert_file.fnmatch("[a-\u3042]*", "\u3042")
assert_file.not_fnmatch("[a-\u3042]*", "\u3043")
end
+
+ def test_nullchar
+ assert_raise(ArgumentError) {
+ File.fnmatch("a\0z", "a")
+ }
+ end
end
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index 7a6309b6a3..b3528ddacd 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -383,6 +383,11 @@ class TestGc < Test::Unit::TestCase
end;
end
+ def test_gc_stress_at_startup
+ skip # it'll be fixed later
+ assert_in_out_err([{"RUBY_DEBUG"=>"gc_stress"}], '', [], [], '[Bug #15784]', success: true)
+ end
+
def test_gc_disabled_start
begin
disabled = GC.disable
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index 8ba34845fa..9ff5307fc3 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -2082,14 +2082,14 @@ EOT
def test_strip_bom
with_tmpdir {
- text = "\uFEFFa"
- stripped = "a"
+ text = "\uFEFF\u0100a"
+ stripped = "\u0100a"
%w/UTF-8 UTF-16BE UTF-16LE UTF-32BE UTF-32LE/.each do |name|
path = '%s-bom.txt' % name
content = text.encode(name)
generate_file(path, content)
result = File.read(path, mode: 'rb:BOM|UTF-8')
- assert_equal(content[1].force_encoding("ascii-8bit"),
+ assert_equal(content[1..-1].force_encoding("ascii-8bit"),
result.force_encoding("ascii-8bit"))
result = File.read(path, mode: 'rb:BOM|UTF-8:UTF-8')
assert_equal(Encoding::UTF_8, result.encoding)
@@ -2099,10 +2099,10 @@ EOT
bug3407 = '[ruby-core:30641]'
path = 'UTF-8-bom.txt'
result = File.read(path, encoding: 'BOM|UTF-8')
- assert_equal("a", result.force_encoding("ascii-8bit"), bug3407)
+ assert_equal(stripped.b, result.force_encoding("ascii-8bit"), bug3407)
bug8323 = '[ruby-core:54563] [Bug #8323]'
- expected = "a\xff".force_encoding("utf-8")
+ expected = (stripped.b + "\xff").force_encoding("utf-8")
open(path, 'ab') {|f| f.write("\xff")}
result = File.read(path, encoding: 'BOM|UTF-8')
assert_not_predicate(result, :valid_encoding?, bug8323)
diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb
index e269428dda..0565a1c04f 100644
--- a/test/ruby/test_marshal.rb
+++ b/test/ruby/test_marshal.rb
@@ -779,4 +779,36 @@ class TestMarshal < Test::Unit::TestCase
obj = Bug14314.new(foo: 42)
assert_equal obj, Marshal.load(Marshal.dump(obj))
end
+
+ class Bug15968
+ attr_accessor :bar, :baz
+
+ def initialize
+ self.bar = Bar.new(self)
+ end
+
+ class Bar
+ attr_accessor :foo
+
+ def initialize(foo)
+ self.foo = foo
+ end
+
+ def marshal_dump
+ self.foo.baz = :problem
+ {foo: self.foo}
+ end
+
+ def marshal_load(data)
+ self.foo = data[:foo]
+ end
+ end
+ end
+
+ def test_marshal_dump_adding_instance_variable
+ obj = Bug15968.new
+ assert_raise_with_message(RuntimeError, /instance variable added/) do
+ Marshal.dump(obj)
+ end
+ end
end
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index cb68b2eca9..77273dade5 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -599,6 +599,11 @@ class TestMethod < Test::Unit::TestCase
assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:keyrest, :o]], self.class.instance_method(:pmk7).parameters)
end
+ def test_hidden_parameters
+ instance_eval("def m((_)"+",(_)"*256+");end")
+ assert_empty(method(:m).parameters.map{|_,n|n}.compact)
+ end
+
def test_public_method_with_zsuper_method
c = Class.new
c.class_eval do
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb
index 983054eafc..2a4cc19699 100644
--- a/test/ruby/test_optimization.rb
+++ b/test/ruby/test_optimization.rb
@@ -755,6 +755,21 @@ class TestRubyOptimization < Test::Unit::TestCase
assert_equal(:ok, x.bug(:ok))
end
+ def test_jump_elimination_with_optimized_out_block_2
+ x = Object.new
+ def x.bug
+ a = "aaa"
+ ok = :NG
+ if a == "bbb" || a == "ccc" then
+ a = a
+ else
+ ok = :ok
+ end
+ ok
+ end
+ assert_equal(:ok, x.bug)
+ end
+
def test_peephole_jump_after_newarray
i = 0
%w(1) || 2 while (i += 1) < 100
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 15c6245bac..b725634a38 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -1099,6 +1099,12 @@ x = __ENCODING__
assert_raise(SyntaxError) { eval("def m\n\C-z""end") }
end
+ def test_void_value_in_command_rhs
+ w = "void value expression"
+ ex = assert_syntax_error("x = return 1", w)
+ assert_equal(1, ex.message.scan(w).size, "same #{w.inspect} warning should be just once")
+ end
+
=begin
def test_past_scope_variable
assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index e6618745f1..df9bb5f549 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -1120,6 +1120,9 @@ class TestProc < Test::Unit::TestCase
assert_equal([[:req]], method(:putc).parameters)
assert_equal([[:rest]], method(:p).parameters)
+
+ pr = eval("proc{|"+"(_),"*30+"|}")
+ assert_empty(pr.parameters.map{|_,n|n}.compact)
end
def pm0() end
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index eb114dbebb..ba7b0f1177 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -1373,6 +1373,14 @@ class TestProcess < Test::Unit::TestCase
}
end
+ def test_argv0_keep_alive
+ assert_in_out_err([], <<~REPRO, ['-'], [], "[Bug #15887]")
+ $0 = "diverge"
+ 4.times { GC.start }
+ puts Process.argv0
+ REPRO
+ end
+
def test_status
with_tmpchdir do
s = run_in_child("exit 1")
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb
index 5583ce6a7a..7725820038 100644
--- a/test/ruby/test_refinement.rb
+++ b/test/ruby/test_refinement.rb
@@ -2055,6 +2055,38 @@ class TestRefinement < Test::Unit::TestCase
INPUT
end
+ def test_call_method_in_unused_refinement
+ bug15720 = '[ruby-core:91916] [Bug #15720]'
+ assert_in_out_err([], <<-INPUT, ["ok"], [], bug15720)
+ module M1
+ refine Kernel do
+ def foo
+ 'foo called!'
+ end
+ end
+ end
+
+ module M2
+ refine Kernel do
+ def bar
+ 'bar called!'
+ end
+ end
+ end
+
+ using M1
+
+ foo
+
+ begin
+ bar
+ rescue NameError
+ end
+
+ puts "ok"
+ INPUT
+ end
+
def test_super_from_refined_module
a = EnvUtil.labeled_module("A") do
def foo;"[A#{super}]";end
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 85d5b2cdfe..fe271dc3d7 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -156,6 +156,10 @@ class TestRegexp < Test::Unit::TestCase
s = "foo"
s[/(?<bar>o)/, "bar"] = "baz"
assert_equal("fbazo", s)
+
+ /.*/ =~ "abc"
+ "a".sub("a", "")
+ assert_raise(IndexError) {Regexp.last_match(:_id)}
end
def test_named_capture_with_nul
@@ -955,6 +959,8 @@ class TestRegexp < Test::Unit::TestCase
assert_match /\A\X\z/, "\u{1F468 200D 1F393}"
assert_match /\A\X\z/, "\u{1F46F 200D 2642 FE0F}"
assert_match /\A\X\z/, "\u{1f469 200d 2764 fe0f 200d 1f469}"
+
+ assert_warning('') {/\X/ =~ "\u{a0}"}
end
def test_backward
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index c0c4fe451a..9574ed31c9 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -68,6 +68,20 @@ class TestString < Test::Unit::TestCase
assert_raise(FrozenError){ str.__send__(:initialize, encoding: 'euc-jp') }
assert_raise(FrozenError){ str.__send__(:initialize, 'abc', encoding: 'euc-jp') }
assert_raise(FrozenError){ str.__send__(:initialize, 'abc', capacity: 1000, encoding: 'euc-jp') }
+
+ str = S("")
+ assert_equal("mystring", str.__send__(:initialize, "mystring"))
+ str = S("mystring")
+ assert_equal("mystring", str.__send__(:initialize, str))
+ str = S("")
+ assert_equal("mystring", str.__send__(:initialize, "mystring", capacity: 1000))
+ str = S("mystring")
+ assert_equal("mystring", str.__send__(:initialize, str, capacity: 1000))
+ end
+
+ def test_initialize_shared
+ String.new(str = "mystring" * 10).__send__(:initialize, capacity: str.bytesize)
+ assert_equal("mystring", str[0, 8])
end
def test_initialize_nonstring
@@ -1932,6 +1946,12 @@ CODE
r.taint
a.sub!(/./, r)
assert_predicate(a, :tainted?)
+
+ bug16105 = '[Bug #16105] heap-use-after-free'
+ a = S("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345678")
+ b = a.dup
+ c = a.slice(1, 100)
+ assert_equal("AABCDEFGHIJKLMNOPQRSTUVWXYZ012345678", b.sub!(c, b), bug16105)
end
def test_succ
@@ -2921,6 +2941,23 @@ CODE
end
=end
+ def test_nesting_shared
+ a = ('a' * 24).encode(Encoding::ASCII).gsub('x', '')
+ hash = {}
+ hash[a] = true
+ assert_equal(('a' * 24), a)
+ 4.times { GC.start }
+ assert_equal(('a' * 24), a, '[Bug #15792]')
+ end
+
+ def test_nesting_shared_b
+ a = ('j' * 24).b.b
+ eval('', binding, a)
+ assert_equal(('j' * 24), a)
+ 4.times { GC.start }
+ assert_equal(('j' * 24), a, '[Bug #15934]')
+ end
+
def test_shared_force_encoding
s = "\u{3066}\u{3059}\u{3068}".gsub(//, '')
h = {}
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb
index 384c95f85b..af68346442 100644
--- a/test/ruby/test_struct.rb
+++ b/test/ruby/test_struct.rb
@@ -92,6 +92,10 @@ module TestStruct
assert_equal([:utime, :stime, :cutime, :cstime], Process.times.members)
end
+ def test_struct_new_with_empty_hash
+ assert_equal({:a=>1}, Struct.new(:a, {}).new({:a=>1}).a)
+ end
+
def test_struct_new_with_keyword_init
@Struct.new("KeywordInitTrue", :a, :b, keyword_init: true)
@Struct.new("KeywordInitFalse", :a, :b, keyword_init: false)
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index b81ec9096d..f8d28a4f8e 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -711,6 +711,35 @@ eom
assert_syntax_error('<<~ "#{}"', /unexpected <</)
end
+ def test_heredoc_mixed_encoding
+ assert_syntax_error(<<-'HEREDOC', 'UTF-8 mixed within Windows-31J source')
+ #encoding: cp932
+ <<-TEXT
+ \xe9\x9d\u1234
+ TEXT
+ HEREDOC
+ assert_syntax_error(<<-'HEREDOC', 'UTF-8 mixed within Windows-31J source')
+ #encoding: cp932
+ <<-TEXT
+ \xe9\x9d
+ \u1234
+ TEXT
+ HEREDOC
+ assert_syntax_error(<<-'HEREDOC', 'UTF-8 mixed within Windows-31J source')
+ #encoding: cp932
+ <<-TEXT
+ \u1234\xe9\x9d
+ TEXT
+ HEREDOC
+ assert_syntax_error(<<-'HEREDOC', 'UTF-8 mixed within Windows-31J source')
+ #encoding: cp932
+ <<-TEXT
+ \u1234
+ \xe9\x9d
+ TEXT
+ HEREDOC
+ end
+
def test_lineno_operation_brace_block
expected = __LINE__ + 1
actual = caller_lineno\
diff --git a/test/ruby/test_time_tz.rb b/test/ruby/test_time_tz.rb
index 8be7294440..bfe9b4eef3 100644
--- a/test/ruby/test_time_tz.rb
+++ b/test/ruby/test_time_tz.rb
@@ -155,6 +155,12 @@ class TestTimeTZ < Test::Unit::TestCase
}
end
+ def test_asia_kuala_lumpur
+ with_tz(tz="Asia/Kuala_Lumpur") {
+ assert_time_constructor(tz, "1933-01-01 00:20:00 +0720", :local, [1933])
+ }
+ end
+
def test_canada_newfoundland
with_tz(tz="America/St_Johns") {
assert_time_constructor(tz, "2007-11-03 23:00:59 -0230", :new, [2007,11,3,23,0,59,:dst])