diff options
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/envutil.rb | 25 | ||||
-rw-r--r-- | test/ruby/memory_status.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_array.rb | 27 | ||||
-rw-r--r-- | test/ruby/test_beginendblock.rb | 11 | ||||
-rw-r--r-- | test/ruby/test_comparable.rb | 7 | ||||
-rw-r--r-- | test/ruby/test_enumerator.rb | 31 | ||||
-rw-r--r-- | test/ruby/test_float.rb | 12 | ||||
-rw-r--r-- | test/ruby/test_gc.rb | 14 | ||||
-rw-r--r-- | test/ruby/test_hash.rb | 37 | ||||
-rw-r--r-- | test/ruby/test_io.rb | 97 | ||||
-rw-r--r-- | test/ruby/test_io_m17n.rb | 12 | ||||
-rw-r--r-- | test/ruby/test_m17n.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_method.rb | 14 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 44 | ||||
-rw-r--r-- | test/ruby/test_pack.rb | 1 | ||||
-rw-r--r-- | test/ruby/test_parse.rb | 21 | ||||
-rw-r--r-- | test/ruby/test_proc.rb | 50 | ||||
-rw-r--r-- | test/ruby/test_process.rb | 12 | ||||
-rw-r--r-- | test/ruby/test_sprintf_comb.rb | 46 | ||||
-rw-r--r-- | test/ruby/test_symbol.rb | 29 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 5 | ||||
-rw-r--r-- | test/ruby/test_thread.rb | 27 | ||||
-rw-r--r-- | test/ruby/test_time.rb | 23 |
23 files changed, 514 insertions, 35 deletions
diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb index 73f0101ac1..6998842259 100644 --- a/test/ruby/envutil.rb +++ b/test/ruby/envutil.rb @@ -184,6 +184,31 @@ module Test assert(msg === stderr, "warning message #{stderr.inspect} is expected to match #{msg.inspect}") end + def assert_no_memory_leak(args, prepare, code, message=nil, opt = {}) + limit = opt.delete(:limit) || 1.5 + token = "\e[7;1m#{$$.to_s}:#{Time.now.strftime('%s.%L')}:#{rand(0x10000).to_s(16)}:\e[m" + token_dump = token.dump + token_re = Regexp.quote(token) + envs = args.shift if Array === args and Hash === args.first + args = [ + "--disable=gems", + "-r", File.expand_path("../memory_status", __FILE__), + *args, + "-v", "-", + ] + args.unshift(envs) if envs + cmd = [ + 'END {STDERR.puts '"#{token_dump}"'"FINAL=#{Memory::Status.new.size}"}', + prepare, + 'STDERR.puts('"#{token_dump}"'"START=#{$initial_size = Memory::Status.new.size}")', + code, + ].join("\n") + _, err, status = EnvUtil.invoke_ruby(args, cmd, true, true, opt) + before = err.sub!(/^#{token_re}START=(\d+)\n/, '') && $1.to_i + after = err.sub!(/^#{token_re}FINAL=(\d+)\n/, '') && $1.to_i + assert_equal([true, ""], [status.success?, err], message) + assert_operator(after.fdiv(before), :<, limit, message) + end def assert_is_minus_zero(f) assert(1.0/f == -Float::INFINITY, "#{f} is not -0.0") diff --git a/test/ruby/memory_status.rb b/test/ruby/memory_status.rb index f504c0a736..cd4a62c1c0 100644 --- a/test/ruby/memory_status.rb +++ b/test/ruby/memory_status.rb @@ -7,7 +7,7 @@ module Memory PROC_FILE = procfile VM_PAT = /^Vm(\w+):\s+(\d+)/ def self.read_status - IO.foreach(PROC_FILE) do |l| + IO.foreach(PROC_FILE, encoding: Encoding::ASCII_8BIT) do |l| yield($1.downcase.intern, $2.to_i * 1024) if VM_PAT =~ l end end diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 28d3e4156b..4350e0578f 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -552,6 +552,29 @@ class TestArray < Test::Unit::TestCase assert_equal(3, a.count {|x| x % 2 == 1 }) assert_equal(2, a.count(1) {|x| x % 2 == 1 }) assert_raise(ArgumentError) { a.count(0, 1) } + + bug8654 = '[ruby-core:56072]' + assert_in_out_err [], <<-EOS, ["0"], [], bug8654 + a1 = [] + a2 = Array.new(100) { |i| i } + a2.count do |i| + p i + a2.replace(a1) if i == 0 + end + EOS + + assert_in_out_err [], <<-EOS, ["[]", "0"], [], bug8654 + ARY = Array.new(100) { |i| i } + class Fixnum + alias old_equal == + def == other + ARY.replace([]) if self.equal?(0) + p ARY + self.equal?(other) + end + end + p ARY.count(42) + EOS end def test_delete @@ -1624,8 +1647,8 @@ class TestArray < Test::Unit::TestCase [2,2,2,2],[2,2,2,3],[2,2,3,3],[2,3,3,3],[3,3,3,3]], a.repeated_combination(4).to_a.sort) assert_equal(@cls[], a.repeated_combination(-1).to_a) - assert_equal("abcde".each_char.to_a.repeated_combination(5).map{|a|a.sort}.sort, - "edcba".each_char.to_a.repeated_combination(5).map{|a|a.sort}.sort) + assert_equal("abcde".each_char.to_a.repeated_combination(5).map{|e|e.sort}.sort, + "edcba".each_char.to_a.repeated_combination(5).map{|e|e.sort}.sort) assert_equal(@cls[].repeated_combination(0).to_a, @cls[[]]) assert_equal(@cls[].repeated_combination(1).to_a, @cls[]) diff --git a/test/ruby/test_beginendblock.rb b/test/ruby/test_beginendblock.rb index b590835a2d..121d116c35 100644 --- a/test/ruby/test_beginendblock.rb +++ b/test/ruby/test_beginendblock.rb @@ -158,4 +158,15 @@ EOW assert_equal(["", "", 42], [out, err, status.exitstatus], "#{bug5218}: #{ex}") end end + + def test_callcc_at_exit + bug9110 = '[ruby-core:58329][Bug #9110]' + script = <<EOS +require "continuation" +c = nil +at_exit { c.call } +at_exit { callcc {|_c| c = _c } } +EOS + assert_normal_exit(script, bug9110) + end end diff --git a/test/ruby/test_comparable.rb b/test/ruby/test_comparable.rb index 00ce6b485a..3526c73add 100644 --- a/test/ruby/test_comparable.rb +++ b/test/ruby/test_comparable.rb @@ -69,4 +69,11 @@ class TestComparable < Test::Unit::TestCase assert_raise(ArgumentError) { 1.0 < nil } assert_raise(ArgumentError) { 1.0 < Object.new } end + + def test_no_cmp + bug9003 = '[ruby-core:57736] [Bug #9003]' + assert_nothing_raised(SystemStackError, bug9003) { + @o <=> @o.dup + } + end end diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 10ba2f184e..feaa2de698 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -1,4 +1,5 @@ require 'test/unit' +require_relative "envutil" class TestEnumerator < Test::Unit::TestCase def setup @@ -97,6 +98,36 @@ class TestEnumerator < Test::Unit::TestCase assert_equal([[1,5],[2,6],[3,7]], @obj.to_enum(:foo, 1, 2, 3).with_index(5).to_a) end + def test_with_index_large_offset + bug8010 = '[ruby-dev:47131] [Bug #8010]' + s = 1 << (8*1.size-2) + assert_equal([[1,s],[2,s+1],[3,s+2]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010) + s <<= 1 + assert_equal([[1,s],[2,s+1],[3,s+2]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010) + end + + def test_with_index_nonnum_offset + bug8010 = '[ruby-dev:47131] [Bug #8010]' + s = Object.new + def s.to_int; 1 end + assert_equal([[1,1],[2,2],[3,3]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010) + end + + def test_with_index_string_offset + bug8010 = '[ruby-dev:47131] [Bug #8010]' + assert_raise(TypeError, bug8010){ @obj.to_enum(:foo, 1, 2, 3).with_index('1').to_a } + end + + def test_with_index_dangling_memo + bug9178 = '[ruby-core:58692] [Bug #9178]' + assert_in_out_err([], <<-"end;", ["Enumerator", "[false, [1]]"], [], bug9178) + bug = "#{bug9178}" + e = [1].to_enum(:chunk).with_index {|c,i| i == 5} + puts e.class + p e.to_a[0] + end; + end + def test_with_object obj = [0, 1] ret = (1..10).each.with_object(obj) {|i, memo| diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index d2cee75433..301aeecf0f 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -519,4 +519,16 @@ class TestFloat < Test::Unit::TestCase sleep(0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1) end end + + def test_long_string + assert_normal_exit(<<-'end;') + assert_in_epsilon(10.0, ("1."+"1"*300000).to_f*9) + end; + end + + def test_long_string + assert_normal_exit(<<-'end;') + assert_in_epsilon(10.0, ("1."+"1"*300000).to_f*9) + end; + end end diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index f04e7e0255..381fcd4d18 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -112,4 +112,18 @@ class TestGc < Test::Unit::TestCase ObjectSpace.define_finalizer(Thread.main) { p 'finalize' } EOS end + + def test_sweep_in_finalizer + bug9205 = '[ruby-core:58833] [Bug #9205]' + 2.times do + assert_ruby_status([], <<-'end;', bug9205) + raise_proc = proc do |id| + GC.start + end + 1000.times do + ObjectSpace.define_finalizer(Object.new, raise_proc) + end + end; + end + end end diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 82272cb301..019196bd2e 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1,5 +1,6 @@ require 'test/unit' require 'continuation' +require_relative "envutil" class TestHash < Test::Unit::TestCase @@ -116,6 +117,12 @@ class TestHash < Test::Unit::TestCase end + def test_self_initialize_copy + h = @cls[1=>2] + h.instance_eval {initialize_copy(h)} + assert_equal(2, h[1]) + end + def test_AREF # '[]' t = Time.now h = @cls[ @@ -144,8 +151,6 @@ class TestHash < Test::Unit::TestCase assert_equal('nil', h1[nil]) assert_equal(nil, h1['nil']) assert_equal(:default, h1['koala']) - - end def test_ASET # '[]=' @@ -920,4 +925,32 @@ class TestHash < Test::Unit::TestCase assert_not_equal(h.hash, h.invert.hash, feature4262) end end + + def test_exception_in_rehash + bug9187 = '[ruby-core:58728] [Bug #9187]' + + prepare = <<-EOS + class Foo + def initialize + @raise = false + end + + def hash + raise if @raise + @raise = true + return 0 + end + end + EOS + + code = <<-EOS + h = {Foo.new => true} + 10_0000.times do + h.rehash rescue nil + end + GC.start + EOS + + assert_no_memory_leak([], prepare, code, bug9187) + end end diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index ad9b80faec..5e3a12c999 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1094,6 +1094,19 @@ class TestIO < Test::Unit::TestCase end end + def test_close_read_write_separately + bug = '[ruby-list:49598]' + (1..10).each do |i| + assert_nothing_raised(IOError, "#{bug} trying ##{i}") do + IO.popen(EnvUtil.rubybin, "r+") {|f| + th = Thread.new {f.close_write} + f.close_read + th.join + } + end + end + end + def test_pid r, w = IO.pipe assert_equal(nil, r.pid) @@ -1110,6 +1123,17 @@ class TestIO < Test::Unit::TestCase assert_raise(IOError) { pipe.pid } end + def tesst_pid_after_close_read + pid1 = pid2 = nil + IO.popen(["echo", ""], "r+") do |io| + pid1 = io.pid + io.close_read + pid2 = io.pid + end + assert_not_nil(pid1) + assert_equal(pid1, pid2) + end + def make_tempfile t = Tempfile.new("test_io") t.binmode @@ -2147,4 +2171,77 @@ End IO.select(tempfiles) }, bug8080 end + + def test_read_32bit_boundary + bug8431 = '[ruby-core:55098] [Bug #8431]' + make_tempfile {|t| + assert_separately(["-", bug8431, t.path], <<-"end;") + msg = ARGV.shift + f = open(ARGV[0], "rb") + f.seek(0xffff_ffff) + assert_nil(f.read(1), msg) + end; + } + end if /mswin|mingw/ =~ RUBY_PLATFORM + + def test_write_32bit_boundary + bug8431 = '[ruby-core:55098] [Bug #8431]' + make_tempfile {|t| + assert_separately(["-", bug8431, t.path], <<-"end;", timeout: 30) + msg = ARGV.shift + f = open(ARGV[0], "wb") + f.seek(0xffff_ffff) + begin + # this will consume very long time or fail by ENOSPC on a + # filesystem which sparse file is not supported + f.write('1') + rescue SystemCallError + else + assert_equal(0x1_0000_0000, f.tell, msg) + end + end; + } + end if /mswin|mingw/ =~ RUBY_PLATFORM + + def test_read_unlocktmp_ensure + bug8669 = '[ruby-core:56121] [Bug #8669]' + + str = "" + r, = IO.pipe + t = Thread.new { r.read(nil, str) } + sleep 0.1 until t.stop? + t.raise + sleep 0.1 while t.alive? + assert_nothing_raised(RuntimeError, bug8669) { str.clear } + ensure + t.kill + end + + def test_readpartial_unlocktmp_ensure + bug8669 = '[ruby-core:56121] [Bug #8669]' + + str = "" + r, = IO.pipe + t = Thread.new { r.readpartial(4096, str) } + sleep 0.1 until t.stop? + t.raise + sleep 0.1 while t.alive? + assert_nothing_raised(RuntimeError, bug8669) { str.clear } + ensure + t.kill + end + + def test_sysread_unlocktmp_ensure + bug8669 = '[ruby-core:56121] [Bug #8669]' + + str = "" + r, = IO.pipe + t = Thread.new { r.sysread(4096, str) } + sleep 0.1 until t.stop? + t.raise + sleep 0.1 while t.alive? + assert_nothing_raised(RuntimeError, bug8669) { str.clear } + ensure + t.kill + end end diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb index 98c9e2b41c..c22f665286 100644 --- a/test/ruby/test_io_m17n.rb +++ b/test/ruby/test_io_m17n.rb @@ -2067,7 +2067,17 @@ EOT open("a", "wb") {|f| f.puts "a"} open("a", "rt") {|f| f.getc} } - assert(c.ascii_only?, "should be ascii_only #{bug4557}") + assert(c.ascii_only?, bug4557) + end + + def test_getc_conversion + bug8516 = '[ruby-core:55444] [Bug #8516]' + c = with_tmpdir { + open("a", "wb") {|f| f.putc "\xe1"} + open("a", "r:iso-8859-1:utf-8") {|f| f.getc} + } + refute(c.ascii_only?, bug8516) + assert_equal(1, c.size, bug8516) end def test_default_mode_on_dosish diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index 699c8151dd..e92b85dbb8 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -1180,7 +1180,7 @@ class TestM17N < Test::Unit::TestCase def test_symbol_op ops = %w" - .. ... + - +(binary) -(binary) * / % ** +@ -@ | ^ & ! <=> > >= < <= == + .. ... + - * / % ** +@ -@ | ^ & ! <=> > >= < <= == === != =~ !~ ~ ! [] []= << >> :: ` " ops.each do |op| diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index ea6c5f2164..889c50efbe 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -472,4 +472,18 @@ class TestMethod < Test::Unit::TestCase 1000.times {p = Bug6171.new('test'); 10000.times {p.reverse}} EOC end + + def test_gced_bmethod + assert_normal_exit %q{ + require 'irb' + IRB::Irb.module_eval do + define_method(:eval_input) do + IRB::Irb.module_eval { alias_method :eval_input, :to_s } + GC.start + Kernel + end + end + IRB.start + }, '[Bug #7825]' + end end diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 6176f484bc..1fe67df2be 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -277,6 +277,17 @@ class TestModule < Test::Unit::TestCase assert_equal([:MIXIN, :USER], User.constants.sort) end + def test_self_initialize_copy + bug9535 = '[ruby-dev:47989] [Bug #9535]' + m = Module.new do + def foo + :ok + end + initialize_copy(self) + end + assert_equal(:ok, Object.new.extend(m).foo, bug9535) + end + def test_included_modules assert_equal([], Mixin.included_modules) assert_equal([Mixin], User.included_modules) @@ -669,6 +680,19 @@ class TestModule < Test::Unit::TestCase m.instance_eval { remove_const(:Foo) } end + class Bug9413 + class << self + Foo = :foo + end + end + + def test_singleton_constants + bug9413 = '[ruby-core:59763] [Bug #9413]' + c = Bug9413.singleton_class + assert_include(c.constants(true), :Foo, bug9413) + assert_include(c.constants(false), :Foo, bug9413) + end + def test_frozen_class m = Module.new m.freeze @@ -1220,4 +1244,24 @@ class TestModule < Test::Unit::TestCase INPUT assert_in_out_err([], src, ["NameError"], []) end + + def test_include_module_with_constants_invalidates_method_cache + assert_in_out_err([], <<-RUBY, %w(123 456), []) + A = 123 + + class Foo + def self.a + A + end + end + + module M + A = 456 + end + + puts Foo.a + Foo.send(:include, M) + puts Foo.a + RUBY + end end diff --git a/test/ruby/test_pack.rb b/test/ruby/test_pack.rb index c862215cb4..52beb9f8d4 100644 --- a/test/ruby/test_pack.rb +++ b/test/ruby/test_pack.rb @@ -180,6 +180,7 @@ class TestPack < Test::Unit::TestCase assert_equal a[0], a.pack("p").unpack("p")[0] assert_equal a, a.pack("p").freeze.unpack("p*") assert_raise(ArgumentError) { (a.pack("p") + "").unpack("p*") } + assert_raise(ArgumentError) { (a.pack("p") << "d").unpack("p*") } end def test_format_string_modified diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index 14990be12c..6de57c1a22 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -358,6 +358,17 @@ class TestParse < Test::Unit::TestCase assert_equal("foo 1 bar", "foo #$1 bar") end + def test_dstr_disallowd_variable + bug8375 = '[ruby-core:54885] [Bug #8375]' + %w[@ @1 @@. @@ @@1 @@. $ $%].each do |src| + src = '#'+src+' ' + str = assert_nothing_raised(SyntaxError, "#{bug8375} #{src.dump}") do + break eval('"'+src+'"') + end + assert_equal(src, str, bug8375) + end + end + def test_dsym assert_nothing_raised { eval(':""') } end @@ -524,13 +535,14 @@ class TestParse < Test::Unit::TestCase ) end - assert_raise(SyntaxError) do - eval %q( + assert_nothing_raised(SyntaxError) do + x = eval %q( <<FOO #$ FOO ) end + assert_equal "\#$\n", x assert_raise(SyntaxError) do eval %Q( @@ -550,14 +562,15 @@ FOO ) end - assert_raise(SyntaxError) do - eval %q( + assert_nothing_raised(SyntaxError) do + x = eval %q( <<FOO #$ foo FOO ) end + assert_equal "\#$\nfoo\n", x assert_nothing_raised do eval "x = <<""FOO\r\n1\r\nFOO" diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index 3cac94a100..7560ce94ef 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -1,4 +1,5 @@ require 'test/unit' +require_relative 'envutil' class TestProc < Test::Unit::TestCase def setup @@ -140,6 +141,14 @@ class TestProc < Test::Unit::TestCase method(:m2).to_proc end + def m1(var) + var + end + + def m_block_given? + m1(block_given?) + end + # [yarv-dev:777] block made by Method#to_proc def test_method_to_proc b = block() @@ -147,6 +156,37 @@ class TestProc < Test::Unit::TestCase assert_instance_of(Binding, b.binding, '[ruby-core:25589]') end + def test_block_given_method + m = method(:m_block_given?) + assert(!m.call, "without block") + assert(m.call {}, "with block") + assert(!m.call, "without block second") + end + + def test_block_given_method_to_proc + bug8341 = '[Bug #8341]' + m = method(:m_block_given?).to_proc + assert(!m.call, "#{bug8341} without block") + assert(m.call {}, "#{bug8341} with block") + assert(!m.call, "#{bug8341} without block second") + end + + def test_block_persist_between_calls + bug8341 = '[Bug #8341]' + o = Object.new + def o.m1(top=true) + if top + [block_given?, @m.call(false)] + else + block_given? + end + end + m = o.method(:m1).to_proc + o.instance_variable_set(:@m, m) + assert_equal([true, false], m.call {}, "#{bug8341} nested with block") + assert_equal([false, false], m.call, "#{bug8341} nested without block") + end + def test_curry b = proc {|x, y, z| (x||0) + (y||0) + (z||0) } assert_equal(6, b.curry[1][2][3]) @@ -818,4 +858,14 @@ class TestProc < Test::Unit::TestCase assert_equal('zot', o.method(:foo).to_proc.() {'zot'}, bug3792) } end + + def test_overriden_lambda + bug8345 = '[ruby-core:54687] [Bug #8345]' + assert_normal_exit('def lambda; end; method(:puts).to_proc', bug8345) + end + + def test_overriden_proc + bug8345 = '[ruby-core:54688] [Bug #8345]' + assert_normal_exit('def proc; end; ->{}.curry', bug8345) + end end diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index d1e2e1984d..83ff379ca9 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -1319,6 +1319,18 @@ class TestProcess < Test::Unit::TestCase assert_equal(2, data.size, bug4920) assert_not_include(data.map(&:to_i), pid) end + else # darwin + def test_daemon_no_threads + data = Timeout.timeout(3) do + IO.popen("-") do |f| + break f.readlines.map(&:chomp) if f + th = Thread.start {sleep 3} + Process.daemon(true, true) + puts Thread.list.size, th.status.inspect + end + end + assert_equal(["1", "false"], data) + end end end diff --git a/test/ruby/test_sprintf_comb.rb b/test/ruby/test_sprintf_comb.rb index 261732bcbc..c58ddf4f15 100644 --- a/test/ruby/test_sprintf_comb.rb +++ b/test/ruby/test_sprintf_comb.rb @@ -107,7 +107,9 @@ class TestSprintfComb < Test::Unit::TestCase ] VS.reverse! - def combination(*args, &b) + FLAGS = [['', ' '], ['', '#'], ['', '+'], ['', '-'], ['', '0']] + + def self.combination(*args, &b) #AllPairs.exhaustive_each(*args, &b) AllPairs.each(*args, &b) end @@ -268,17 +270,8 @@ class TestSprintfComb < Test::Unit::TestCase str end - def test_format_integer - combination( - %w[B b d o X x], - [nil, 0, 5, 20], - ["", ".", ".0", ".8", ".20"], - ['', ' '], - ['', '#'], - ['', '+'], - ['', '-'], - ['', '0']) {|type, width, precision, sp, hs, pl, mi, zr| - format = "%#{sp}#{hs}#{pl}#{mi}#{zr}#{width}#{precision}#{type}" + def self.assertions_format_integer(format) + proc { VS.each {|v| r = sprintf format, v e = emu_int format, v @@ -293,6 +286,14 @@ class TestSprintfComb < Test::Unit::TestCase } end + combination(%w[B b d o X x], + [nil, 0, 5, 20], + ["", ".", ".0", ".8", ".20"], + *FLAGS) {|type, width, precision, sp, hs, pl, mi, zr| + format = "%#{sp}#{hs}#{pl}#{mi}#{zr}#{width}#{precision}#{type}" + define_method("test_format_integer(#{format})", assertions_format_integer(format)) + } + FLOAT_VALUES = [ -1e100, -123456789.0, @@ -526,17 +527,8 @@ class TestSprintfComb < Test::Unit::TestCase end - def test_format_float - combination( - %w[e E f g G], - [nil, 0, 5, 20], - ["", ".", ".0", ".8", ".20", ".200"], - ['', ' '], - ['', '#'], - ['', '+'], - ['', '-'], - ['', '0']) {|type, width, precision, sp, hs, pl, mi, zr| - format = "%#{sp}#{hs}#{pl}#{mi}#{zr}#{width}#{precision}#{type}" + def self.assertions_format_float(format) + proc { FLOAT_VALUES.each {|v| r = sprintf format, v e = emu_float format, v @@ -550,4 +542,12 @@ class TestSprintfComb < Test::Unit::TestCase } } end + + combination(%w[e E f g G], + [nil, 0, 5, 20], + ["", ".", ".0", ".8", ".20", ".200", ".9999"], + *FLAGS) {|type, width, precision, sp, hs, pl, mi, zr| + format = "%#{sp}#{hs}#{pl}#{mi}#{zr}#{width}#{precision}#{type}" + define_method("test_format_float(#{format})", assertions_format_float(format)) + } end diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb index c98f954092..23c50e6778 100644 --- a/test/ruby/test_symbol.rb +++ b/test/ruby/test_symbol.rb @@ -33,7 +33,7 @@ class TestSymbol < Test::Unit::TestCase assert_inspect_evaled(':foo') assert_inspect_evaled(':foo!') assert_inspect_evaled(':bar?') - assert_inspect_evaled(':<<') + assert_inspect_evaled(":<<") assert_inspect_evaled(':>>') assert_inspect_evaled(':<=') assert_inspect_evaled(':>=') @@ -102,6 +102,33 @@ class TestSymbol < Test::Unit::TestCase assert_raise(ArgumentError) { :foo.to_proc.call } end + def m_block_given? + block_given? + end + + def m2_block_given?(m = nil) + if m + [block_given?, m.call(self)] + else + block_given? + end + end + + def test_block_given_to_proc + bug8531 = '[Bug #8531]' + m = :m_block_given?.to_proc + assert(!m.call(self), "#{bug8531} without block") + assert(m.call(self) {}, "#{bug8531} with block") + assert(!m.call(self), "#{bug8531} without block second") + end + + def test_block_persist_between_calls + bug8531 = '[Bug #8531]' + m2 = :m2_block_given?.to_proc + assert_equal([true, false], m2.call(self, m2) {}, "#{bug8531} nested with block") + assert_equal([false, false], m2.call(self, m2), "#{bug8531} nested without block") + end + def test_succ assert_equal(:fop, :foo.succ) end diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index d924679c7f..a65b567153 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -55,6 +55,11 @@ class TestSyntax < Test::Unit::TestCase f.close! end + def test_do_block_in_call_args + bug9308 = '[ruby-core:59342] [Bug #9308]' + assert_valid_syntax("bar def foo; self.each do end end", bug9308) + end + def test_reserved_method_no_args bug6403 = '[ruby-dev:45626]' assert_valid_syntax("def self; :foo; end", __FILE__, bug6403) diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index e8cb3b1722..4d99053b2f 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -710,4 +710,31 @@ class TestThreadGroup < Test::Unit::TestCase end assert_in_delta(t1 - t0, 1, 1) end + + def test_blocking_mutex_unlocked_on_fork + bug8433 = '[ruby-core:55102] [Bug #8433]' + + mutex = Mutex.new + flag = false + mutex.lock + + th = Thread.new do + mutex.synchronize do + flag = true + sleep + end + end + + Thread.pass until th.stop? + mutex.unlock + + pid = Process.fork do + exit(mutex.locked?) + end + + th.kill + + pid, status = Process.waitpid2(pid) + assert_equal(false, status.success?, bug8433) + end if Process.respond_to?(:fork) end diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index 961c49432c..03172149ea 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -14,6 +14,20 @@ class TestTime < Test::Unit::TestCase $VERBOSE = @verbose end + def no_leap_seconds? + # 1972-06-30T23:59:60Z is the first leap second. + Time.utc(1972, 7, 1, 0, 0, 0) - Time.utc(1972, 6, 30, 23, 59, 59) == 1 + end + + def get_t2000 + if no_leap_seconds? + # Sat Jan 01 00:00:00 UTC 2000 + Time.at(946684800).gmtime + else + Time.utc(2000, 1, 1) + end + end + def test_new assert_equal(Time.utc(2000,2,10), Time.new(2000,2,10, 11,0,0, 3600*11)) assert_equal(Time.utc(2000,2,10), Time.new(2000,2,9, 13,0,0, -3600*11)) @@ -378,6 +392,15 @@ class TestTime < Test::Unit::TestCase assert_kind_of(Integer, T2000.hash) end + def test_reinitialize + bug8099 = '[ruby-core:53436] [Bug #8099]' + t2000 = get_t2000 + assert_raise(TypeError, bug8099) { + t2000.send(:initialize, 2013, 03, 14) + } + assert_equal(get_t2000, t2000, bug8099) + end + def test_init_copy assert_equal(T2000, T2000.dup) assert_raise(TypeError) do |