test/ruby: tweaked heredocs

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-08-29 07:11:52 +00:00
parent 480c84e1af
commit 3895e30074
6 changed files with 53 additions and 32 deletions

View File

@ -122,7 +122,8 @@ class TestAlias < Test::Unit::TestCase
end end
def test_alias_wb_miss def test_alias_wb_miss
assert_normal_exit %q{ assert_normal_exit "#{<<-"begin;"}\n#{<<-'end;'}"
begin;
require 'stringio' require 'stringio'
GC.verify_internal_consistency GC.verify_internal_consistency
GC.start GC.start
@ -130,7 +131,7 @@ class TestAlias < Test::Unit::TestCase
alias_method :read_nonblock, :sysread alias_method :read_nonblock, :sysread
end end
GC.verify_internal_consistency GC.verify_internal_consistency
} end;
end end
def test_cyclic_zsuper def test_cyclic_zsuper
@ -183,7 +184,8 @@ class TestAlias < Test::Unit::TestCase
def test_alias_in_module def test_alias_in_module
bug9663 = '[ruby-core:61635] [Bug #9663]' bug9663 = '[ruby-core:61635] [Bug #9663]'
assert_separately(['-', bug9663], <<-'end;') assert_separately(['-', bug9663], "#{<<-"begin;"}\n#{<<-'end;'}")
begin;
bug = ARGV[0] bug = ARGV[0]
m = Module.new do m = Module.new do

View File

@ -934,7 +934,8 @@ class TestArgf < Test::Unit::TestCase
end end
def test_wrong_type def test_wrong_type
assert_separately([], <<-'end;') assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
bug11610 = '[ruby-core:71140] [Bug #11610]' bug11610 = '[ruby-core:71140] [Bug #11610]'
ARGV[0] = nil ARGV[0] = nil
assert_raise(TypeError, bug11610) {gets} assert_raise(TypeError, bug11610) {gets}

View File

@ -1899,8 +1899,10 @@ class TestArray < Test::Unit::TestCase
def test_permutation_stack_error def test_permutation_stack_error
bug9932 = '[ruby-core:63103] [Bug #9932]' bug9932 = '[ruby-core:63103] [Bug #9932]'
assert_separately([], <<-"end;", timeout: 30) # do assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}", timeout: 30)
assert_nothing_raised(SystemStackError, "#{bug9932}") do bug = "#{bug9932}"
begin;
assert_nothing_raised(SystemStackError, bug) do
assert_equal(:ok, Array.new(100_000, nil).permutation {break :ok}) assert_equal(:ok, Array.new(100_000, nil).permutation {break :ok})
end end
end; end;
@ -1932,7 +1934,8 @@ class TestArray < Test::Unit::TestCase
end end
def test_repeated_permutation_stack_error def test_repeated_permutation_stack_error
assert_separately([], <<-"end;", timeout: 30) # do assert_separately([], "#{<<-"begin;"}\n#{<<~'end;'}", timeout: 30)
begin;
assert_nothing_raised(SystemStackError) do assert_nothing_raised(SystemStackError) do
assert_equal(:ok, Array.new(100_000, nil).repeated_permutation(500_000) {break :ok}) assert_equal(:ok, Array.new(100_000, nil).repeated_permutation(500_000) {break :ok})
end end
@ -1969,7 +1972,8 @@ class TestArray < Test::Unit::TestCase
end end
def test_repeated_combination_stack_error def test_repeated_combination_stack_error
assert_separately([], <<-"end;", timeout: 20) # do assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}", timeout: 20)
begin;
assert_nothing_raised(SystemStackError) do assert_nothing_raised(SystemStackError) do
assert_equal(:ok, Array.new(100_000, nil).repeated_combination(500_000) {break :ok}) assert_equal(:ok, Array.new(100_000, nil).repeated_combination(500_000) {break :ok})
end end
@ -2752,21 +2756,24 @@ class TestArray < Test::Unit::TestCase
Bug11235 = '[ruby-dev:49043] [Bug #11235]' Bug11235 = '[ruby-dev:49043] [Bug #11235]'
def test_push_over_ary_max def test_push_over_ary_max
assert_separately(['-', ARY_MAX.to_s, Bug11235], <<-"end;", timeout: 30) assert_separately(['-', ARY_MAX.to_s, Bug11235], "#{<<~"begin;"}\n#{<<~'end;'}", timeout: 30)
begin;
a = Array.new(ARGV[0].to_i) a = Array.new(ARGV[0].to_i)
assert_raise(IndexError, ARGV[1]) {0x1000.times {a.push(1)}} assert_raise(IndexError, ARGV[1]) {0x1000.times {a.push(1)}}
end; end;
end end
def test_unshift_over_ary_max def test_unshift_over_ary_max
assert_separately(['-', ARY_MAX.to_s, Bug11235], <<-"end;") assert_separately(['-', ARY_MAX.to_s, Bug11235], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
a = Array.new(ARGV[0].to_i) a = Array.new(ARGV[0].to_i)
assert_raise(IndexError, ARGV[1]) {0x1000.times {a.unshift(1)}} assert_raise(IndexError, ARGV[1]) {0x1000.times {a.unshift(1)}}
end; end;
end end
def test_splice_over_ary_max def test_splice_over_ary_max
assert_separately(['-', ARY_MAX.to_s, Bug11235], <<-"end;") assert_separately(['-', ARY_MAX.to_s, Bug11235], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
a = Array.new(ARGV[0].to_i) a = Array.new(ARGV[0].to_i)
assert_raise(IndexError, ARGV[1]) {a[0, 0] = Array.new(0x1000)} assert_raise(IndexError, ARGV[1]) {a[0, 0] = Array.new(0x1000)}
end; end;

View File

@ -31,7 +31,8 @@ class TestBeginEndBlock < Test::Unit::TestCase
end end
def test_endblockwarn def test_endblockwarn
assert_in_out_err([], <<-'end;', [], ['-:2: warning: END in method; use at_exit']) assert_in_out_err([], "#{<<~"begin;"}#{<<~'end;'}", [], ['-:2: warning: END in method; use at_exit'])
begin;
def end1 def end1
END {} END {}
end end
@ -39,7 +40,8 @@ class TestBeginEndBlock < Test::Unit::TestCase
end end
def test_endblockwarn_in_eval def test_endblockwarn_in_eval
assert_in_out_err([], <<-'end;', [], ['(eval):2: warning: END in method; use at_exit']) assert_in_out_err([], "#{<<~"begin;"}\n#{<<~'end;'}", [], ['(eval):2: warning: END in method; use at_exit'])
begin;
eval <<-EOE eval <<-EOE
def end2 def end2
END {} END {}
@ -72,7 +74,8 @@ class TestBeginEndBlock < Test::Unit::TestCase
end end
def test_propagate_signaled def test_propagate_signaled
status = assert_in_out_err([], <<-'end;', [], /Interrupt$/) status = assert_in_out_err([], "#{<<~"begin;"}\n#{<<~'end;'}", [], /Interrupt$/)
begin;
trap(:INT, "DEFAULT") trap(:INT, "DEFAULT")
at_exit{Process.kill(:INT, $$)} at_exit{Process.kill(:INT, $$)}
end; end;
@ -82,7 +85,8 @@ class TestBeginEndBlock < Test::Unit::TestCase
end end
def test_endblock_raise def test_endblock_raise
assert_in_out_err([], <<-'end;', %w(e6 e4 e2), [:*, /e5/, :*, /e3/, :*, /e1/, :*]) assert_in_out_err([], "#{<<~"begin;"}\n#{<<~'end;'}", %w(e6 e4 e2), [:*, /e5/, :*, /e3/, :*, /e1/, :*])
begin;
END {raise "e1"}; END {puts "e2"} END {raise "e1"}; END {puts "e2"}
END {raise "e3"}; END {puts "e4"} END {raise "e3"}; END {puts "e4"}
END {raise "e5"}; END {puts "e6"} END {raise "e5"}; END {puts "e6"}
@ -99,7 +103,8 @@ class TestBeginEndBlock < Test::Unit::TestCase
"inner1", "inner1",
"outer0" ] "outer0" ]
assert_in_out_err([], <<-'end;', expected, [], "[ruby-core:35237]") assert_in_out_err([], "#{<<~"begin;"}\n#{<<~'end;'}", expected, [], "[ruby-core:35237]")
begin;
at_exit { puts :outer0 } at_exit { puts :outer0 }
at_exit { puts :outer1_begin; at_exit { puts :inner1 }; puts :outer1_end } at_exit { puts :outer1_begin; at_exit { puts :inner1 }; puts :outer1_end }
at_exit { puts :outer2_begin; at_exit { puts :inner2 }; puts :outer2_end } at_exit { puts :outer2_begin; at_exit { puts :inner2 }; puts :outer2_end }
@ -122,18 +127,19 @@ class TestBeginEndBlock < Test::Unit::TestCase
def test_callcc_at_exit def test_callcc_at_exit
bug9110 = '[ruby-core:58329][Bug #9110]' bug9110 = '[ruby-core:58329][Bug #9110]'
script = <<EOS assert_ruby_status([], "#{<<~"begin;"}\n#{<<~'end;'}", bug9110)
require "continuation" begin;
c = nil require "continuation"
at_exit { c.call } c = nil
at_exit { callcc {|_c| c = _c } } at_exit { c.call }
EOS at_exit { callcc {|_c| c = _c } }
assert_normal_exit(script, bug9110) end;
end end
def test_errinfo_at_exit def test_errinfo_at_exit
bug12302 = '[ruby-core:75038] [Bug #12302]' bug12302 = '[ruby-core:75038] [Bug #12302]'
assert_in_out_err([], <<-'end;', %w[2:exit 1:exit], [], bug12302) assert_in_out_err([], "#{<<~"begin;"}\n#{<<~'end;'}", %w[2:exit 1:exit], [], bug12302)
begin;
at_exit do at_exit do
puts "1:#{$!}" puts "1:#{$!}"
end end

View File

@ -297,7 +297,8 @@ class TestClass < Test::Unit::TestCase
end end
def test_cannot_reinitialize_class_with_initialize_copy # [ruby-core:50869] def test_cannot_reinitialize_class_with_initialize_copy # [ruby-core:50869]
assert_in_out_err([], <<-'end;', ["Object"], []) assert_in_out_err([], "#{<<~"begin;"}\n#{<<~'end;'}", ["Object"], [])
begin;
class Class class Class
def initialize_copy(*); super; end def initialize_copy(*); super; end
end end
@ -579,7 +580,8 @@ class TestClass < Test::Unit::TestCase
m.module_eval "class #{n}; end" m.module_eval "class #{n}; end"
} }
assert_separately([], <<-"end;") assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}")
begin;
Date = (class C\u{1f5ff}; self; end).new Date = (class C\u{1f5ff}; self; end).new
assert_raise_with_message(TypeError, /C\u{1f5ff}/) { assert_raise_with_message(TypeError, /C\u{1f5ff}/) {
require 'date' require 'date'
@ -588,22 +590,24 @@ class TestClass < Test::Unit::TestCase
end end
def test_should_not_expose_singleton_class_without_metaclass def test_should_not_expose_singleton_class_without_metaclass
assert_normal_exit %q{ assert_normal_exit "#{<<~"begin;"}\n#{<<~'end;'}", '[Bug #11740]'
begin;
klass = Class.new(Array) klass = Class.new(Array)
# The metaclass of +klass+ should handle #bla since it should inherit methods from meta:meta:Array # The metaclass of +klass+ should handle #bla since it should inherit methods from meta:meta:Array
def (Array.singleton_class).bla; :bla; end def (Array.singleton_class).bla; :bla; end
hidden = ObjectSpace.each_object(Class).find { |c| klass.is_a? c and c.inspect.include? klass.inspect } hidden = ObjectSpace.each_object(Class).find { |c| klass.is_a? c and c.inspect.include? klass.inspect }
raise unless hidden.nil? raise unless hidden.nil?
}, '[Bug #11740]' end;
assert_normal_exit %q{ assert_normal_exit "#{<<~"begin;"}\n#{<<~'end;'}", '[Bug #11740]'
begin;
klass = Class.new(Array) klass = Class.new(Array)
klass.singleton_class klass.singleton_class
# The metaclass of +klass+ should handle #bla since it should inherit methods from meta:meta:Array # The metaclass of +klass+ should handle #bla since it should inherit methods from meta:meta:Array
def (Array.singleton_class).bla; :bla; end def (Array.singleton_class).bla; :bla; end
hidden = ObjectSpace.each_object(Class).find { |c| klass.is_a? c and c.inspect.include? klass.inspect } hidden = ObjectSpace.each_object(Class).find { |c| klass.is_a? c and c.inspect.include? klass.inspect }
raise if hidden.nil? raise if hidden.nil?
}, '[Bug #11740]' end;
end end
end end

View File

@ -117,9 +117,10 @@ class TestEncoding < Test::Unit::TestCase
end end
def test_errinfo_after_autoload def test_errinfo_after_autoload
assert_separately(%w[--disable=gems], "#{<<~"begin;"}\n#{<<~'end;'}")
bug9038 = '[ruby-core:57949] [Bug #9038]' bug9038 = '[ruby-core:57949] [Bug #9038]'
assert_separately(%w[--disable=gems], <<-"end;") begin;
assert_raise_with_message(SyntaxError, /unknown regexp option - Q/, #{bug9038.dump}) { assert_raise_with_message(SyntaxError, /unknown regexp option - Q/, bug9038) {
eval("/regexp/sQ") eval("/regexp/sQ")
} }
end; end;