Updated MSpec source to 1c3ee1c8.
[rbx.git] / test / mri / fileutils / test_nowrite.rb
blob091e211d24b57215cbd2654c0215a089045f93cf
1 # $Id: test_nowrite.rb 11708 2007-02-12 23:01:19Z shyouhei $
3 require 'fileutils'
4 require 'fileasserts'
5 require 'tmpdir'
6 require 'test/unit'
8 class TestFileUtilsNoWrite < Test::Unit::TestCase
10   include FileUtils::NoWrite
12   def test_visibility
13     FileUtils::METHODS.each do |m|
14       assert_equal true, FileUtils::NoWrite.respond_to?(m, true),
15                    "FileUtils::NoWrite.#{m} is not defined"
16       assert_equal true, FileUtils::NoWrite.respond_to?(m, false),
17                    "FileUtils::NoWrite.#{m} is not public"
18     end
19     FileUtils::METHODS.each do |m|
20       assert_equal true, respond_to?(m, true),
21                    "FileUtils::NoWrite\##{m} is not defined"
22       assert_equal true, FileUtils::NoWrite.private_method_defined?(m),
23                    "FileUtils::NoWrite\##{m} is not private"
24     end
25   end
27   def my_rm_rf(path)
28     if File.exist?('/bin/rm')
29       system %Q[/bin/rm -rf "#{path}"]
30     else
31       FileUtils.rm_rf path
32     end
33   end
35   SRC  = 'data/src'
36   COPY = 'data/copy'
38   def setup
39     @prevdir = Dir.pwd
40     tmproot = "#{Dir.tmpdir}/fileutils.rb.#{$$}"
41     Dir.mkdir tmproot unless File.directory?(tmproot)
42     Dir.chdir tmproot
43     my_rm_rf 'data'; Dir.mkdir 'data'
44     my_rm_rf 'tmp'; Dir.mkdir 'tmp'
45     File.open(SRC,  'w') {|f| f.puts 'dummy' }
46     File.open(COPY, 'w') {|f| f.puts 'dummy' }
47   end
49   def teardown
50     tmproot = Dir.pwd
51     Dir.chdir @prevdir
52     my_rm_rf tmproot
53   end
55   def test_cp
56     cp SRC, 'tmp/cp'
57     check 'tmp/cp'
58   end
60   def test_mv
61     mv SRC, 'tmp/mv'
62     check 'tmp/mv'
63   end
65   def check(dest)
66     assert_file_not_exist dest
67     assert_file_exist SRC
68     assert_same_file SRC, COPY
69   end
71   def test_rm
72     rm SRC
73     assert_file_exist SRC
74     assert_same_file SRC, COPY
75   end
77   def test_rm_f
78     rm_f SRC
79     assert_file_exist SRC
80     assert_same_file SRC, COPY
81   end
83   def test_rm_rf
84     rm_rf SRC
85     assert_file_exist SRC
86     assert_same_file SRC, COPY
87   end
89   def test_mkdir
90     mkdir 'dir'
91     assert_file_not_exist 'dir'
92   end
94   def test_mkdir_p
95     mkdir 'dir/dir/dir'
96     assert_file_not_exist 'dir'
97   end
99 end