1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/fileutils.rb: use module_function instead of single extend.

* test/fileutils/test_fileutils.rb: test existence of singleton methods.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9215 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2005-09-18 20:59:29 +00:00
parent 14d206dbb5
commit b7083f661d
3 changed files with 258 additions and 20 deletions

View file

@ -1,3 +1,10 @@
Mon Sep 19 05:58:59 2005 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb: use module_function instead of single extend.
* test/fileutils/test_fileutils.rb: test existence of singleton
methods.
Mon Sep 19 05:32:41 2005 Minero Aoki <aamine@loveruby.net> Mon Sep 19 05:32:41 2005 Minero Aoki <aamine@loveruby.net>
* lib/fileutils.rb (remove_entry_secure): does not use chdir(2). * lib/fileutils.rb (remove_entry_secure): does not use chdir(2).

View file

@ -84,7 +84,10 @@
module FileUtils module FileUtils
# All methods are module_function. def self.private_module_function(name) #:nodoc:
module_function name
private_class_method name
end
# This hash table holds command options. # This hash table holds command options.
OPT_TABLE = {} #:nodoc: internal use only OPT_TABLE = {} #:nodoc: internal use only
@ -97,8 +100,10 @@ module FileUtils
def pwd def pwd
Dir.pwd Dir.pwd
end end
module_function :pwd
alias getwd pwd alias getwd pwd
module_function :getwd
# #
# Options: verbose # Options: verbose
@ -116,8 +121,10 @@ module FileUtils
Dir.chdir(dir, &block) unless options[:noop] Dir.chdir(dir, &block) unless options[:noop]
fu_output_message 'cd -' if options[:verbose] and block fu_output_message 'cd -' if options[:verbose] and block
end end
module_function :cd
alias chdir cd alias chdir cd
module_function :chdir
OPT_TABLE['cd'] = OPT_TABLE['cd'] =
OPT_TABLE['chdir'] = %w( verbose ) OPT_TABLE['chdir'] = %w( verbose )
@ -143,6 +150,7 @@ module FileUtils
end end
true true
end end
module_function :uptodate?
# #
# Options: mode noop verbose # Options: mode noop verbose
@ -164,6 +172,7 @@ module FileUtils
fu_mkdir dir, options[:mode] fu_mkdir dir, options[:mode]
end end
end end
module_function :mkdir
OPT_TABLE['mkdir'] = %w( noop verbose mode ) OPT_TABLE['mkdir'] = %w( noop verbose mode )
@ -214,15 +223,18 @@ module FileUtils
return *list return *list
end end
module_function :mkdir_p
alias mkpath mkdir_p alias mkpath mkdir_p
alias makedirs mkdir_p alias makedirs mkdir_p
module_function :mkpath
module_function :makedirs
OPT_TABLE['mkdir_p'] = OPT_TABLE['mkdir_p'] =
OPT_TABLE['mkpath'] = OPT_TABLE['mkpath'] =
OPT_TABLE['makedirs'] = %w( noop verbose ) OPT_TABLE['makedirs'] = %w( noop verbose )
def fu_mkdir(path, mode) def fu_mkdir(path, mode) #:nodoc:
path = path.sub(%r</\z>, '') path = path.sub(%r</\z>, '')
if mode if mode
Dir.mkdir path, mode Dir.mkdir path, mode
@ -231,7 +243,7 @@ module FileUtils
Dir.mkdir path Dir.mkdir path
end end
end end
private :fu_mkdir private_module_function :fu_mkdir
# #
# Options: noop, verbose # Options: noop, verbose
@ -252,6 +264,7 @@ module FileUtils
Dir.rmdir dir.sub(%r</\z>, '') Dir.rmdir dir.sub(%r</\z>, '')
end end
end end
module_function :rmdir
OPT_TABLE['rmdir'] = %w( noop verbose ) OPT_TABLE['rmdir'] = %w( noop verbose )
@ -286,8 +299,10 @@ module FileUtils
File.link s, d File.link s, d
end end
end end
module_function :ln
alias link ln alias link ln
module_function :link
OPT_TABLE['ln'] = OPT_TABLE['ln'] =
OPT_TABLE['link'] = %w( noop verbose force ) OPT_TABLE['link'] = %w( noop verbose force )
@ -323,8 +338,10 @@ module FileUtils
File.symlink s, d File.symlink s, d
end end
end end
module_function :ln_s
alias symlink ln_s alias symlink ln_s
module_function :symlink
OPT_TABLE['ln_s'] = OPT_TABLE['ln_s'] =
OPT_TABLE['symlink'] = %w( noop verbose force ) OPT_TABLE['symlink'] = %w( noop verbose force )
@ -341,6 +358,7 @@ module FileUtils
options[:force] = true options[:force] = true
ln_s src, dest, options ln_s src, dest, options
end end
module_function :ln_sf
OPT_TABLE['ln_sf'] = %w( noop verbose ) OPT_TABLE['ln_sf'] = %w( noop verbose )
@ -365,8 +383,10 @@ module FileUtils
copy_file s, d, options[:preserve] copy_file s, d, options[:preserve]
end end
end end
module_function :cp
alias copy cp alias copy cp
module_function :copy
OPT_TABLE['cp'] = OPT_TABLE['cp'] =
OPT_TABLE['copy'] = %w( noop verbose preserve ) OPT_TABLE['copy'] = %w( noop verbose preserve )
@ -402,6 +422,7 @@ module FileUtils
copy_entry s, d, options[:preserve], options[:dereference_root] copy_entry s, d, options[:preserve], options[:dereference_root]
end end
end end
module_function :cp_r
OPT_TABLE['cp_r'] = %w( noop verbose preserve dereference_root ) OPT_TABLE['cp_r'] = %w( noop verbose preserve dereference_root )
@ -426,6 +447,7 @@ module FileUtils
ent.copy_metadata destent.path if preserve ent.copy_metadata destent.path if preserve
end end
end end
module_function :copy_entry
# #
# Copies file contents of +src+ to +dest+. # Copies file contents of +src+ to +dest+.
@ -436,6 +458,7 @@ module FileUtils
ent.copy_file dest ent.copy_file dest
ent.copy_metadata dest if preserve ent.copy_metadata dest if preserve
end end
module_function :copy_file
# #
# Copies stream +src+ to +dest+. # Copies stream +src+ to +dest+.
@ -445,6 +468,7 @@ module FileUtils
def copy_stream(src, dest) def copy_stream(src, dest)
fu_copy_stream0 src, dest, fu_stream_blksize(src, dest) fu_copy_stream0 src, dest, fu_stream_blksize(src, dest)
end end
module_function :copy_stream
# #
# Options: force noop verbose # Options: force noop verbose
@ -482,8 +506,10 @@ module FileUtils
end end
end end
end end
module_function :mv
alias move mv alias move mv
module_function :move
OPT_TABLE['mv'] = OPT_TABLE['mv'] =
OPT_TABLE['move'] = %w( noop verbose force ) OPT_TABLE['move'] = %w( noop verbose force )
@ -491,7 +517,7 @@ module FileUtils
def rename_cannot_overwrite_file? #:nodoc: def rename_cannot_overwrite_file? #:nodoc:
/djgpp|cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM /djgpp|cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM
end end
private :rename_cannot_overwrite_file? private_module_function :rename_cannot_overwrite_file?
# #
# Options: force noop verbose # Options: force noop verbose
@ -513,8 +539,10 @@ module FileUtils
remove_file path, options[:force] remove_file path, options[:force]
end end
end end
module_function :rm
alias remove rm alias remove rm
module_function :remove
OPT_TABLE['rm'] = OPT_TABLE['rm'] =
OPT_TABLE['remove'] = %w( noop verbose force ) OPT_TABLE['remove'] = %w( noop verbose force )
@ -532,8 +560,10 @@ module FileUtils
options[:force] = true options[:force] = true
rm list, options rm list, options
end end
module_function :rm_f
alias safe_unlink rm_f alias safe_unlink rm_f
module_function :safe_unlink
OPT_TABLE['rm_f'] = OPT_TABLE['rm_f'] =
OPT_TABLE['safe_unlink'] = %w( noop verbose ) OPT_TABLE['safe_unlink'] = %w( noop verbose )
@ -573,6 +603,7 @@ module FileUtils
end end
end end
end end
module_function :rm_r
OPT_TABLE['rm_r'] = %w( noop verbose force secure ) OPT_TABLE['rm_r'] = %w( noop verbose force secure )
@ -592,8 +623,10 @@ module FileUtils
options[:force] = true options[:force] = true
rm_r list, options rm_r list, options
end end
module_function :rm_rf
alias rmtree rm_rf alias rmtree rm_rf
module_function :rmtree
OPT_TABLE['rm_rf'] = OPT_TABLE['rm_rf'] =
OPT_TABLE['rmtree'] = %w( noop verbose secure ) OPT_TABLE['rmtree'] = %w( noop verbose secure )
@ -679,19 +712,21 @@ module FileUtils
rescue rescue
raise unless force raise unless force
end end
module_function :remove_entry_secure
def fu_have_symlink? def fu_have_symlink? #:nodoc
File.symlink nil, nil File.symlink nil, nil
rescue NotImplementedError rescue NotImplementedError
return false return false
rescue rescue
return true return true
end end
private_module_function :fu_have_symlink?
def fu_stat_identical_entry?(a, b) def fu_stat_identical_entry?(a, b) #:nodoc:
a.dev == b.dev and a.ino == b.ino a.dev == b.dev and a.ino == b.ino
end end
private :fu_stat_identical_entry? private_module_function :fu_stat_identical_entry?
# #
# This method removes a file system entry +path+. # This method removes a file system entry +path+.
@ -711,6 +746,7 @@ module FileUtils
rescue rescue
raise unless force raise unless force
end end
module_function :remove_entry
# #
# Removes a file +path+. # Removes a file +path+.
@ -721,6 +757,7 @@ module FileUtils
rescue rescue
raise unless force raise unless force
end end
module_function :remove_file
# #
# Removes a directory +dir+ and its contents recursively. # Removes a directory +dir+ and its contents recursively.
@ -729,6 +766,7 @@ module FileUtils
def remove_dir(path, force = false) def remove_dir(path, force = false)
remove_entry path, force # FIXME?? check if it is a directory remove_entry path, force # FIXME?? check if it is a directory
end end
module_function :remove_dir
# #
# Returns true if the contents of a file A and a file B are identical. # Returns true if the contents of a file A and a file B are identical.
@ -744,9 +782,12 @@ module FileUtils
} }
} }
end end
module_function :compare_file
alias identical? compare_file alias identical? compare_file
alias cmp compare_file alias cmp compare_file
module_function :identical?
module_function :cmp
# #
# Returns true if the contents of a stream +a+ and +b+ are identical. # Returns true if the contents of a stream +a+ and +b+ are identical.
@ -765,6 +806,7 @@ module FileUtils
end end
false false
end end
module_function :compare_stream
# #
# Options: mode noop verbose # Options: mode noop verbose
@ -789,6 +831,7 @@ module FileUtils
end end
end end
end end
module_function :install
OPT_TABLE['install'] = %w( noop verbose preserve mode ) OPT_TABLE['install'] = %w( noop verbose preserve mode )
@ -811,6 +854,7 @@ module FileUtils
Entry_.new(path).chmod mode Entry_.new(path).chmod mode
end end
end end
module_function :chmod
OPT_TABLE['chmod'] = %w( noop verbose ) OPT_TABLE['chmod'] = %w( noop verbose )
@ -839,6 +883,7 @@ module FileUtils
end end
end end
end end
module_function :chmod_R
OPT_TABLE['chmod_R'] = %w( noop verbose ) OPT_TABLE['chmod_R'] = %w( noop verbose )
@ -867,6 +912,7 @@ module FileUtils
Entry_.new(path).chown uid, gid Entry_.new(path).chown uid, gid
end end
end end
module_function :chown
OPT_TABLE['chown'] = %w( noop verbose ) OPT_TABLE['chown'] = %w( noop verbose )
@ -903,6 +949,7 @@ module FileUtils
end end
end end
end end
module_function :chown_R
OPT_TABLE['chown_R'] = %w( noop verbose ) OPT_TABLE['chown_R'] = %w( noop verbose )
@ -917,7 +964,7 @@ module FileUtils
else Etc.getpwnam(user).uid else Etc.getpwnam(user).uid
end end
end end
private :fu_get_uid private_module_function :fu_get_uid
def fu_get_gid(group) #:nodoc: def fu_get_gid(group) #:nodoc:
return nil unless group return nil unless group
@ -926,7 +973,7 @@ module FileUtils
else Etc.getgrnam(group).gid else Etc.getgrnam(group).gid
end end
end end
private :fu_get_gid private_module_function :fu_get_gid
rescue LoadError rescue LoadError
# need Win32 support??? # need Win32 support???
@ -934,10 +981,12 @@ module FileUtils
def fu_get_uid(user) #:nodoc: def fu_get_uid(user) #:nodoc:
user # FIXME user # FIXME
end end
private_module_function :fu_get_uid
def fu_get_gid(group) #:nodoc: def fu_get_gid(group) #:nodoc:
group # FIXME group # FIXME
end end
private_module_function :fu_get_gid
end end
# #
@ -965,6 +1014,7 @@ module FileUtils
end end
end end
end end
module_function :touch
OPT_TABLE['touch'] = %w( noop verbose ) OPT_TABLE['touch'] = %w( noop verbose )
@ -1006,6 +1056,7 @@ module FileUtils
end end
include StreamUtils_ include StreamUtils_
extend StreamUtils_
class Entry_ #:nodoc: internal use only class Entry_ #:nodoc: internal use only
include StreamUtils_ include StreamUtils_
@ -1310,18 +1361,20 @@ module FileUtils
end end
end # class Entry_ end # class Entry_
def fu_list(arg) def fu_list(arg) #:nodoc:
[arg].flatten.map {|path| File.path(path) } [arg].flatten.map {|path| File.path(path) }
end end
private_module_function :fu_list
def fu_each_src_dest(src, dest) def fu_each_src_dest(src, dest) #:nodoc:
fu_each_src_dest0(src, dest) do |s, d| fu_each_src_dest0(src, dest) do |s, d|
raise ArgumentError, "same file: #{s} and #{d}" if fu_same?(s, d) raise ArgumentError, "same file: #{s} and #{d}" if fu_same?(s, d)
yield s, d yield s, d
end end
end end
private_module_function :fu_each_src_dest
def fu_each_src_dest0(src, dest) def fu_each_src_dest0(src, dest) #:nodoc:
if src.is_a?(Array) if src.is_a?(Array)
src.each do |s| src.each do |s|
s = File.path(s) s = File.path(s)
@ -1336,8 +1389,9 @@ module FileUtils
end end
end end
end end
private_module_function :fu_each_src_dest0
def fu_same?(a, b) def fu_same?(a, b) #:nodoc:
if fu_have_st_ino? if fu_have_st_ino?
st1 = File.stat(a) st1 = File.stat(a)
st2 = File.stat(b) st2 = File.stat(b)
@ -1348,20 +1402,23 @@ module FileUtils
rescue Errno::ENOENT rescue Errno::ENOENT
return false return false
end end
private_module_function :fu_same?
def fu_have_st_ino? def fu_have_st_ino? #:nodoc:
not fu_windows? not fu_windows?
end end
private_module_function :fu_have_st_ino?
def fu_check_options(options, *optdecl) def fu_check_options(options, *optdecl) #:nodoc:
h = options.dup h = options.dup
optdecl.each do |name| optdecl.each do |name|
h.delete name h.delete name
end end
raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty? raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty?
end end
private_module_function :fu_check_options
def fu_update_option(args, new) def fu_update_option(args, new) #:nodoc:
if args.last.is_a?(Hash) if args.last.is_a?(Hash)
args[-1] = args.last.dup.update(new) args[-1] = args.last.dup.update(new)
else else
@ -1369,18 +1426,17 @@ module FileUtils
end end
args args
end end
private_module_function :fu_update_option
@fileutils_output = $stderr @fileutils_output = $stderr
@fileutils_label = '' @fileutils_label = ''
def fu_output_message(msg) def fu_output_message(msg) #:nodoc:
@fileutils_output ||= $stderr @fileutils_output ||= $stderr
@fileutils_label ||= '' @fileutils_label ||= ''
@fileutils_output.puts @fileutils_label + msg @fileutils_output.puts @fileutils_label + msg
end end
private_module_function :fu_output_message
# All Methods are public instance method and are public class method.
extend self
# #
# Returns an Array of method names which have any options. # Returns an Array of method names which have any options.

View file

@ -76,6 +76,10 @@ class TestFileUtils
include FileUtils include FileUtils
def check_singleton(name)
assert_equal true, ::FileUtils.public_methods.include?(name.to_s)
end
def my_rm_rf(path) def my_rm_rf(path)
if File.exist?('/bin/rm') if File.exist?('/bin/rm')
system %Q[/bin/rm -rf "#{path}"] system %Q[/bin/rm -rf "#{path}"]
@ -164,6 +168,8 @@ class TestFileUtils
# #
def test_pwd def test_pwd
check_singleton :pwd
assert_equal Dir.pwd, pwd() assert_equal Dir.pwd, pwd()
cwd = Dir.pwd cwd = Dir.pwd
@ -181,6 +187,8 @@ end
end end
def test_cmp def test_cmp
check_singleton :cmp
TARGETS.each do |fname| TARGETS.each do |fname|
assert cmp(fname, fname), 'not same?' assert cmp(fname, fname), 'not same?'
end end
@ -198,6 +206,8 @@ end
end end
def test_cp def test_cp
check_singleton :cp
each_srcdest do |srcpath, destpath| each_srcdest do |srcpath, destpath|
cp srcpath, destpath cp srcpath, destpath
assert_same_file srcpath, destpath assert_same_file srcpath, destpath
@ -245,6 +255,8 @@ end
end end
def test_cp_r def test_cp_r
check_singleton :cp_r
cp_r 'data', 'tmp' cp_r 'data', 'tmp'
TARGETS.each do |fname| TARGETS.each do |fname|
assert_same_file fname, "tmp/#{fname}" assert_same_file fname, "tmp/#{fname}"
@ -299,6 +311,8 @@ end
end end
def test_mv def test_mv
check_singleton :mv
mkdir 'tmp/dest' mkdir 'tmp/dest'
TARGETS.each do |fname| TARGETS.each do |fname|
cp fname, 'tmp/mvsrc' cp fname, 'tmp/mvsrc'
@ -356,6 +370,8 @@ end
end end
def test_rm def test_rm
check_singleton :rm
TARGETS.each do |fname| TARGETS.each do |fname|
cp fname, 'tmp/rmsrc' cp fname, 'tmp/rmsrc'
rm 'tmp/rmsrc' rm 'tmp/rmsrc'
@ -376,6 +392,8 @@ end
end end
def test_rm_f def test_rm_f
check_singleton :rm_f
TARGETS.each do |fname| TARGETS.each do |fname|
cp fname, 'tmp/rmsrc' cp fname, 'tmp/rmsrc'
rm_f 'tmp/rmsrc' rm_f 'tmp/rmsrc'
@ -421,6 +439,8 @@ end
end end
def test_rm_r def test_rm_r
check_singleton :rm_r
my_rm_rf 'tmpdatadir' my_rm_rf 'tmpdatadir'
Dir.mkdir 'tmpdatadir' Dir.mkdir 'tmpdatadir'
@ -479,6 +499,64 @@ end
assert_file_not_exist 'tmp/tmpdir3' assert_file_not_exist 'tmp/tmpdir3'
end end
def test_remove_entry_secure
check_singleton :remove_entry_secure
my_rm_rf 'tmpdatadir'
Dir.mkdir 'tmpdatadir'
remove_entry_secure 'tmpdatadir'
assert_file_not_exist 'tmpdatadir'
Dir.mkdir 'tmpdatadir'
remove_entry_secure 'tmpdatadir/'
assert_file_not_exist 'tmpdatadir'
Dir.mkdir 'tmp/tmpdir'
remove_entry_secure 'tmp/tmpdir/'
assert_file_not_exist 'tmp/tmpdir'
assert_file_exist 'tmp'
Dir.mkdir 'tmp/tmpdir'
remove_entry_secure 'tmp/tmpdir'
assert_file_not_exist 'tmp/tmpdir'
assert_file_exist 'tmp'
Dir.mkdir 'tmp/tmpdir'
File.open('tmp/tmpdir/a', 'w') {|f| f.puts 'dummy' }
File.open('tmp/tmpdir/b', 'w') {|f| f.puts 'dummy' }
File.open('tmp/tmpdir/c', 'w') {|f| f.puts 'dummy' }
remove_entry_secure 'tmp/tmpdir'
assert_file_not_exist 'tmp/tmpdir'
assert_file_exist 'tmp'
Dir.mkdir 'tmp/tmpdir'
File.open('tmp/tmpdir/a', 'w') {|f| f.puts 'dummy' }
File.open('tmp/tmpdir/c', 'w') {|f| f.puts 'dummy' }
remove_entry_secure 'tmp/tmpdir/a', true
remove_entry_secure 'tmp/tmpdir/b', true
remove_entry_secure 'tmp/tmpdir/c', true
assert_file_not_exist 'tmp/tmpdir/a'
assert_file_not_exist 'tmp/tmpdir/c'
Dir.rmdir 'tmp/tmpdir'
if have_symlink?
# [ruby-talk:94635] a symlink to the directory
Dir.mkdir 'tmp/tmpdir'
File.symlink '..', 'tmp/tmpdir/symlink_to_dir'
remove_entry_secure 'tmp/tmpdir'
assert_file_not_exist 'tmp/tmpdir'
assert_file_exist 'tmp'
end
# pathname
Dir.mkdir 'tmp/tmpdir1'; touch 'tmp/tmpdir1/tmp'
assert_nothing_raised {
remove_entry_secure Pathname.new('tmp/tmpdir1')
}
assert_file_not_exist 'tmp/tmpdir1'
end
def test_with_big_file def test_with_big_file
prepare_big_file prepare_big_file
@ -545,6 +623,8 @@ end
if have_symlink? if have_symlink?
def test_ln_s def test_ln_s
check_singleton :ln_s
TARGETS.each do |fname| TARGETS.each do |fname|
ln_s fname, 'tmp/lnsdest' ln_s fname, 'tmp/lnsdest'
assert FileTest.symlink?('tmp/lnsdest'), 'not symlink' assert FileTest.symlink?('tmp/lnsdest'), 'not symlink'
@ -568,6 +648,8 @@ end
if have_symlink? if have_symlink?
def test_ln_sf def test_ln_sf
check_singleton :ln_sf
TARGETS.each do |fname| TARGETS.each do |fname|
ln_sf fname, 'tmp/lnsdest' ln_sf fname, 'tmp/lnsdest'
assert FileTest.symlink?('tmp/lnsdest'), 'not symlink' assert FileTest.symlink?('tmp/lnsdest'), 'not symlink'
@ -590,6 +672,8 @@ if have_symlink?
end end
def test_mkdir def test_mkdir
check_singleton :mkdir
my_rm_rf 'tmpdatadir' my_rm_rf 'tmpdatadir'
mkdir 'tmpdatadir' mkdir 'tmpdatadir'
assert_directory 'tmpdatadir' assert_directory 'tmpdatadir'
@ -629,6 +713,8 @@ end
end end
def test_mkdir_p def test_mkdir_p
check_singleton :mkdir_p
dirs = %w( dirs = %w(
tmpdir/dir/ tmpdir/dir/
tmpdir/dir/./ tmpdir/dir/./
@ -692,6 +778,8 @@ end
end end
def test_install def test_install
check_singleton :install
File.open('tmp/aaa', 'w') {|f| f.puts 'aaa' } File.open('tmp/aaa', 'w') {|f| f.puts 'aaa' }
File.open('tmp/bbb', 'w') {|f| f.puts 'bbb' } File.open('tmp/bbb', 'w') {|f| f.puts 'bbb' }
install 'tmp/aaa', 'tmp/bbb', :mode => 0600 install 'tmp/aaa', 'tmp/bbb', :mode => 0600
@ -750,6 +838,8 @@ end
if have_file_perm? if have_file_perm?
def test_chmod def test_chmod
check_singleton :chmod
touch 'tmp/a' touch 'tmp/a'
chmod 0700, 'tmp/a' chmod 0700, 'tmp/a'
assert_equal 0700, File.stat('tmp/a').mode & 0777 assert_equal 0700, File.stat('tmp/a').mode & 0777
@ -758,6 +848,8 @@ if have_file_perm?
end end
def test_chmod_R def test_chmod_R
check_singleton :chmod_R
mkdir_p 'tmp/dir/dir' mkdir_p 'tmp/dir/dir'
touch %w( tmp/dir/file tmp/dir/dir/file ) touch %w( tmp/dir/file tmp/dir/dir/file )
chmod_R 0700, 'tmp/dir' chmod_R 0700, 'tmp/dir'
@ -775,14 +867,18 @@ if have_file_perm?
# FIXME: How can I test this method? # FIXME: How can I test this method?
def test_chown def test_chown
check_singleton :chown
end end
# FIXME: How can I test this method? # FIXME: How can I test this method?
def test_chown_R def test_chown_R
check_singleton :chown_R
end end
end end
def test_copy_entry def test_copy_entry
check_singleton :copy_entry
each_srcdest do |srcpath, destpath| each_srcdest do |srcpath, destpath|
copy_entry srcpath, destpath copy_entry srcpath, destpath
assert_same_file srcpath, destpath assert_same_file srcpath, destpath
@ -807,6 +903,8 @@ end
end end
def test_copy_file def test_copy_file
check_singleton :copy_file
each_srcdest do |srcpath, destpath| each_srcdest do |srcpath, destpath|
copy_file srcpath, destpath copy_file srcpath, destpath
assert_same_file srcpath, destpath assert_same_file srcpath, destpath
@ -814,6 +912,7 @@ end
end end
def test_copy_stream def test_copy_stream
check_singleton :copy_stream
# IO # IO
each_srcdest do |srcpath, destpath| each_srcdest do |srcpath, destpath|
File.open(srcpath) {|src| File.open(srcpath) {|src|
@ -838,6 +937,7 @@ end
end end
def test_remove_file def test_remove_file
check_singleton :remove_file
File.open('data/tmp', 'w') {|f| f.puts 'dummy' } File.open('data/tmp', 'w') {|f| f.puts 'dummy' }
remove_file 'data/tmp' remove_file 'data/tmp'
assert_file_not_exist 'data/tmp' assert_file_not_exist 'data/tmp'
@ -850,6 +950,7 @@ end
end end
def test_remove_dir def test_remove_dir
check_singleton :remove_dir
Dir.mkdir 'data/tmpdir' Dir.mkdir 'data/tmpdir'
File.open('data/tmpdir/a', 'w') {|f| f.puts 'dummy' } File.open('data/tmpdir/a', 'w') {|f| f.puts 'dummy' }
remove_dir 'data/tmpdir' remove_dir 'data/tmpdir'
@ -863,10 +964,12 @@ end
end end
def test_compare_file def test_compare_file
check_singleton :compare_file
# FIXME # FIXME
end end
def test_compare_stream def test_compare_stream
check_singleton :compare_stream
# FIXME # FIXME
end end
@ -885,6 +988,7 @@ end
end end
def test_uptodate? def test_uptodate?
check_singleton :uptodate?
prepare_time_data prepare_time_data
Dir.chdir('data') { Dir.chdir('data') {
assert( uptodate?('newest', %w(old newer notexist)) ) assert( uptodate?('newest', %w(old newer notexist)) )
@ -904,4 +1008,75 @@ end
} }
end end
def test_cd
check_singleton :cd
end
def test_chdir
check_singleton :chdir
end
def test_getwd
check_singleton :getwd
end
def test_identical?
check_singleton :identical?
end
def test_link
check_singleton :link
end
def test_makedirs
check_singleton :makedirs
end
def test_mkpath
check_singleton :mkpath
end
def test_move
check_singleton :move
end
def test_rm_rf
check_singleton :rm_rf
end
def test_rmdir
check_singleton :rmdir
end
def test_rmtree
check_singleton :rmtree
end
def test_safe_unlink
check_singleton :safe_unlink
end
def test_symlink
check_singleton :symlink
end
def test_touch
check_singleton :touch
end
def test_collect_methods
end
def test_commands
end
def test_have_option?
end
def test_options
end
def test_options_of
end
end end