1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/bootstraptest/test_autoload.rb
nobu 6b7dbd3e31 * insns.def (defineclass): try to autoload const to be overridden.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-12 15:48:44 +00:00

78 lines
1.9 KiB
Ruby

assert_equal 'ok', %q{
open("zzz.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"}
autoload :ZZZ, "./zzz.rb"
ZZZ.ok
}
assert_equal 'ok', %q{
open("zzz.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"}
autoload :ZZZ, "./zzz.rb"
require "./zzz.rb"
ZZZ.ok
}
assert_equal 'ok', %q{
open("zzz.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"}
autoload :ZZZ, "./zzz.rb"
proc{$SAFE=4; ZZZ.ok}.call
}
assert_equal 'ok', %q{
open("zzz.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"}
autoload :ZZZ, "./zzz.rb"
require "./zzz.rb"
proc{$SAFE=4; ZZZ.ok}.call
}
assert_equal 'ok', %q{
open("zzz.rb", "w") {|f| f.puts "class ZZZ; def hoge;:ok;end;end"}
autoload :ZZZ, File.join(Dir.pwd, 'zzz.rb')
module M; end
Thread.new{M.instance_eval('$SAFE=4; ZZZ.new.hoge')}.value
}
assert_equal 'ok', %q{
open("zzz.rb", "w") {|f| f.puts "class ZZZ; def hoge;:ok;end;end"}
autoload :ZZZ, File.join(Dir.pwd, 'zzz.rb')
module M; end
Thread.new{$SAFE=4; M.instance_eval('ZZZ.new.hoge')}.value
}
assert_equal 'ok', %q{
open("zzz.rb", "w") {|f| f.puts "class ZZZ; def hoge;:ok;end;end"}
autoload :ZZZ, File.join(Dir.pwd, 'zzz.rb')
Thread.new{$SAFE=4; eval('ZZZ.new.hoge')}.value
}
assert_equal 'ok', %q{
open("zzz.rb", "w") {|f| f.puts "class ZZZ; def hoge;:ok;end;end"}
autoload :ZZZ, File.join(Dir.pwd, 'zzz.rb')
module M; end
Thread.new{eval('$SAFE=4; ZZZ.new.hoge')}.value
}
assert_equal 'okok', %q{
open("zzz.rb", "w") {|f| f.puts "class ZZZ; def self.ok;:ok;end;end"}
autoload :ZZZ, "./zzz.rb"
t1 = Thread.new {ZZZ.ok}
t2 = Thread.new {ZZZ.ok}
[t1.value, t2.value].join
}
assert_finish 5, %q{
autoload :ZZZ, File.expand_path(__FILE__)
begin
ZZZ
rescue NameError
end
}, '[ruby-core:21696]'
assert_equal 'A::C', %q{
open("zzz.rb", "w") {}
class A
autoload :C, "zzz"
class C
end
C
end
}