2005-09-23 19:30:09 -04:00
|
|
|
# $Id$
|
2003-09-17 05:52:50 -04:00
|
|
|
|
|
|
|
require 'fileutils'
|
|
|
|
require 'fileasserts'
|
2003-11-25 04:13:58 -05:00
|
|
|
require 'tmpdir'
|
|
|
|
require 'test/unit'
|
2003-09-17 05:52:50 -04:00
|
|
|
|
2005-09-23 19:30:09 -04:00
|
|
|
class TestFileUtilsNoWrite < Test::Unit::TestCase
|
2003-09-17 05:52:50 -04:00
|
|
|
|
|
|
|
include FileUtils::NoWrite
|
|
|
|
|
2005-09-23 19:30:09 -04:00
|
|
|
def test_visibility
|
|
|
|
FileUtils::METHODS.each do |m|
|
|
|
|
assert_equal true, FileUtils::NoWrite.respond_to?(m, true),
|
|
|
|
"FileUtils::NoWrite.#{m} is not defined"
|
|
|
|
assert_equal true, FileUtils::NoWrite.respond_to?(m, false),
|
|
|
|
"FileUtils::NoWrite.#{m} is not public"
|
|
|
|
end
|
|
|
|
FileUtils::METHODS.each do |m|
|
|
|
|
assert_equal true, respond_to?(m, true),
|
|
|
|
"FileUtils::NoWrite\##{m} is not defined"
|
|
|
|
assert_equal true, FileUtils::NoWrite.private_method_defined?(m),
|
|
|
|
"FileUtils::NoWrite\##{m} is not private"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def my_rm_rf(path)
|
2003-09-26 20:44:50 -04:00
|
|
|
if File.exist?('/bin/rm')
|
2003-11-25 06:02:30 -05:00
|
|
|
system %Q[/bin/rm -rf "#{path}"]
|
2003-09-26 20:44:50 -04:00
|
|
|
else
|
|
|
|
FileUtils.rm_rf path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-09-17 05:52:50 -04:00
|
|
|
SRC = 'data/src'
|
|
|
|
COPY = 'data/copy'
|
|
|
|
|
|
|
|
def setup
|
2003-11-25 04:13:58 -05:00
|
|
|
@prevdir = Dir.pwd
|
2003-11-25 06:02:30 -05:00
|
|
|
tmproot = "#{Dir.tmpdir}/fileutils.rb.#{$$}"
|
|
|
|
Dir.mkdir tmproot unless File.directory?(tmproot)
|
|
|
|
Dir.chdir tmproot
|
|
|
|
my_rm_rf 'data'; Dir.mkdir 'data'
|
2003-09-26 20:44:50 -04:00
|
|
|
my_rm_rf 'tmp'; Dir.mkdir 'tmp'
|
|
|
|
File.open(SRC, 'w') {|f| f.puts 'dummy' }
|
|
|
|
File.open(COPY, 'w') {|f| f.puts 'dummy' }
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2003-11-25 06:02:30 -05:00
|
|
|
tmproot = Dir.pwd
|
2003-11-25 04:13:58 -05:00
|
|
|
Dir.chdir @prevdir
|
2003-11-25 06:02:30 -05:00
|
|
|
my_rm_rf tmproot
|
2003-09-17 05:52:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_cp
|
|
|
|
cp SRC, 'tmp/cp'
|
|
|
|
check 'tmp/cp'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_mv
|
|
|
|
mv SRC, 'tmp/mv'
|
|
|
|
check 'tmp/mv'
|
|
|
|
end
|
|
|
|
|
2005-09-23 19:30:09 -04:00
|
|
|
def check(dest)
|
2003-09-17 05:52:50 -04:00
|
|
|
assert_file_not_exist dest
|
|
|
|
assert_file_exist SRC
|
|
|
|
assert_same_file SRC, COPY
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rm
|
|
|
|
rm SRC
|
|
|
|
assert_file_exist SRC
|
|
|
|
assert_same_file SRC, COPY
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rm_f
|
|
|
|
rm_f SRC
|
|
|
|
assert_file_exist SRC
|
|
|
|
assert_same_file SRC, COPY
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rm_rf
|
|
|
|
rm_rf SRC
|
|
|
|
assert_file_exist SRC
|
|
|
|
assert_same_file SRC, COPY
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_mkdir
|
|
|
|
mkdir 'dir'
|
|
|
|
assert_file_not_exist 'dir'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_mkdir_p
|
|
|
|
mkdir 'dir/dir/dir'
|
|
|
|
assert_file_not_exist 'dir'
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|