summaryrefslogtreecommitdiffstats
path: root/test/ruby
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-09 07:21:49 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-09 07:21:49 +0000
commita5c4bdc35210fed3a1775ad57359eb99e58288f9 (patch)
tree93c8dc47b0616af6001a90f76ccb7ae6d2a7a63a /test/ruby
parent6261e58116bb92dabf51460742de0aa177b297f6 (diff)
downloadruby-a5c4bdc35210fed3a1775ad57359eb99e58288f9.tar.gz
ruby-a5c4bdc35210fed3a1775ad57359eb99e58288f9.tar.xz
ruby-a5c4bdc35210fed3a1775ad57359eb99e58288f9.zip
* test/ruby/test_require.rb (test_relative): tests for require_relative.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@24818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_require.rb20
1 files changed, 19 insertions, 1 deletions
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb
index a1726bf63..b2cdae3fd 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