require 'test/unit' require 'test/test_helper' require 'rbconfig' def load_behavior_block(&block) eval("__FILE__", block.binding) end class TestLoad < Test::Unit::TestCase include TestHelper def test_require # Allow us to run MRI against non-Java dependent tests if RUBY_PLATFORM=~/java/ $ruby_init = false file = __FILE__ if (File::Separator == '\\') file.gsub!('\\\\', '/') end # Load jar file RubyInitTest.java require File::dirname(file) + "/RubyInitTest" assert($ruby_init) # JRUBY-1229, allow loading jar files without manifest assert_nothing_raised { require "test/jar_with_no_manifest.jar" } end assert require('test/requireTarget') assert !require('test/requireTarget') $loaded_foo_bar = false assert require('test/foo.bar') assert $loaded_foo_bar end def test_require_bogus assert_raises(LoadError) { require 'foo/' } assert_raises(LoadError) { require '' } # Yes, the following line is supposed to appear twice assert_raises(LoadError) { require 'NonExistantRequriedFile'} assert_raises(LoadError) { require 'NonExistantRequriedFile'} end def test_require_jar_should_make_its_scripts_accessible require 'test/jar_with_ruby_files' require 'hello_from_jar' assert "hi", $hello end def call_extern_load_foo_bar(classpath = nil) cmd = "" # FIX plain windows cmd += "CLASSPATH=#{classpath}" if classpath cmd += "unset CLASSPATH &&" unless classpath cmd += " #{Config::CONFIG['bindir']}/#{Config::CONFIG['RUBY_INSTALL_NAME']} -e " cmd += "'"+'begin load "./test/foo.bar.rb"; rescue Exception => e; print "FAIL"; else print "OK"; end'+"'" `#{cmd}` end def test_load_relative_with_classpath # FIX for Windows unless WINDOWS assert_equal call_extern_load_foo_bar(File.join('test', 'jar_with_ruby_files.jar')), 'OK' end end def test_load_relative_with_classpath_ends_colon # FIX for Windows unless WINDOWS assert_equal call_extern_load_foo_bar(File.join('test', 'jar_with_ruby_files.jar') + ':'), 'OK' end end def test_load_relative_without_classpath # FIX for Windows unless WINDOWS assert_equal call_extern_load_foo_bar(), 'OK' end end def test_require_with_non_existent_jar_1 $:.unshift "file:/someHopefullyUnexistentJarFile.jar/" filename = File.join(File.dirname(__FILE__), "blargus1.rb") require_name = File.join(File.dirname(__FILE__), "blargus1") assert !defined?($_blargus_has_been_loaded_oh_yeah_baby_1) File.open(filename, "w") do |f| f.write <