diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_require.rb | 99 |
1 files changed, 30 insertions, 69 deletions
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb index 41cbff5c02..e3da03606b 100644 --- a/test/ruby/test_require.rb +++ b/test/ruby/test_require.rb @@ -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 |