aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_find.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-14 11:56:03 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-12-14 11:56:03 +0000
commit4df4a7430865257795938c3dd791e3c0afee8778 (patch)
treec28dd817511729605d5e187cee4df9af063627a3 /test/test_find.rb
parent315cab1249095a228482d57bc30bea2aabf4ca0f (diff)
downloadruby-4df4a7430865257795938c3dd791e3c0afee8778.tar.gz
add tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/test_find.rb')
-rw-r--r--test/test_find.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/test_find.rb b/test/test_find.rb
index bcd27e7645..7e9f21fdd4 100644
--- a/test/test_find.rb
+++ b/test/test_find.rb
@@ -24,6 +24,34 @@ class TestFind < Test::Unit::TestCase
}
end
+ def test_relative
+ Dir.mktmpdir {|d|
+ File.open("#{d}/a", "w")
+ Dir.mkdir("#{d}/b")
+ File.open("#{d}/b/a", "w")
+ File.open("#{d}/b/b", "w")
+ Dir.mkdir("#{d}/c")
+ a = []
+ Dir.chdir(d) {
+ Find.find(".") {|f| a << f }
+ }
+ assert_equal([".", "./a", "./b", "./b/a", "./b/b", "./c"], a)
+ }
+ end
+
+ def test_dont_follow_symlink
+ Dir.mktmpdir {|d|
+ File.open("#{d}/a", "w")
+ Dir.mkdir("#{d}/b")
+ File.open("#{d}/b/a", "w")
+ File.open("#{d}/b/b", "w")
+ File.symlink("#{d}/b", "#{d}/c")
+ a = []
+ Find.find(d) {|f| a << f }
+ assert_equal([d, "#{d}/a", "#{d}/b", "#{d}/b/a", "#{d}/b/b", "#{d}/c"], a)
+ }
+ end
+
def test_prune
Dir.mktmpdir {|d|
File.open("#{d}/a", "w")
@@ -89,6 +117,30 @@ class TestFind < Test::Unit::TestCase
}
end
+ def test_dangling_symlink
+ Dir.mktmpdir {|d|
+ File.symlink("foo", "#{d}/bar")
+ a = []
+ Find.find(d) {|f| a << f }
+ assert_equal([d, "#{d}/bar"], a)
+ assert_raise(Errno::ENOENT) { File.stat("#{d}/bar") }
+ }
+ end
+
+ def test_enumerator
+ Dir.mktmpdir {|d|
+ File.open("#{d}/a", "w")
+ Dir.mkdir("#{d}/b")
+ File.open("#{d}/b/a", "w")
+ File.open("#{d}/b/b", "w")
+ Dir.mkdir("#{d}/c")
+ e = Find.find(d)
+ a = []
+ e.each {|f| a << f }
+ assert_equal([d, "#{d}/a", "#{d}/b", "#{d}/b/a", "#{d}/b/b", "#{d}/c"], a)
+ }
+ end
+
class TestInclude < Test::Unit::TestCase
include Find