aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_autoload.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-20 23:03:52 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-20 23:03:52 +0000
commit8f671120f1d99b47f28d67183855d634d006389a (patch)
tree5a6a943efb8bfb690d7cf5a5f05d2aa701d114ac /test/ruby/test_autoload.rb
parent65261bda4d964c081fc3a510bfaa094a7647e8bc (diff)
downloadruby-8f671120f1d99b47f28d67183855d634d006389a.tar.gz
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb, test/openssl/test_config.rb, test/psych/test_encoding.rb, test/psych/test_exception.rb, test/psych/test_psych.rb, test/psych/test_tainted.rb, test/readline/test_readline.rb, test/rexml/test_contrib.rb, test/ruby/test_autoload.rb, test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb, test/ruby/test_file.rb, test/ruby/test_io.rb, test/ruby/test_marshal.rb, test/ruby/test_process.rb, test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb, test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb, test/zlib/test_zlib.rb: Use Tempfile.create. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_autoload.rb')
-rw-r--r--test/ruby/test_autoload.rb162
1 files changed, 78 insertions, 84 deletions
diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb
index 8ca2187970..1931df45c5 100644
--- a/test/ruby/test_autoload.rb
+++ b/test/ruby/test_autoload.rb
@@ -57,109 +57,103 @@ p Foo::Bar
end
def test_require_explicit
- file = Tempfile.open(['autoload', '.rb'])
- file.puts 'class Object; AutoloadTest = 1; end'
- file.close
- add_autoload(file.path)
- begin
- assert_nothing_raised do
- assert(require file.path)
- assert_equal(1, ::AutoloadTest)
+ Tempfile.create(['autoload', '.rb']) {|file|
+ file.puts 'class Object; AutoloadTest = 1; end'
+ file.close
+ add_autoload(file.path)
+ begin
+ assert_nothing_raised do
+ assert(require file.path)
+ assert_equal(1, ::AutoloadTest)
+ end
+ ensure
+ remove_autoload_constant
end
- ensure
- remove_autoload_constant
- end
- ensure
- file.unlink
+ }
end
def test_threaded_accessing_constant
- file = Tempfile.open(['autoload', '.rb'])
- file.puts 'sleep 0.5; class AutoloadTest; X = 1; end'
- file.close
- add_autoload(file.path)
- begin
- assert_nothing_raised do
- t1 = Thread.new { ::AutoloadTest::X }
- t2 = Thread.new { ::AutoloadTest::X }
- [t1, t2].each(&:join)
+ Tempfile.create(['autoload', '.rb']) {|file|
+ file.puts 'sleep 0.5; class AutoloadTest; X = 1; end'
+ file.close
+ add_autoload(file.path)
+ begin
+ assert_nothing_raised do
+ t1 = Thread.new { ::AutoloadTest::X }
+ t2 = Thread.new { ::AutoloadTest::X }
+ [t1, t2].each(&:join)
+ end
+ ensure
+ remove_autoload_constant
end
- ensure
- remove_autoload_constant
- end
- ensure
- file.unlink
+ }
end
def test_threaded_accessing_inner_constant
- file = Tempfile.open(['autoload', '.rb'])
- file.puts 'class AutoloadTest; sleep 0.5; X = 1; end'
- file.close
- add_autoload(file.path)
- begin
- assert_nothing_raised do
- t1 = Thread.new { ::AutoloadTest::X }
- t2 = Thread.new { ::AutoloadTest::X }
- [t1, t2].each(&:join)
+ Tempfile.create(['autoload', '.rb']) {|file|
+ file.puts 'class AutoloadTest; sleep 0.5; X = 1; end'
+ file.close
+ add_autoload(file.path)
+ begin
+ assert_nothing_raised do
+ t1 = Thread.new { ::AutoloadTest::X }
+ t2 = Thread.new { ::AutoloadTest::X }
+ [t1, t2].each(&:join)
+ end
+ ensure
+ remove_autoload_constant
end
- ensure
- remove_autoload_constant
- end
- ensure
- file.unlink
+ }
end
def test_nameerror_when_autoload_did_not_define_the_constant
- file = Tempfile.open(['autoload', '.rb'])
- file.puts ''
- file.close
- add_autoload(file.path)
- begin
- assert_raise(NameError) do
- AutoloadTest
+ Tempfile.create(['autoload', '.rb']) {|file|
+ file.puts ''
+ file.close
+ add_autoload(file.path)
+ begin
+ assert_raise(NameError) do
+ AutoloadTest
+ end
+ ensure
+ remove_autoload_constant
end
- ensure
- remove_autoload_constant
- end
- ensure
- file.unlink
+ }
end
def test_override_autoload
- file = Tempfile.open(['autoload', '.rb'])
- file.puts ''
- file.close
- add_autoload(file.path)
- begin
- eval %q(class AutoloadTest; end)
- assert_equal(Class, AutoloadTest.class)
- ensure
- remove_autoload_constant
- end
- ensure
- file.unlink
+ Tempfile.create(['autoload', '.rb']) {|file|
+ file.puts ''
+ file.close
+ add_autoload(file.path)
+ begin
+ eval %q(class AutoloadTest; end)
+ assert_equal(Class, AutoloadTest.class)
+ ensure
+ remove_autoload_constant
+ end
+ }
end
def test_override_while_autoloading
- file = Tempfile.open(['autoload', '.rb'])
- file.puts 'class AutoloadTest; sleep 0.5; end'
- file.close
- add_autoload(file.path)
- begin
- # while autoloading...
- t = Thread.new { AutoloadTest }
- sleep 0.1
- # override it
- EnvUtil.suppress_warning {
- eval %q(AutoloadTest = 1)
- }
- t.join
- assert_equal(1, AutoloadTest)
- ensure
- remove_autoload_constant
- end
- ensure
- file.unlink
+ Tempfile.create(['autoload', '.rb']) {|file|
+ file.puts 'class AutoloadTest; sleep 0.5; end'
+ file.close
+ add_autoload(file.path)
+ begin
+ # while autoloading...
+ t = Thread.new { AutoloadTest }
+ sleep 0.1
+ # override it
+ EnvUtil.suppress_warning {
+ eval %q(AutoloadTest = 1)
+ }
+ t.join
+ assert_equal(1, AutoloadTest)
+ ensure
+ remove_autoload_constant
+ end
+ }
end
def add_autoload(path)