2 def eval_part(libname, sep, part)
3 path = libpath(libname)
4 program = File.open(path) { |f| f.read }
5 mainpart, endpart = program.split(sep)
7 raise RuntimeError.new("No #{part} part in the library '#{path}'")
9 eval(endpart, TOPLEVEL_BINDING, path, mainpart.count("\n")+1)
11 module_function :eval_part
16 in_progname(libpath(libname)) do
17 eval_part(libname, /^(?=if\s+(?:\$0\s*==\s*__FILE__|__FILE__\s*==\s*\$0)(?:[\#\s]|$))/, '$0 == __FILE__')
21 module_function :loadtest
23 def loadtest__END__part(libname)
25 eval_part(libname, /^__END__\r?$/, '__END__')
27 module_function :loadtest__END__part
31 def self.in_critical(&block)
32 @mutex.synchronize(&block)
35 def self.in_progname(progname)
36 $program_name = progname
37 alias $0 $program_name
41 alias $0 $PROGRAM_NAME
45 def self.libpath(libname)
48 File.file?(testname = File.join(path, libname)) && libpath = testname
51 raise RuntimeError.new("'#{libname}' not found")