1 # $Id: test_fileutils.rb 11708 2007-02-12 23:01:19Z shyouhei $
9 class TestFileUtils < Test::Unit::TestCase
10 TMPROOT = "#{Dir.tmpdir}/fileutils.rb.#{$$}"
14 tmproot = TestFileUtils::TMPROOT
15 Dir.mkdir tmproot unless File.directory?(tmproot)
18 def have_drive_letter?
19 /djgpp|mswin(?!ce)|mingw|bcc|emx/ =~ RUBY_PLATFORM
23 /djgpp|mswin|mingw|bcc|wince|emx/ !~ RUBY_PLATFORM
26 $fileutils_rb_have_symlink = nil
29 if $fileutils_rb_have_symlink == nil
30 $fileutils_rb_have_symlink = check_have_symlink?
32 $fileutils_rb_have_symlink
35 def check_have_symlink?
37 rescue NotImplementedError
43 $fileutils_rb_have_hardlink = nil
46 if $fileutils_rb_have_hardlink == nil
47 $fileutils_rb_have_hardlink = check_have_hardlink?
49 $fileutils_rb_have_hardlink
52 def check_have_hardlink?
54 rescue NotImplementedError
63 def lf_in_path_allowed?
67 def lf_in_path_allowed?
79 def check_singleton(name)
80 assert_equal true, ::FileUtils.public_methods.include?(name.to_s)
84 if File.exist?('/bin/rm')
85 system %Q[/bin/rm -rf "#{path}"]
93 File.chown nil, Process.gid, path if have_file_perm?
99 mymkdir tmproot unless File.directory?(tmproot)
101 my_rm_rf 'data'; mymkdir 'data'
102 my_rm_rf 'tmp'; mymkdir 'tmp'
113 TARGETS = %w( data/a data/all data/random data/zero )
115 def prepare_data_file
116 File.open('data/a', 'w') {|f|
122 all_chars = (0..255).map {|n| n.chr }.join('')
123 File.open('data/all', 'w') {|f|
129 random_chars = (0...50).map { rand(256).chr }.join('')
130 File.open('data/random', 'w') {|f|
136 File.open('data/zero', 'w') {|f|
144 File.open('data/big', 'w') {|f|
145 (4 * 1024 * 1024 / 256).times do # 4MB
146 f.print "aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa\n"
151 def prepare_time_data
152 File.open('data/old', 'w') {|f| f.puts 'dummy' }
153 File.open('data/newer', 'w') {|f| f.puts 'dummy' }
154 File.open('data/newest', 'w') {|f| f.puts 'dummy' }
156 File.utime t-8, t-8, 'data/old'
157 File.utime t-4, t-4, 'data/newer'
161 TARGETS.each do |path|
162 yield path, "tmp/#{File.basename(path)}"
173 assert_equal Dir.pwd, pwd()
176 if have_drive_letter?
178 assert_equal 'C:/', pwd()
180 assert_equal cwd, pwd()
183 assert_equal '/', pwd()
185 assert_equal cwd, pwd()
192 TARGETS.each do |fname|
193 assert cmp(fname, fname), 'not same?'
195 assert_raises(ArgumentError) {
196 cmp TARGETS[0], TARGETS[0], :undefinedoption => true
201 assert_nothing_raised {
202 cmp Pathname.new('tmp/cmptmp'), 'tmp/cmptmp'
203 cmp 'tmp/cmptmp', Pathname.new('tmp/cmptmp')
204 cmp Pathname.new('tmp/cmptmp'), Pathname.new('tmp/cmptmp')
211 each_srcdest do |srcpath, destpath|
213 assert_same_file srcpath, destpath
215 cp srcpath, File.dirname(destpath)
216 assert_same_file srcpath, destpath
218 cp srcpath, File.dirname(destpath) + '/'
219 assert_same_file srcpath, destpath
221 cp srcpath, destpath, :preserve => true
222 assert_same_file srcpath, destpath
223 assert_same_entry srcpath, destpath
226 # src==dest (1) same path
228 assert_raises(ArgumentError) {
229 cp 'tmp/cptmp', 'tmp/cptmp'
232 # src==dest (2) symlink and its target
233 File.symlink 'cptmp', 'tmp/cptmp_symlink'
234 assert_raises(ArgumentError) {
235 cp 'tmp/cptmp', 'tmp/cptmp_symlink'
237 assert_raises(ArgumentError) {
238 cp 'tmp/cptmp_symlink', 'tmp/cptmp'
240 # src==dest (3) looped symlink
241 File.symlink 'symlink', 'tmp/symlink'
242 assert_raises(Errno::ELOOP) {
243 cp 'tmp/symlink', 'tmp/symlink'
248 assert_nothing_raised {
249 cp 'tmp/cptmp', Pathname.new('tmp/tmpdest')
250 cp Pathname.new('tmp/cptmp'), 'tmp/tmpdest'
251 cp Pathname.new('tmp/cptmp'), Pathname.new('tmp/tmpdest')
253 cp ['tmp/cptmp', 'tmp/tmpdest'], Pathname.new('tmp/tmpdir')
258 check_singleton :cp_r
261 TARGETS.each do |fname|
262 assert_same_file fname, "tmp/#{fname}"
265 cp_r 'data', 'tmp2', :preserve => true
266 TARGETS.each do |fname|
267 assert_same_entry fname, "tmp2/#{File.basename(fname)}"
268 assert_same_file fname, "tmp2/#{File.basename(fname)}"
274 File.open('tmp/cpr_src/a', 'w') {|f| f.puts 'a' }
275 File.open('tmp/cpr_src/b', 'w') {|f| f.puts 'b' }
276 File.open('tmp/cpr_src/c', 'w') {|f| f.puts 'c' }
277 mkdir 'tmp/cpr_src/d'
278 cp_r 'tmp/cpr_src/.', 'tmp/cpr_dest'
279 assert_same_file 'tmp/cpr_src/a', 'tmp/cpr_dest/a'
280 assert_same_file 'tmp/cpr_src/b', 'tmp/cpr_dest/b'
281 assert_same_file 'tmp/cpr_src/c', 'tmp/cpr_dest/c'
282 assert_directory 'tmp/cpr_dest/d'
283 my_rm_rf 'tmp/cpr_src'
284 my_rm_rf 'tmp/cpr_dest'
287 # symlink in a directory
289 ln_s 'SLdest', 'tmp/cpr_src/symlink'
290 cp_r 'tmp/cpr_src', 'tmp/cpr_dest'
291 assert_symlink 'tmp/cpr_dest/symlink'
292 assert_equal 'SLdest', File.readlink('tmp/cpr_dest/symlink')
295 ln_s 'cpr_src', 'tmp/cpr_src2'
296 cp_r 'tmp/cpr_src2', 'tmp/cpr_dest2'
297 assert_directory 'tmp/cpr_dest2'
298 #assert_not_symlink 'tmp/cpr_dest2'
299 # * 2005-05-26: feature change on trunk
300 #assert_symlink 'tmp/cpr_dest2'
301 # * 2005-09-19: revert for 1.8 (:dereference_root => true by default)
302 assert_not_symlink 'tmp/cpr_dest2'
303 assert_symlink 'tmp/cpr_dest2/symlink'
304 assert_equal 'SLdest', File.readlink('tmp/cpr_dest2/symlink')
309 assert_nothing_raised {
310 cp_r Pathname.new('tmp/cprtmp'), 'tmp/tmpdest'
311 cp_r 'tmp/cprtmp', Pathname.new('tmp/tmpdest')
312 cp_r Pathname.new('tmp/cprtmp'), Pathname.new('tmp/tmpdest')
320 TARGETS.each do |fname|
321 cp fname, 'tmp/mvsrc'
322 mv 'tmp/mvsrc', 'tmp/mvdest'
323 assert_same_file fname, 'tmp/mvdest'
325 mv 'tmp/mvdest', 'tmp/dest/'
326 assert_same_file fname, 'tmp/dest/mvdest'
328 mv 'tmp/dest/mvdest', 'tmp'
329 assert_same_file fname, 'tmp/mvdest'
334 mkdir_p 'tmp/dest2/tmpdir'
335 assert_raises(Errno::EEXIST) {
336 mv 'tmp/tmpdir', 'tmp/dest2'
338 mkdir 'tmp/dest2/tmpdir/junk'
339 assert_raises(Errno::EEXIST) {
340 mv 'tmp/tmpdir', 'tmp/dest2'
343 # src==dest (1) same path
345 assert_raises(ArgumentError) {
346 mv 'tmp/cptmp', 'tmp/cptmp'
349 # src==dest (2) symlink and its target
350 File.symlink 'cptmp', 'tmp/cptmp_symlink'
351 assert_raises(ArgumentError) {
352 mv 'tmp/cptmp', 'tmp/cptmp_symlink'
354 assert_raises(ArgumentError) {
355 mv 'tmp/cptmp_symlink', 'tmp/cptmp'
357 # src==dest (3) looped symlink
358 File.symlink 'symlink', 'tmp/symlink'
359 assert_raises(Errno::ELOOP) {
360 mv 'tmp/symlink', 'tmp/symlink'
365 assert_nothing_raised {
367 mv Pathname.new('tmp/mvtmpsrc'), 'tmp/mvtmpdest'
369 mv 'tmp/mvtmpsrc', Pathname.new('tmp/mvtmpdest')
371 mv Pathname.new('tmp/mvtmpsrc'), Pathname.new('tmp/mvtmpdest')
378 TARGETS.each do |fname|
379 cp fname, 'tmp/rmsrc'
381 assert_file_not_exist 'tmp/rmsrc'
388 assert_nothing_raised {
389 rm Pathname.new('tmp/rmtmp1')
390 rm [Pathname.new('tmp/rmtmp2'), Pathname.new('tmp/rmtmp3')]
392 assert_file_not_exist 'tmp/rmtmp1'
393 assert_file_not_exist 'tmp/rmtmp2'
394 assert_file_not_exist 'tmp/rmtmp3'
398 check_singleton :rm_f
400 TARGETS.each do |fname|
401 cp fname, 'tmp/rmsrc'
403 assert_file_not_exist 'tmp/rmsrc'
407 File.open('tmp/lnf_symlink_src', 'w') {|f| f.puts 'dummy' }
408 File.symlink 'tmp/lnf_symlink_src', 'tmp/lnf_symlink_dest'
409 rm_f 'tmp/lnf_symlink_dest'
410 assert_file_not_exist 'tmp/lnf_symlink_dest'
411 assert_file_exist 'tmp/lnf_symlink_src'
414 rm_f 'notexistdatafile'
415 rm_f 'tmp/notexistdatafile'
416 my_rm_rf 'tmpdatadir'
417 Dir.mkdir 'tmpdatadir'
419 Dir.rmdir 'tmpdatadir'
421 Dir.mkdir 'tmp/tmpdir'
422 File.open('tmp/tmpdir/a', 'w') {|f| f.puts 'dummy' }
423 File.open('tmp/tmpdir/c', 'w') {|f| f.puts 'dummy' }
424 rm_f ['tmp/tmpdir/a', 'tmp/tmpdir/b', 'tmp/tmpdir/c']
425 assert_file_not_exist 'tmp/tmpdir/a'
426 assert_file_not_exist 'tmp/tmpdir/c'
427 Dir.rmdir 'tmp/tmpdir'
434 assert_nothing_raised {
435 rm_f Pathname.new('tmp/rmtmp1')
436 rm_f [Pathname.new('tmp/rmtmp2'), Pathname.new('tmp/rmtmp3')]
438 assert_file_not_exist 'tmp/rmtmp1'
439 assert_file_not_exist 'tmp/rmtmp2'
440 assert_file_not_exist 'tmp/rmtmp3'
441 assert_file_exist 'tmp/rmtmp4'
445 check_singleton :rm_r
447 my_rm_rf 'tmpdatadir'
449 Dir.mkdir 'tmpdatadir'
451 assert_file_not_exist 'tmpdatadir'
453 Dir.mkdir 'tmpdatadir'
455 assert_file_not_exist 'tmpdatadir'
457 Dir.mkdir 'tmp/tmpdir'
459 assert_file_not_exist 'tmp/tmpdir'
460 assert_file_exist 'tmp'
462 Dir.mkdir 'tmp/tmpdir'
464 assert_file_not_exist 'tmp/tmpdir'
465 assert_file_exist 'tmp'
467 Dir.mkdir 'tmp/tmpdir'
468 File.open('tmp/tmpdir/a', 'w') {|f| f.puts 'dummy' }
469 File.open('tmp/tmpdir/b', 'w') {|f| f.puts 'dummy' }
470 File.open('tmp/tmpdir/c', 'w') {|f| f.puts 'dummy' }
472 assert_file_not_exist 'tmp/tmpdir'
473 assert_file_exist 'tmp'
475 Dir.mkdir 'tmp/tmpdir'
476 File.open('tmp/tmpdir/a', 'w') {|f| f.puts 'dummy' }
477 File.open('tmp/tmpdir/c', 'w') {|f| f.puts 'dummy' }
478 rm_r ['tmp/tmpdir/a', 'tmp/tmpdir/b', 'tmp/tmpdir/c'], :force => true
479 assert_file_not_exist 'tmp/tmpdir/a'
480 assert_file_not_exist 'tmp/tmpdir/c'
481 Dir.rmdir 'tmp/tmpdir'
484 # [ruby-talk:94635] a symlink to the directory
485 Dir.mkdir 'tmp/tmpdir'
486 File.symlink '..', 'tmp/tmpdir/symlink_to_dir'
488 assert_file_not_exist 'tmp/tmpdir'
489 assert_file_exist 'tmp'
493 Dir.mkdir 'tmp/tmpdir1'; touch 'tmp/tmpdir1/tmp'
494 Dir.mkdir 'tmp/tmpdir2'; touch 'tmp/tmpdir2/tmp'
495 Dir.mkdir 'tmp/tmpdir3'; touch 'tmp/tmpdir3/tmp'
496 assert_nothing_raised {
497 rm_r Pathname.new('tmp/tmpdir1')
498 rm_r [Pathname.new('tmp/tmpdir2'), Pathname.new('tmp/tmpdir3')]
500 assert_file_not_exist 'tmp/tmpdir1'
501 assert_file_not_exist 'tmp/tmpdir2'
502 assert_file_not_exist 'tmp/tmpdir3'
505 def test_remove_entry_secure
506 check_singleton :remove_entry_secure
508 my_rm_rf 'tmpdatadir'
510 Dir.mkdir 'tmpdatadir'
511 remove_entry_secure 'tmpdatadir'
512 assert_file_not_exist 'tmpdatadir'
514 Dir.mkdir 'tmpdatadir'
515 remove_entry_secure 'tmpdatadir/'
516 assert_file_not_exist 'tmpdatadir'
518 Dir.mkdir 'tmp/tmpdir'
519 remove_entry_secure 'tmp/tmpdir/'
520 assert_file_not_exist 'tmp/tmpdir'
521 assert_file_exist 'tmp'
523 Dir.mkdir 'tmp/tmpdir'
524 remove_entry_secure 'tmp/tmpdir'
525 assert_file_not_exist 'tmp/tmpdir'
526 assert_file_exist 'tmp'
528 Dir.mkdir 'tmp/tmpdir'
529 File.open('tmp/tmpdir/a', 'w') {|f| f.puts 'dummy' }
530 File.open('tmp/tmpdir/b', 'w') {|f| f.puts 'dummy' }
531 File.open('tmp/tmpdir/c', 'w') {|f| f.puts 'dummy' }
532 remove_entry_secure 'tmp/tmpdir'
533 assert_file_not_exist 'tmp/tmpdir'
534 assert_file_exist 'tmp'
536 Dir.mkdir 'tmp/tmpdir'
537 File.open('tmp/tmpdir/a', 'w') {|f| f.puts 'dummy' }
538 File.open('tmp/tmpdir/c', 'w') {|f| f.puts 'dummy' }
539 remove_entry_secure 'tmp/tmpdir/a', true
540 remove_entry_secure 'tmp/tmpdir/b', true
541 remove_entry_secure 'tmp/tmpdir/c', true
542 assert_file_not_exist 'tmp/tmpdir/a'
543 assert_file_not_exist 'tmp/tmpdir/c'
544 Dir.rmdir 'tmp/tmpdir'
547 # [ruby-talk:94635] a symlink to the directory
548 Dir.mkdir 'tmp/tmpdir'
549 File.symlink '..', 'tmp/tmpdir/symlink_to_dir'
550 remove_entry_secure 'tmp/tmpdir'
551 assert_file_not_exist 'tmp/tmpdir'
552 assert_file_exist 'tmp'
556 Dir.mkdir 'tmp/tmpdir1'; touch 'tmp/tmpdir1/tmp'
557 assert_nothing_raised {
558 remove_entry_secure Pathname.new('tmp/tmpdir1')
560 assert_file_not_exist 'tmp/tmpdir1'
563 def test_with_big_file
566 cp BIGFILE, 'tmp/cpdest'
567 assert_same_file BIGFILE, 'tmp/cpdest'
568 assert cmp(BIGFILE, 'tmp/cpdest'), 'orig != copied'
570 mv 'tmp/cpdest', 'tmp/mvdest'
571 assert_same_file BIGFILE, 'tmp/mvdest'
572 assert_file_not_exist 'tmp/cpdest'
575 assert_file_not_exist 'tmp/mvdest'
580 TARGETS.each do |fname|
581 ln fname, 'tmp/lndest'
582 assert_same_file fname, 'tmp/lndest'
583 File.unlink 'tmp/lndest'
587 TARGETS.each do |fname|
588 assert_same_file fname, 'tmp/' + File.basename(fname)
590 TARGETS.each do |fname|
591 File.unlink 'tmp/' + File.basename(fname)
594 # src==dest (1) same path
596 assert_raises(Errno::EEXIST) {
597 ln 'tmp/cptmp', 'tmp/cptmp'
600 # src==dest (2) symlink and its target
601 File.symlink 'cptmp', 'tmp/symlink'
602 assert_raises(Errno::EEXIST) {
603 ln 'tmp/cptmp', 'tmp/symlink' # normal file -> symlink
605 assert_raises(Errno::EEXIST) {
606 ln 'tmp/symlink', 'tmp/cptmp' # symlink -> normal file
608 # src==dest (3) looped symlink
609 File.symlink 'cptmp_symlink', 'tmp/cptmp_symlink'
611 ln 'tmp/cptmp_symlink', 'tmp/cptmp_symlink'
613 assert_kind_of SystemCallError, err
619 assert_nothing_raised {
620 ln Pathname.new('tmp/lntmp'), 'tmp/lndesttmp1'
621 ln 'tmp/lntmp', Pathname.new('tmp/lndesttmp2')
622 ln Pathname.new('tmp/lntmp'), Pathname.new('tmp/lndesttmp3')
629 check_singleton :ln_s
631 TARGETS.each do |fname|
632 ln_s fname, 'tmp/lnsdest'
633 assert FileTest.symlink?('tmp/lnsdest'), 'not symlink'
634 assert_equal fname, File.readlink('tmp/lnsdest')
637 assert_nothing_raised {
638 ln_s 'symlink', 'tmp/symlink'
640 assert_symlink 'tmp/symlink'
644 assert_nothing_raised {
645 ln_s Pathname.new('lnsdest'), 'tmp/symlink_tmp1'
646 ln_s 'lnsdest', Pathname.new('tmp/symlink_tmp2')
647 ln_s Pathname.new('lnsdest'), Pathname.new('tmp/symlink_tmp3')
654 check_singleton :ln_sf
656 TARGETS.each do |fname|
657 ln_sf fname, 'tmp/lnsdest'
658 assert FileTest.symlink?('tmp/lnsdest'), 'not symlink'
659 assert_equal fname, File.readlink('tmp/lnsdest')
660 ln_sf fname, 'tmp/lnsdest'
661 ln_sf fname, 'tmp/lnsdest'
663 assert_nothing_raised {
664 ln_sf 'symlink', 'tmp/symlink'
669 assert_nothing_raised {
670 ln_sf Pathname.new('lns_dest'), 'tmp/symlink_tmp1'
671 ln_sf 'lns_dest', Pathname.new('tmp/symlink_tmp2')
672 ln_sf Pathname.new('lns_dest'), Pathname.new('tmp/symlink_tmp3')
678 check_singleton :mkdir
680 my_rm_rf 'tmpdatadir'
682 assert_directory 'tmpdatadir'
683 Dir.rmdir 'tmpdatadir'
686 assert_directory 'tmpdatadir'
687 Dir.rmdir 'tmpdatadir'
689 mkdir 'tmp/mkdirdest'
690 assert_directory 'tmp/mkdirdest'
691 Dir.rmdir 'tmp/mkdirdest'
693 mkdir 'tmp/tmp', :mode => 0700
694 assert_directory 'tmp/tmp'
695 assert_equal 0700, (File.stat('tmp/tmp').mode & 0777) if have_file_perm?
699 mkdir 'tmp/tmp', :mode => 07777
700 assert_directory 'tmp/tmp'
701 assert_equal 07777, (File.stat('tmp/tmp').mode & 07777)
705 if lf_in_path_allowed?
706 mkdir "tmp-first-line\ntmp-second-line"
707 assert_directory "tmp-first-line\ntmp-second-line"
708 Dir.rmdir "tmp-first-line\ntmp-second-line"
712 assert_nothing_raised {
713 mkdir Pathname.new('tmp/tmpdirtmp')
714 mkdir [Pathname.new('tmp/tmpdirtmp2'), Pathname.new('tmp/tmpdirtmp3')]
719 check_singleton :mkdir_p
724 tmpdir/dir/./.././dir/
731 tmpdir/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a
738 assert_file_not_exist "#{d}/a"
739 assert_file_not_exist "#{d}/b"
740 assert_file_not_exist "#{d}/c"
749 mkdir_p "#{Dir.pwd}/#{d}"
754 mkdir_p 'tmp/tmp/tmp', :mode => 0700
755 assert_directory 'tmp/tmp'
756 assert_directory 'tmp/tmp/tmp'
757 assert_equal 0700, (File.stat('tmp/tmp').mode & 0777) if have_file_perm?
758 assert_equal 0700, (File.stat('tmp/tmp/tmp').mode & 0777) if have_file_perm?
761 mkdir_p 'tmp/tmp', :mode => 0
762 assert_directory 'tmp/tmp'
763 assert_equal 0, (File.stat('tmp/tmp').mode & 0777) if have_file_perm?
764 # DO NOT USE rm_rf here.
765 # (rm(1) try to chdir to parent directory, it fails to remove directory.)
770 mkdir_p 'tmp/tmp/tmp', :mode => 07777
771 assert_directory 'tmp/tmp/tmp'
772 assert_equal 07777, (File.stat('tmp/tmp/tmp').mode & 07777)
773 Dir.rmdir 'tmp/tmp/tmp'
778 assert_nothing_raised {
779 mkdir_p Pathname.new('tmp/tmp/tmp')
784 check_singleton :install
786 File.open('tmp/aaa', 'w') {|f| f.puts 'aaa' }
787 File.open('tmp/bbb', 'w') {|f| f.puts 'bbb' }
788 install 'tmp/aaa', 'tmp/bbb', :mode => 0600
789 assert_equal "aaa\n", File.read('tmp/bbb')
790 assert_equal 0600, (File.stat('tmp/bbb').mode & 0777) if have_file_perm?
792 t = File.mtime('tmp/bbb')
793 install 'tmp/aaa', 'tmp/bbb'
794 assert_equal "aaa\n", File.read('tmp/bbb')
795 assert_equal 0600, (File.stat('tmp/bbb').mode & 0777) if have_file_perm?
796 assert_equal t, File.mtime('tmp/bbb')
798 File.unlink 'tmp/aaa'
799 File.unlink 'tmp/bbb'
801 # src==dest (1) same path
803 assert_raises(ArgumentError) {
804 install 'tmp/cptmp', 'tmp/cptmp'
807 # src==dest (2) symlink and its target
808 File.symlink 'cptmp', 'tmp/cptmp_symlink'
809 assert_raises(ArgumentError) {
810 install 'tmp/cptmp', 'tmp/cptmp_symlink'
812 assert_raises(ArgumentError) {
813 install 'tmp/cptmp_symlink', 'tmp/cptmp'
815 # src==dest (3) looped symlink
816 File.symlink 'symlink', 'tmp/symlink'
817 assert_raises(Errno::ELOOP) {
818 # File#install invokes open(2), always ELOOP must be raised
819 install 'tmp/symlink', 'tmp/symlink'
824 assert_nothing_raised {
825 rm_f 'tmp/a'; touch 'tmp/a'
826 install 'tmp/a', Pathname.new('tmp/b')
827 rm_f 'tmp/a'; touch 'tmp/a'
828 install Pathname.new('tmp/a'), 'tmp/b'
829 rm_f 'tmp/a'; touch 'tmp/a'
830 install Pathname.new('tmp/a'), Pathname.new('tmp/b')
835 install [Pathname.new('tmp/a'), Pathname.new('tmp/b')], 'tmp/dest'
838 install [Pathname.new('tmp/a'), Pathname.new('tmp/b')], Pathname.new('tmp/dest')
844 check_singleton :chmod
848 assert_equal 0700, File.stat('tmp/a').mode & 0777
850 assert_equal 0500, File.stat('tmp/a').mode & 0777
854 check_singleton :chmod_R
856 mkdir_p 'tmp/dir/dir'
857 touch %w( tmp/dir/file tmp/dir/dir/file )
858 chmod_R 0700, 'tmp/dir'
859 assert_equal 0700, File.stat('tmp/dir').mode & 0777
860 assert_equal 0700, File.stat('tmp/dir/file').mode & 0777
861 assert_equal 0700, File.stat('tmp/dir/dir').mode & 0777
862 assert_equal 0700, File.stat('tmp/dir/dir/file').mode & 0777
863 chmod_R 0500, 'tmp/dir'
864 assert_equal 0500, File.stat('tmp/dir').mode & 0777
865 assert_equal 0500, File.stat('tmp/dir/file').mode & 0777
866 assert_equal 0500, File.stat('tmp/dir/dir').mode & 0777
867 assert_equal 0500, File.stat('tmp/dir/dir/file').mode & 0777
868 chmod_R 0700, 'tmp/dir' # to remove
871 # FIXME: How can I test this method?
873 check_singleton :chown
876 # FIXME: How can I test this method?
878 check_singleton :chown_R
883 check_singleton :copy_entry
885 each_srcdest do |srcpath, destpath|
886 copy_entry srcpath, destpath
887 assert_same_file srcpath, destpath
888 assert_equal File.stat(srcpath).ftype, File.stat(destpath).ftype
892 File.symlink 'somewhere', 'tmp/symsrc'
893 copy_entry 'tmp/symsrc', 'tmp/symdest'
894 assert_symlink 'tmp/symdest'
895 assert_equal 'somewhere', File.readlink('tmp/symdest')
897 # content is a symlink
899 File.symlink 'somewhere', 'tmp/dir/sym'
900 copy_entry 'tmp/dir', 'tmp/dirdest'
901 assert_directory 'tmp/dirdest'
902 assert_not_symlink 'tmp/dirdest'
903 assert_symlink 'tmp/dirdest/sym'
904 assert_equal 'somewhere', File.readlink('tmp/dirdest/sym')
909 check_singleton :copy_file
911 each_srcdest do |srcpath, destpath|
912 copy_file srcpath, destpath
913 assert_same_file srcpath, destpath
918 check_singleton :copy_stream
920 each_srcdest do |srcpath, destpath|
921 File.open(srcpath) {|src|
922 File.open(destpath, 'w') {|dest|
923 copy_stream src, dest
926 assert_same_file srcpath, destpath
929 # duck typing test [ruby-dev:25369]
932 each_srcdest do |srcpath, destpath|
933 File.open(srcpath) {|src|
934 File.open(destpath, 'w') {|dest|
935 copy_stream Stream.new(src), Stream.new(dest)
938 assert_same_file srcpath, destpath
943 check_singleton :remove_file
944 File.open('data/tmp', 'w') {|f| f.puts 'dummy' }
945 remove_file 'data/tmp'
946 assert_file_not_exist 'data/tmp'
948 File.open('data/tmp', 'w') {|f| f.puts 'dummy' }
949 File.chmod 0, 'data/tmp'
950 remove_file 'data/tmp'
951 assert_file_not_exist 'data/tmp'
956 check_singleton :remove_dir
957 Dir.mkdir 'data/tmpdir'
958 File.open('data/tmpdir/a', 'w') {|f| f.puts 'dummy' }
959 remove_dir 'data/tmpdir'
960 assert_file_not_exist 'data/tmpdir'
962 Dir.mkdir 'data/tmpdir'
963 File.chmod 0555, 'data/tmpdir'
964 remove_dir 'data/tmpdir'
965 assert_file_not_exist 'data/tmpdir'
969 def test_compare_file
970 check_singleton :compare_file
974 def test_compare_stream
975 check_singleton :compare_stream
994 check_singleton :uptodate?
997 assert( uptodate?('newest', %w(old newer notexist)) )
998 assert( ! uptodate?('newer', %w(old newest notexist)) )
999 assert( ! uptodate?('notexist', %w(old newest newer)) )
1006 assert_nothing_raised {
1007 uptodate? Pathname.new('tmp/a'), ['tmp/b', 'tmp/c']
1008 uptodate? 'tmp/a', [Pathname.new('tmp/b'), 'tmp/c']
1009 uptodate? 'tmp/a', ['tmp/b', Pathname.new('tmp/c')]
1010 uptodate? Pathname.new('tmp/a'), [Pathname.new('tmp/b'), Pathname.new('tmp/c')]
1019 check_singleton :chdir
1023 check_singleton :getwd
1027 check_singleton :identical?
1031 check_singleton :link
1035 check_singleton :makedirs
1039 check_singleton :mkpath
1043 check_singleton :move
1047 check_singleton :rm_rf
1051 check_singleton :rmdir
1055 check_singleton :rmtree
1058 def test_safe_unlink
1059 check_singleton :safe_unlink
1063 check_singleton :symlink
1067 check_singleton :touch
1070 def test_collect_methods
1076 def test_have_option?