mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test_require.rb: use assert_separately
* test/ruby/test_require.rb: use assert_separately preferably to assert_in_out_err for clear messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42185 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5cbfd7509c
commit
4af852faa2
1 changed files with 30 additions and 69 deletions
|
@ -18,24 +18,20 @@ class TestRequire < Test::Unit::TestCase
|
|||
t.puts "dummy"
|
||||
t.close
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
assert_separately([], <<-INPUT)
|
||||
$:.replace([IO::NULL])
|
||||
begin
|
||||
assert_raise(LoadError) do
|
||||
require \"#{ t.path }\"
|
||||
rescue LoadError
|
||||
p :ok
|
||||
end
|
||||
INPUT
|
||||
}
|
||||
end
|
||||
|
||||
def test_require_too_long_filename
|
||||
assert_in_out_err(["RUBYOPT"=>nil], <<-INPUT, %w(:ok), [])
|
||||
assert_separately(["RUBYOPT"=>nil], <<-INPUT)
|
||||
$:.replace([IO::NULL])
|
||||
begin
|
||||
assert_raise(LoadError) do
|
||||
require '#{ "foo/" * 10000 }foo'
|
||||
rescue LoadError
|
||||
p :ok
|
||||
end
|
||||
INPUT
|
||||
|
||||
|
@ -171,33 +167,24 @@ class TestRequire < Test::Unit::TestCase
|
|||
return
|
||||
end
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
assert_separately([], <<-INPUT)
|
||||
BasicSocket = 1
|
||||
begin
|
||||
assert_raise(TypeError) do
|
||||
require 'socket'
|
||||
p :ng
|
||||
rescue TypeError
|
||||
p :ok
|
||||
end
|
||||
INPUT
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
assert_separately([], <<-INPUT)
|
||||
class BasicSocket; end
|
||||
begin
|
||||
assert_raise(TypeError) do
|
||||
require 'socket'
|
||||
p :ng
|
||||
rescue TypeError
|
||||
p :ok
|
||||
end
|
||||
INPUT
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
assert_separately([], <<-INPUT)
|
||||
class BasicSocket < IO; end
|
||||
begin
|
||||
assert_nothing_raised do
|
||||
require 'socket'
|
||||
p :ok
|
||||
rescue Exception
|
||||
p :ng
|
||||
end
|
||||
INPUT
|
||||
end
|
||||
|
@ -209,36 +196,27 @@ class TestRequire < Test::Unit::TestCase
|
|||
return
|
||||
end
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
assert_separately([], <<-INPUT)
|
||||
module Zlib; end
|
||||
Zlib::Error = 1
|
||||
begin
|
||||
assert_raise(TypeError) do
|
||||
require 'zlib'
|
||||
p :ng
|
||||
rescue TypeError
|
||||
p :ok
|
||||
end
|
||||
INPUT
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
assert_separately([], <<-INPUT)
|
||||
module Zlib; end
|
||||
class Zlib::Error; end
|
||||
begin
|
||||
assert_raise(NameError) do
|
||||
require 'zlib'
|
||||
p :ng
|
||||
rescue NameError
|
||||
p :ok
|
||||
end
|
||||
INPUT
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
assert_separately([], <<-INPUT)
|
||||
module Zlib; end
|
||||
class Zlib::Error < StandardError; end
|
||||
begin
|
||||
assert_nothing_raised do
|
||||
require 'zlib'
|
||||
p :ok
|
||||
rescue Exception
|
||||
p :ng
|
||||
end
|
||||
INPUT
|
||||
end
|
||||
|
@ -250,13 +228,10 @@ class TestRequire < Test::Unit::TestCase
|
|||
return
|
||||
end
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
assert_separately([], <<-INPUT)
|
||||
Zlib = 1
|
||||
begin
|
||||
assert_raise(TypeError) do
|
||||
require 'zlib'
|
||||
p :ng
|
||||
rescue TypeError
|
||||
p :ok
|
||||
end
|
||||
INPUT
|
||||
end
|
||||
|
@ -268,15 +243,12 @@ class TestRequire < Test::Unit::TestCase
|
|||
return
|
||||
end
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
assert_separately([], <<-INPUT)
|
||||
class BasicSocket < IO; end
|
||||
class Socket < BasicSocket; end
|
||||
Socket::Constants = 1
|
||||
begin
|
||||
assert_raise(TypeError) do
|
||||
require 'socket'
|
||||
p :ng
|
||||
rescue TypeError
|
||||
p :ok
|
||||
end
|
||||
INPUT
|
||||
end
|
||||
|
@ -318,47 +290,36 @@ class TestRequire < Test::Unit::TestCase
|
|||
abs_dir, file = File.split(t.path)
|
||||
abs_dir = File.expand_path(abs_dir).untaint
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
assert_separately([], <<-INPUT)
|
||||
abs_dir = "#{ abs_dir }"
|
||||
$: << abs_dir
|
||||
require "#{ file }"
|
||||
p :ok
|
||||
assert_nothing_raised {require "#{ file }"}
|
||||
INPUT
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
assert_separately([], <<-INPUT)
|
||||
abs_dir = "#{ abs_dir }"
|
||||
$: << abs_dir.taint
|
||||
require "#{ file }"
|
||||
p :ok
|
||||
assert_nothing_raised {require "#{ file }"}
|
||||
INPUT
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
assert_separately([], <<-INPUT)
|
||||
abs_dir = "#{ abs_dir }"
|
||||
$: << abs_dir.taint
|
||||
$SAFE = 1
|
||||
begin
|
||||
require "#{ file }"
|
||||
rescue SecurityError
|
||||
p :ok
|
||||
end
|
||||
assert_raise(SecurityError) {require "#{ file }"}
|
||||
INPUT
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
assert_separately([], <<-INPUT)
|
||||
abs_dir = "#{ abs_dir }"
|
||||
$: << abs_dir.taint
|
||||
$SAFE = 1
|
||||
begin
|
||||
require "#{ file }"
|
||||
rescue SecurityError
|
||||
p :ok
|
||||
end
|
||||
assert_raise(SecurityError) {require "#{ file }"}
|
||||
INPUT
|
||||
|
||||
assert_in_out_err([], <<-INPUT, %w(:ok), [])
|
||||
assert_separately([], <<-INPUT)
|
||||
abs_dir = "#{ abs_dir }"
|
||||
$: << abs_dir << 'elsewhere'.taint
|
||||
require "#{ file }"
|
||||
p :ok
|
||||
assert_nothing_raised {require "#{ file }"}
|
||||
INPUT
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue