1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

test/ruby/test_require.rb: use squiggly heredocs

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-03-11 11:15:05 +00:00
parent 20952cc5da
commit 0348262384

View file

@ -18,22 +18,24 @@ class TestRequire < Test::Unit::TestCase
t.puts "dummy" t.puts "dummy"
t.close t.close
assert_separately([], <<-INPUT) assert_separately([], "#{<<~"begin;"}\n#{<<~"end;"}")
begin;
$:.replace([IO::NULL]) $:.replace([IO::NULL])
assert_raise(LoadError) do assert_raise(LoadError) do
require \"#{ t.path }\" require \"#{ t.path }\"
end end
INPUT end;
} }
end end
def test_require_too_long_filename def test_require_too_long_filename
assert_separately(["RUBYOPT"=>nil], <<-INPUT) assert_separately(["RUBYOPT"=>nil], "#{<<~"begin;"}\n#{<<~"end;"}")
begin;
$:.replace([IO::NULL]) $:.replace([IO::NULL])
assert_raise(LoadError) do assert_raise(LoadError) do
require '#{ "foo/" * 10000 }foo' require '#{ "foo/" * 10000 }foo'
end end
INPUT end;
begin begin
assert_in_out_err(["-S", "-w", "foo/" * 1024 + "foo"], "") do |r, e| assert_in_out_err(["-S", "-w", "foo/" * 1024 + "foo"], "") do |r, e|
@ -445,7 +447,8 @@ class TestRequire < Test::Unit::TestCase
verbose = $VERBOSE verbose = $VERBOSE
Tempfile.create(%w"bug5754 .rb") {|tmp| Tempfile.create(%w"bug5754 .rb") {|tmp|
path = tmp.path path = tmp.path
tmp.print %{\ tmp.print "#{<<~"begin;"}\n#{<<~"end;"}"
begin;
th = Thread.current th = Thread.current
t = th[:t] t = th[:t]
scratch = th[:scratch] scratch = th[:scratch]
@ -457,7 +460,7 @@ class TestRequire < Test::Unit::TestCase
else else
scratch << :post scratch << :post
end end
} end;
tmp.close tmp.close
class << (output = "") class << (output = "")
@ -537,7 +540,8 @@ class TestRequire < Test::Unit::TestCase
open(File.join("b", "bar.rb"), "w") {|f| open(File.join("b", "bar.rb"), "w") {|f|
f.puts "p :ok" f.puts "p :ok"
} }
assert_in_out_err([], <<-INPUT, %w(:ok), [], bug7158) assert_in_out_err([], "#{<<~"begin;"}\n#{<<~"end;"}", %w(:ok), [], bug7158)
begin;
$:.replace([IO::NULL]) $:.replace([IO::NULL])
$: << "." $: << "."
Dir.chdir("a") Dir.chdir("a")
@ -546,7 +550,7 @@ class TestRequire < Test::Unit::TestCase
p :ng unless require "bar" p :ng unless require "bar"
Dir.chdir("..") Dir.chdir("..")
p :ng if require "b/bar" p :ng if require "b/bar"
INPUT end;
} }
} }
end end
@ -556,7 +560,8 @@ class TestRequire < Test::Unit::TestCase
Dir.mktmpdir {|tmp| Dir.mktmpdir {|tmp|
Dir.chdir(tmp) { Dir.chdir(tmp) {
open("foo.rb", "w") {} open("foo.rb", "w") {}
assert_in_out_err([], <<-INPUT, %w(:ok), [], bug7158) assert_in_out_err([], "#{<<~"begin;"}\n#{<<~"end;"}", %w(:ok), [], bug7158)
begin;
$:.replace([IO::NULL]) $:.replace([IO::NULL])
a = Object.new a = Object.new
def a.to_str def a.to_str
@ -566,7 +571,7 @@ class TestRequire < Test::Unit::TestCase
require "foo" require "foo"
last_path = $:.pop last_path = $:.pop
p :ok if last_path == a && last_path.class == Object p :ok if last_path == a && last_path.class == Object
INPUT end;
} }
} }
end end
@ -578,14 +583,15 @@ class TestRequire < Test::Unit::TestCase
open("foo.rb", "w") {} open("foo.rb", "w") {}
Dir.mkdir("a") Dir.mkdir("a")
open(File.join("a", "bar.rb"), "w") {} open(File.join("a", "bar.rb"), "w") {}
assert_in_out_err([], <<-INPUT, %w(:ok), [], bug7158) assert_in_out_err([], "#{<<~"begin;"}\n#{<<~"end;"}", %w(:ok), [], bug7158)
begin;
$:.replace([IO::NULL]) $:.replace([IO::NULL])
$: << '~' $: << '~'
ENV['HOME'] = "#{tmp}" ENV['HOME'] = "#{tmp}"
require "foo" require "foo"
ENV['HOME'] = "#{tmp}/a" ENV['HOME'] = "#{tmp}/a"
p :ok if require "bar" p :ok if require "bar"
INPUT end;
} }
} }
end end
@ -595,7 +601,8 @@ class TestRequire < Test::Unit::TestCase
Dir.mktmpdir {|tmp| Dir.mktmpdir {|tmp|
Dir.chdir(tmp) { Dir.chdir(tmp) {
open("foo.rb", "w") {} open("foo.rb", "w") {}
assert_in_out_err([{"RUBYOPT"=>nil}, '--disable-gems'], <<-INPUT, %w(:ok), [], bug7158) assert_in_out_err([{"RUBYOPT"=>nil}, '--disable-gems'], "#{<<~"begin;"}\n#{<<~"end;"}", %w(:ok), [], bug7158)
begin;
$:.replace([IO::NULL]) $:.replace([IO::NULL])
a = Object.new a = Object.new
def a.to_path def a.to_path
@ -612,7 +619,7 @@ class TestRequire < Test::Unit::TestCase
"#{tmp}" "#{tmp}"
end end
p :ok if require "foo" p :ok if require "foo"
INPUT end;
} }
} }
end end
@ -622,7 +629,8 @@ class TestRequire < Test::Unit::TestCase
Dir.mktmpdir {|tmp| Dir.mktmpdir {|tmp|
Dir.chdir(tmp) { Dir.chdir(tmp) {
open("foo.rb", "w") {} open("foo.rb", "w") {}
assert_in_out_err([{"RUBYOPT"=>nil}, '--disable-gems'], <<-INPUT, %w(:ok), [], bug7158) assert_in_out_err([{"RUBYOPT"=>nil}, '--disable-gems'], "#{<<~"begin;"}\n#{<<~"end;"}", %w(:ok), [], bug7158)
begin;
$:.replace([IO::NULL]) $:.replace([IO::NULL])
a = Object.new a = Object.new
def a.to_str def a.to_str
@ -639,7 +647,7 @@ class TestRequire < Test::Unit::TestCase
"#{tmp}" "#{tmp}"
end end
p :ok if require "foo" p :ok if require "foo"
INPUT end;
} }
} }
end end
@ -651,7 +659,8 @@ class TestRequire < Test::Unit::TestCase
open("foo.rb", "w") {} open("foo.rb", "w") {}
Dir.mkdir("a") Dir.mkdir("a")
open(File.join("a", "bar.rb"), "w") {} open(File.join("a", "bar.rb"), "w") {}
assert_in_out_err(['--disable-gems'], <<-INPUT, %w(:ok), [], bug7383) assert_in_out_err(['--disable-gems'], "#{<<~"begin;"}\n#{<<~"end;"}", %w(:ok), [], bug7383)
begin;
$:.replace([IO::NULL]) $:.replace([IO::NULL])
$:.#{add} "#{tmp}" $:.#{add} "#{tmp}"
$:.#{add} "#{tmp}/a" $:.#{add} "#{tmp}/a"
@ -667,7 +676,7 @@ class TestRequire < Test::Unit::TestCase
raise raise
end end
end end
INPUT end;
} }
} }
end end
@ -685,10 +694,11 @@ class TestRequire < Test::Unit::TestCase
Dir.mktmpdir {|tmp| Dir.mktmpdir {|tmp|
Dir.chdir(tmp) { Dir.chdir(tmp) {
open("bar.rb", "w") {|f| f.puts 'TOPLEVEL_BINDING.eval("lib = 2")' } open("bar.rb", "w") {|f| f.puts 'TOPLEVEL_BINDING.eval("lib = 2")' }
assert_in_out_err(%w[-r./bar.rb], <<-INPUT, %w([:lib] 2), [], bug7536) assert_in_out_err(%w[-r./bar.rb], "#{<<~"begin;"}\n#{<<~"end;"}", %w([:lib] 2), [], bug7536)
begin;
puts TOPLEVEL_BINDING.eval("local_variables").inspect puts TOPLEVEL_BINDING.eval("local_variables").inspect
puts TOPLEVEL_BINDING.eval("lib").inspect puts TOPLEVEL_BINDING.eval("lib").inspect
INPUT end;
} }
} }
end end
@ -697,7 +707,8 @@ class TestRequire < Test::Unit::TestCase
bug7530 = '[ruby-core:50645]' bug7530 = '[ruby-core:50645]'
Tempfile.create(%w'bug-7530- .rb') {|script| Tempfile.create(%w'bug-7530- .rb') {|script|
script.close script.close
assert_in_out_err([{"RUBYOPT" => nil}, "-", script.path], <<-INPUT, %w(:ok), [], bug7530, timeout: 60) assert_in_out_err([{"RUBYOPT" => nil}, "-", script.path], "#{<<~"begin;"}\n#{<<~"end;"}", %w(:ok), [], bug7530, timeout: 60)
begin;
PATH = ARGV.shift PATH = ARGV.shift
THREADS = 4 THREADS = 4
ITERATIONS_PER_THREAD = 1000 ITERATIONS_PER_THREAD = 1000
@ -711,7 +722,7 @@ class TestRequire < Test::Unit::TestCase
end end
}.each(&:join) }.each(&:join)
p :ok p :ok
INPUT end;
} }
end end
@ -720,7 +731,7 @@ class TestRequire < Test::Unit::TestCase
f.close f.close
File.unlink(f.path) File.unlink(f.path)
File.mkfifo(f.path) File.mkfifo(f.path)
assert_separately(["-", f.path], "#{<<-"begin;"}\n#{<<-"end;"}", timeout: 3) assert_separately(["-", f.path], "#{<<~"begin;"}\n#{<<~"end;"}", timeout: 3)
begin; begin;
th = Thread.current th = Thread.current
Thread.start {begin sleep(0.001) end until th.stop?; th.raise(IOError)} Thread.start {begin sleep(0.001) end until th.stop?; th.raise(IOError)}
@ -737,7 +748,7 @@ class TestRequire < Test::Unit::TestCase
File.unlink(f.path) File.unlink(f.path)
File.mkfifo(f.path) File.mkfifo(f.path)
assert_separately(["-", f.path], "#{<<-"begin;"}\n#{<<-"end;"}", timeout: 3) assert_separately(["-", f.path], "#{<<~"begin;"}\n#{<<~"end;"}", timeout: 3)
begin; begin;
path = ARGV[0] path = ARGV[0]
th = Thread.current th = Thread.current
@ -762,7 +773,7 @@ class TestRequire < Test::Unit::TestCase
f.close f.close
File.unlink(f.path) File.unlink(f.path)
File.mkfifo(f.path) File.mkfifo(f.path)
assert_separately(["-", f.path], "#{<<-"begin;"}\n#{<<-"end;"}", timeout: 3) assert_separately(["-", f.path], "#{<<~"begin;"}\n#{<<~"end;"}", timeout: 3)
begin; begin;
Process.setrlimit(Process::RLIMIT_NOFILE, 50) Process.setrlimit(Process::RLIMIT_NOFILE, 50)
th = Thread.current th = Thread.current
@ -786,7 +797,8 @@ class TestRequire < Test::Unit::TestCase
f.puts 'sleep' f.puts 'sleep'
f.close f.close
assert_separately(["-", f.path], <<-'end;') assert_separately(["-", f.path], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
path = ARGV[0] path = ARGV[0]
class Error < RuntimeError class Error < RuntimeError
def exception(*) def exception(*)