diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-07-09 01:20:20 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-07-09 01:20:20 +0000 |
commit | 58f2e6bc942bb161f73adad6410769a6ef581f8e (patch) | |
tree | 08e7127d98a6593b8e3b22b259b4f1ffe4dac67d /test/ruby/test_dir.rb | |
parent | 0528838b377ff3e5161d47df753c3203b028bf57 (diff) | |
download | ruby-58f2e6bc942bb161f73adad6410769a6ef581f8e.tar.gz |
dir.c: fix directory glob
* dir.c (glob_helper): fix directory glob which resulted in lacking
the first byte. adjust the length of basename to be appended as
well as removing the heading path, not the length of the joined
path. [ruby-dev:50588] [Bug #14899]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_dir.rb')
-rw-r--r-- | test/ruby/test_dir.rb | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb index 5323c764f5..9ac56ec09d 100644 --- a/test/ruby/test_dir.rb +++ b/test/ruby/test_dir.rb @@ -11,11 +11,13 @@ class TestDir < Test::Unit::TestCase $VERBOSE = nil @root = File.realpath(Dir.mktmpdir('__test_dir__')) @nodir = File.join(@root, "dummy") + @dirs = [] for i in "a".."z" if i.ord % 2 == 0 FileUtils.touch(File.join(@root, i)) else FileUtils.mkdir(File.join(@root, i)) + @dirs << File.join(i, "") end end end @@ -210,18 +212,38 @@ class TestDir < Test::Unit::TestCase def test_glob_base files = %w[a/foo.c c/bar.c] files.each {|n| File.write(File.join(@root, n), "")} + Dir.mkdir(File.join(@root, "a/dir")) + dirs = @dirs + %w[a/dir/] + dirs.sort! assert_equal(files, Dir.glob("*/*.c", base: @root).sort) assert_equal(files, Dir.chdir(@root) {Dir.glob("*/*.c", base: ".").sort}) assert_equal(%w[foo.c], Dir.chdir(@root) {Dir.glob("*.c", base: "a").sort}) assert_equal(files, Dir.chdir(@root) {Dir.glob("*/*.c", base: "").sort}) assert_equal(files, Dir.chdir(@root) {Dir.glob("*/*.c", base: nil).sort}) + assert_equal(@dirs, Dir.glob("*/", base: @root).sort) + assert_equal(@dirs, Dir.chdir(@root) {Dir.glob("*/", base: ".").sort}) + assert_equal(%w[dir/], Dir.chdir(@root) {Dir.glob("*/", base: "a").sort}) + assert_equal(@dirs, Dir.chdir(@root) {Dir.glob("*/", base: "").sort}) + assert_equal(@dirs, Dir.chdir(@root) {Dir.glob("*/", base: nil).sort}) + assert_equal(dirs, Dir.glob("**/*/", base: @root).sort) + assert_equal(dirs, Dir.chdir(@root) {Dir.glob("**/*/", base: ".").sort}) + assert_equal(%w[dir/], Dir.chdir(@root) {Dir.glob("**/*/", base: "a").sort}) + assert_equal(dirs, Dir.chdir(@root) {Dir.glob("**/*/", base: "").sort}) + assert_equal(dirs, Dir.chdir(@root) {Dir.glob("**/*/", base: nil).sort}) end def test_glob_base_dir files = %w[a/foo.c c/bar.c] files.each {|n| File.write(File.join(@root, n), "")} + Dir.mkdir(File.join(@root, "a/dir")) + dirs = @dirs + %w[a/dir/] + dirs.sort! assert_equal(files, Dir.open(@root) {|d| Dir.glob("*/*.c", base: d)}.sort) - assert_equal(%w[foo.c], Dir.chdir(@root) {Dir.open("a") {|d| Dir.glob("*", base: d)}}) + assert_equal(%w[foo.c], Dir.chdir(@root) {Dir.open("a") {|d| Dir.glob("*.c", base: d)}}) + assert_equal(@dirs, Dir.open(@root) {|d| Dir.glob("*/", base: d).sort}) + assert_equal(%w[dir/], Dir.chdir(@root) {Dir.open("a") {|d| Dir.glob("*/", base: d).sort}}) + assert_equal(dirs, Dir.open(@root) {|d| Dir.glob("**/*/", base: d).sort}) + assert_equal(%w[dir/], Dir.chdir(@root) {Dir.open("a") {|d| Dir.glob("**/*/", base: d).sort}}) end def assert_entries(entries, children_only = false) |