Skip to content

Commit

Permalink
Fixed issue where Dir glob would not work properly when doing /**/*.
Browse files Browse the repository at this point in the history
  • Loading branch information
marano committed Nov 4, 2010
1 parent aa0cb96 commit b497343
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/fakefs/file_system.rb
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions test/fakefs_test.rb
Expand Up @@ -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*']
Expand All @@ -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
Expand Down

0 comments on commit b497343

Please sign in to comment.