Permalink
Browse files

Fixed issue where Dir glob would not work properly when doing /**/*.

  • Loading branch information...
marano committed Nov 3, 2010
1 parent 4b371c7 commit 76b6bb10ab36423ab5d9ea173c044d1d0b7906ea
Showing with 15 additions and 5 deletions.
  1. +5 −2 lib/fakefs/file_system.rb
  2. +10 −3 test/fakefs_test.rb
@@ -109,11 +109,14 @@ def find_recurser(dir, parts)
matches = case pattern
when '**'
case parts
when ['*'], []
when ['*']
parts = [] # end recursion
directories_under(dir).map do |d|
d.values.select{|f| f.is_a? FakeFile }
d.values.select{|f| f.is_a?(FakeFile) || f.is_a?(FakeDir) }
end.flatten.uniq
when []
parts = [] # end recursion
dir.values.flatten.uniq
else
directories_under(dir)
end
View
@@ -458,6 +458,13 @@ def test_dir_globs_paths
assert_equal ['/path/foo', '/path/foobar'], Dir['/p*h/foo*']
assert_equal ['/path/foo', '/path/foobar'], Dir['/p??h/foo*']
assert_equal ['/path/bar', '/path/bar/baz', '/path/bar2', '/path/bar2/baz', '/path/foo', '/path/foobar'], Dir['/path/**/*']
assert_equal ['/path', '/path/bar', '/path/bar/baz', '/path/bar2', '/path/bar2/baz', '/path/foo', '/path/foobar'], Dir['/**/*']
assert_equal ['/path/bar', '/path/bar/baz', '/path/bar2', '/path/bar2/baz', '/path/foo', '/path/foobar'], Dir['/path/**/*']
assert_equal ['/path/bar/baz'], Dir['/path/bar/**/*']
FileUtils.cp_r '/path', '/otherpath'
assert_equal %w( /otherpath/foo /otherpath/foobar /path/foo /path/foobar ), Dir['/*/foo*']
@@ -478,11 +485,11 @@ def test_dir_glob_handles_recursive_globs
assert_equal ['/one/two/three'], Dir['/one/**/three']
end
def test_dir_recursive_glob_ending_in_wildcards_only_returns_files
def test_dir_recursive_glob_ending_in_wildcards_returns_both_files_and_dirs
File.open('/one/two/three/four.rb', 'w')
File.open('/one/five.rb', 'w')
assert_equal ['/one/five.rb', '/one/two/three/four.rb'], Dir['/one/**/*']
assert_equal ['/one/five.rb', '/one/two/three/four.rb'], Dir['/one/**']
assert_equal ['/one/five.rb', '/one/two', '/one/two/three', '/one/two/three/four.rb'], Dir['/one/**/*']
assert_equal ['/one/five.rb', '/one/two'], Dir['/one/**']
end
def test_should_report_pos_as_0_when_opening

0 comments on commit 76b6bb1

Please sign in to comment.