diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-09 07:21:49 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-09 07:21:49 +0000 |
commit | 481a6476ce0b2669f98e0bcdaa9e210c411b166b (patch) | |
tree | 93c8dc47b0616af6001a90f76ccb7ae6d2a7a63a | |
parent | 31a6d508635815d24ced07c5a65273cb0fcf54de (diff) | |
download | ruby-481a6476ce0b2669f98e0bcdaa9e210c411b166b.tar.gz |
* test/ruby/test_require.rb (test_relative): tests for require_relative.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | test/ruby/test_require.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb index a1726bf63b..b2cdae3fda 100644 --- a/test/ruby/test_require.rb +++ b/test/ruby/test_require.rb @@ -198,7 +198,7 @@ class TestRequire < Test::Unit::TestCase def test_tainted_loadpath t = Tempfile.new(["test_ruby_test_require", ".rb"]) - abs_dir, file = File.dirname(t.path), File.basename(t.path) + abs_dir, file = File.split(t.path) abs_dir = File.expand_path(abs_dir).untaint assert_in_out_err([], <<-INPUT, %w(:ok), []) @@ -244,4 +244,22 @@ class TestRequire < Test::Unit::TestCase p :ok INPUT end + + def test_relative + require 'tmpdir' + Dir.mktmpdir do |tmp| + Dir.chdir(tmp) do + Dir.mkdir('x') + File.open('x/t.rb', 'wb') {} + File.open('x/a.rb', 'wb') {|f| f.puts("require_relative('t.rb')")} + assert require('./x/t.rb') + assert !require(File.expand_path('x/t.rb')) + assert_nothing_raised(LoadError) {require('./x/a.rb')} + assert_raise(LoadError) {require('x/t.rb')} + File.unlink(*Dir.glob('x/*')) + Dir.rmdir("#{tmp}/x") + assert(!require('tmpdir')) + end + end + end end |