Fix some symbol.to_proc problems
[jruby.git] / test / test_load.rb
blob13cdc862eb2c78bd38456bf20ed943f80a53066f
1 require 'test/unit'
3 def load_behavior_block(&block)
4   eval("__FILE__", block.binding)
5 end
7 class TestLoad < Test::Unit::TestCase
8   def test_require
9     # Allow us to run MRI against non-Java dependent tests
10     if RUBY_PLATFORM=~/java/
11       $ruby_init = false
12       file = __FILE__
13       if (File::Separator == '\\')
14         file.gsub!('\\\\', '/')
15       end
16       # Load jar file RubyInitTest.java
17       require File::dirname(file) + "/RubyInitTest"
18       assert($ruby_init)
20       # JRUBY-1229, allow loading jar files without manifest
21       assert_nothing_raised {
22         require "test/jar_with_no_manifest.jar"
23       }
24     end
26     assert require('test/requireTarget')
27     assert !require('test/requireTarget')
29     $loaded_foo_bar = false
30     assert require('test/foo.bar')
31     assert $loaded_foo_bar
32   end
33   
34   def test_require_bogus
35     assert_raises(LoadError) { require 'foo/' }
36     assert_raises(LoadError) { require '' }
37     
38     # Yes, the following line is supposed to appear twice
39     assert_raises(LoadError) { require 'NonExistantRequriedFile'}
40     assert_raises(LoadError) { require 'NonExistantRequriedFile'}
41   end
43   def test_require_jar_should_make_its_scripts_accessible
44     require 'test/jar_with_ruby_files'
45     require 'hello_from_jar'
46     assert "hi", $hello
47   end
48   
49   def test_overriding_require_shouldnt_cause_problems
50     eval(<<DEPS, binding, "deps")
51 class ::Object
52   alias old_require require
53   
54   def require(file)
55     old_require(file)
56   end
57 end
58 DEPS
60     require 'test/test_loading_behavior'
62     res = File.expand_path($loading_behavior_result)
64     assert_equal File.expand_path(File.join('test', 'test_loading_behavior.rb')), res
65   end
66 end