Finished tests for Class methods. chroot isn't implemented

This commit is contained in:
Myles Eftos 2009-09-13 22:10:42 +08:00
parent af330bc5ab
commit fa3f27e6c3
2 changed files with 118 additions and 12 deletions

View File

@ -65,6 +65,7 @@ module FakeFS
end end
def self.delete(string) def self.delete(string)
raise SystemCallError, "No such file or directory - #{string}" unless FileSystem.find(string).values.empty?
FileSystem.delete(string) FileSystem.delete(string)
end end
@ -82,13 +83,15 @@ module FakeFS
end end
def self.mkdir(string, integer = 0) def self.mkdir(string, integer = 0)
parent = string.split('/')
parent.pop
raise Errno::ENOENT, "No such file or directory - #{string}" unless parent.join == "" || FileSystem.find(parent.join('/'))
FileUtils.mkdir_p(string) FileUtils.mkdir_p(string)
end end
def self.open(string, &block) def self.open(string, &block)
if block_given? if block_given?
d = Dir.new(string).each { |file| yield(file) } Dir.new(string).each { |file| yield(file) }
d.close
else else
Dir.new(string) Dir.new(string)
end end

View File

@ -547,7 +547,7 @@ class FakeFSTest < Test::Unit::TestCase
} }
end end
def test_close def test_directory_close
FileUtils.mkdir_p('/this/path/should/be/here') FileUtils.mkdir_p('/this/path/should/be/here')
dir = Dir.new('/this/path/should/be/here') dir = Dir.new('/this/path/should/be/here')
assert dir.close.nil? assert dir.close.nil?
@ -557,7 +557,7 @@ class FakeFSTest < Test::Unit::TestCase
} }
end end
def test_each def test_directory_each
test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ]
FileUtils.mkdir_p('/this/path/should/be/here') FileUtils.mkdir_p('/this/path/should/be/here')
@ -577,12 +577,12 @@ class FakeFSTest < Test::Unit::TestCase
test.each { |t| assert yielded.include?(t) } test.each { |t| assert yielded.include?(t) }
end end
def test_path def test_directory_path
FileUtils.mkdir_p('/this/path/should/be/here') FileUtils.mkdir_p('/this/path/should/be/here')
assert Dir.new('/this/path/should/be/here').path == '/this/path/should/be/here' assert Dir.new('/this/path/should/be/here').path == '/this/path/should/be/here'
end end
def test_pos def test_directory_pos
test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ]
FileUtils.mkdir_p('/this/path/should/be/here') FileUtils.mkdir_p('/this/path/should/be/here')
test.each do |f| test.each do |f|
@ -604,7 +604,7 @@ class FakeFSTest < Test::Unit::TestCase
assert dir.pos == 5 assert dir.pos == 5
end end
def test_pos_assign def test_directory_pos_assign
test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ]
FileUtils.mkdir_p('/this/path/should/be/here') FileUtils.mkdir_p('/this/path/should/be/here')
test.each do |f| test.each do |f|
@ -618,7 +618,7 @@ class FakeFSTest < Test::Unit::TestCase
assert dir.pos == 2 assert dir.pos == 2
end end
def test_read def test_directory_read
test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ]
FileUtils.mkdir_p('/this/path/should/be/here') FileUtils.mkdir_p('/this/path/should/be/here')
test.each do |f| test.each do |f|
@ -637,7 +637,7 @@ class FakeFSTest < Test::Unit::TestCase
assert d == '..' assert d == '..'
end end
def test_read_past_length def test_directory_read_past_length
test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ]
FileUtils.mkdir_p('/this/path/should/be/here') FileUtils.mkdir_p('/this/path/should/be/here')
test.each do |f| test.each do |f|
@ -664,7 +664,7 @@ class FakeFSTest < Test::Unit::TestCase
assert_nil d assert_nil d
end end
def test_rewind def test_directory_rewind
test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ]
FileUtils.mkdir_p('/this/path/should/be/here') FileUtils.mkdir_p('/this/path/should/be/here')
test.each do |f| test.each do |f|
@ -680,8 +680,8 @@ class FakeFSTest < Test::Unit::TestCase
assert dir.pos == 0 assert dir.pos == 0
end end
def test_seek def test_directory_seek
test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ] test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ]
FileUtils.mkdir_p('/this/path/should/be/here') FileUtils.mkdir_p('/this/path/should/be/here')
test.each do |f| test.each do |f|
FileUtils.touch(f) FileUtils.touch(f)
@ -695,6 +695,109 @@ class FakeFSTest < Test::Unit::TestCase
assert dir.pos == 1 assert dir.pos == 1
end end
def test_directory_class_delete
FileUtils.mkdir_p('/this/path/should/be/here')
Dir.delete('/this/path/should/be/here')
assert File.exists?('/this/path/should/be/here') == false
end
def test_directory_class_delete_does_not_act_on_non_empty_directory
test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ]
FileUtils.mkdir_p('/this/path/should/be/here')
test.each do |f|
FileUtils.touch(f)
end
assert_raises(SystemCallError) do
Dir.delete('/this/path/should/be/here')
end
end
def test_directory_entries
test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ]
FileUtils.mkdir_p('/this/path/should/be/here')
test.each do |f|
FileUtils.touch(f)
end
yielded = Dir.entries('/this/path/should/be/here')
assert yielded.size == test.size
test.each { |t| assert yielded.include?(t) }
end
def test_directory_foreach
test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ]
FileUtils.mkdir_p('/this/path/should/be/here')
test.each do |f|
FileUtils.touch(f)
end
yielded = []
Dir.foreach('/this/path/should/be/here') do |dir|
yielded << dir
end
assert yielded.size == test.size
test.each { |t| assert yielded.include?(t) }
end
def test_directory_mkdir
Dir.mkdir('/path')
assert File.exists?('/path')
end
def test_directory_mkdir_relative
FileUtils.mkdir_p('/new/root')
FileSystem.chdir('/new/root')
Dir.mkdir('path')
assert File.exists?('/new/root/path')
end
def test_directory_mkdir_not_recursive
assert_raises(Errno::ENOENT) do
Dir.mkdir('/path/does/not/exist')
end
end
def test_directory_open
test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ]
FileUtils.mkdir_p('/this/path/should/be/here')
test.each do |f|
FileUtils.touch(f)
end
dir = Dir.open('/this/path/should/be/here')
assert dir.path == '/this/path/should/be/here'
end
def test_directory_open_block
test = ['.', '..', '/this/path/should/be/here/file_1', '/this/path/should/be/here/file_2', '/this/path/should/be/here/file_3', '/this/path/should/be/here/file_4', '/this/path/should/be/here/file_5' ]
FileUtils.mkdir_p('/this/path/should/be/here')
test.each do |f|
FileUtils.touch(f)
end
yielded = []
Dir.open('/this/path/should/be/here') do |dir|
yielded << dir
end
assert yielded.size == test.size
test.each { |t| assert yielded.include?(t) }
end
def test_tmpdir
assert Dir.tmp_dir == "/tmp"
end
def here(fname) def here(fname)
RealFile.expand_path(RealFile.dirname(__FILE__)+'/'+fname) RealFile.expand_path(RealFile.dirname(__FILE__)+'/'+fname)
end end