###################################################################### # tc_find.rb # # Test case for the File::Find package. ###################################################################### Dir.chdir '..' if File.basename(Dir.pwd) == 'test' $:.unshift File.join(Dir.pwd, 'lib') require 'test/unit' require 'fileutils' require 'file/find' class TC_File_Find < Test::Unit::TestCase def setup @file1 = 'test1.rb' @file2 = 'test1.txt' @link1 = 'link1' File.open(@file1, 'w'){} File.open(@file2, 'w'){} File.symlink(@file1, @link1) @rule1 = File::Find.new(:name => '*.rb') end def test_path assert_respond_to(@rule1, :path) assert_respond_to(@rule1, :path=) assert_equal(Dir.pwd, @rule1.path) end def test_options assert_respond_to(@rule1, :options) assert_respond_to(@rule1, :options=) assert_equal({:name => '*.rb'}, @rule1.options) end def test_atime_basic assert_respond_to(@rule1, :atime) assert_respond_to(@rule1, :atime=) assert_nil(@rule1.atime) end def test_atime rule1 = File::Find.new(:name => "*.rb", :atime => 0) rule2 = File::Find.new(:name => "*.rb", :atime => 1) assert_equal(false, rule1.find.empty?) assert_equal(true, rule2.find.empty?) end def test_ctime_basic assert_respond_to(@rule1, :ctime) assert_respond_to(@rule1, :ctime=) assert_nil(@rule1.ctime) end def test_ctime rule1 = File::Find.new(:name => "*.rb", :ctime => 0) rule2 = File::Find.new(:name => "*.rb", :ctime => 1) assert_equal(false, rule1.find.empty?) assert_equal(true, rule2.find.empty?) end def test_ftype_basic assert_respond_to(@rule1, :ftype) assert_respond_to(@rule1, :ftype=) assert_nil(@rule1.ftype) end def test_ftype rule1 = File::Find.new(:name => "*.rb", :ftype => "file") rule2 = File::Find.new(:name => "*.rb", :ftype => "characterSpecial") assert_equal(false, rule1.find.empty?) assert_equal(true, rule2.find.empty?) end def test_group_basic assert_respond_to(@rule1, :group) assert_respond_to(@rule1, :group=) assert_nil(@rule1.group) end def test_inum_basic assert_respond_to(@rule1, :inum) assert_respond_to(@rule1, :inum=) assert_nil(@rule1.inum) end def test_follow_basic assert_respond_to(@rule1, :follow) assert_respond_to(@rule1, :follow=) assert_equal(true, @rule1.follow) end def test_name_basic assert_respond_to(@rule1, :name) assert_respond_to(@rule1, :name=) assert_equal('*.rb', @rule1.name) end def test_size_basic assert_respond_to(@rule1, :size) assert_respond_to(@rule1, :size=) assert_nil(@rule1.size) end def test_user_basic assert_respond_to(@rule1, :user) assert_respond_to(@rule1, :user=) assert_nil(@rule1.user) end def test_expected_errors assert_raises(Errno::ENOENT){ File::Find.new(:path => '/bogus/dir').find } end def teardown FileUtils.rm_rf(@file1) FileUtils.rm_rf(@file2) FileUtils.rm_rf(@link1) end end