From 8dc14638eaab3f03a9ad504af4c6ea96b91181a1 Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 13 Dec 2009 16:00:33 +0000 Subject: new test file. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/test_find.rb | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 test/test_find.rb (limited to 'test') diff --git a/test/test_find.rb b/test/test_find.rb new file mode 100644 index 0000000000..d0f5b5c6bc --- /dev/null +++ b/test/test_find.rb @@ -0,0 +1,92 @@ +require 'test/unit' +require 'find' +require 'tmpdir' + +class TestFind < Test::Unit::TestCase + def test_empty + Dir.mktmpdir {|d| + a = [] + Find.find(d) {|f| a << f } + assert_equal([d], a) + } + end + + def test_rec + 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 = [] + 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") + Dir.mkdir("#{d}/b") + File.open("#{d}/b/a", "w") + File.open("#{d}/b/b", "w") + Dir.mkdir("#{d}/c") + a = [] + Find.find(d) {|f| + a << f + Find.prune if f == "#{d}/b" + } + assert_equal([d, "#{d}/a", "#{d}/b", "#{d}/c"], a) + } + end + + def test_countup3 + Dir.mktmpdir {|d| + 1.upto(3) {|n| File.open("#{d}/#{n}", "w") } + a = [] + Find.find(d) {|f| a << f } + assert_equal([d, "#{d}/1", "#{d}/2", "#{d}/3"], a) + } + end + + def test_countdown3 + Dir.mktmpdir {|d| + 3.downto(1) {|n| File.open("#{d}/#{n}", "w") } + a = [] + Find.find(d) {|f| a << f } + assert_equal([d, "#{d}/1", "#{d}/2", "#{d}/3"], a) + } + end + + def test_unreadable_dir + Dir.mktmpdir {|d| + Dir.mkdir(dir = "#{d}/dir") + File.open(file = "#{dir}/foo", "w") + begin + File.chmod(0300, dir) + a = [] + Find.find(d) {|f| a << f } + assert_equal([d, dir], a) + ensure + File.chmod(0700, dir) + end + } + end + + def test_unsearchable_dir + Dir.mktmpdir {|d| + Dir.mkdir(dir = "#{d}/dir") + File.open(file = "#{dir}/foo", "w") + begin + File.chmod(0600, dir) + a = [] + Find.find(d) {|f| a << f } + assert_equal([d, dir, file], a) + assert_raise(Errno::EACCES) { File.lstat(file) } + ensure + File.chmod(0700, dir) + end + } + end + +end -- cgit v1.2.3