From 272560359a3ec52a00de51b5c8d01fe72d44348d Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 12 Oct 2006 17:31:15 +0000 Subject: * lib/test/unit/collector/dir.rb (Collector::Dir#collect): prepend base directory to load path. * lib/test/unit/collector/dir.rb (Collector::Dir#collect_file): should use the given File-like interface, but not File directly. * test/testunit/collector/test_dir.rb (TestDir::FileSystem): implement File-like methods correctly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/testunit/collector/test_dir.rb | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'test/testunit/collector') diff --git a/test/testunit/collector/test_dir.rb b/test/testunit/collector/test_dir.rb index 3576333a08..99fb3de112 100644 --- a/test/testunit/collector/test_dir.rb +++ b/test/testunit/collector/test_dir.rb @@ -89,19 +89,19 @@ module Test end def directory?(name) + return true if (base = basename(name)) == '/' e = find(dirname(name)) return false unless(e) - e.directory?(basename(name)) + e.directory?(base) end def find(path) if(/\A\// =~ path) - path = path.sub(/\A\//, '') thing = @root else thing = @pwd end - split(path).each do |e| + path.scan(/[^\/]+/) do |e| break thing = false unless(thing.kind_of?(Directory)) thing = thing[e] end @@ -109,15 +109,19 @@ module Test end def dirname(name) - join(*split(name)[0..-2]) + if (name = name.tr_s('/', '/')) == '/' + name + else + name[%r"\A.+(?=/[^/]+/?\z)|\A/"] || "." + end end def basename(name) - split(name)[-1] + name[%r"(\A/|[^/]+)/*\z", 1] end def split(name) - name.split('/') + [dirname(name), basename(name)] end def join(*parts) @@ -140,6 +144,19 @@ module Test @pwd = e end + def expand_path(path, base = nil) + until /\A\// =~ path + base ||= pwd + path = join(base, path) + base = nil + end + path.gsub!(%r"(?:/\.)+(?=/)", '') + nil while path.sub!(%r"/(?!\.\./)[^/]+/\.\.(?=/)", '') + path.sub!(%r"\A(?:/\.\.)+(?=/)", '') + path.sub!(%r"(?:\A(/)|/)\.\.?\z", '\1') + path + end + def require_directory(path) raise Errno::ENOTDIR, path unless(directory?(path)) end -- cgit v1.2.3