summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-12 17:31:15 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-12 17:31:15 +0000
commit11a696870a0d9ad0744110bfcd061ed0b8b6421f (patch)
treeb78490122bf741f44dc82d6342ee96477bc8487b
parent98716977c4e4d84dc4bf066074440b66ea74664f (diff)
* 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/branches/ruby_1_8@11147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog11
-rw-r--r--lib/test/unit/collector/dir.rb6
-rw-r--r--test/testunit/collector/test_dir.rb29
3 files changed, 39 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 764a6252b8..f85583ea61 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Fri Oct 13 02:30:12 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+[] * 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.
+
Fri Oct 13 01:48:42 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/date.rb (Date::self.complete_hash): need to check if g is
diff --git a/lib/test/unit/collector/dir.rb b/lib/test/unit/collector/dir.rb
index dadd9408c7..4e553db4df 100644
--- a/lib/test/unit/collector/dir.rb
+++ b/lib/test/unit/collector/dir.rb
@@ -21,6 +21,8 @@ module Test
end
def collect(*from)
+ basedir = @base
+ $:.unshift(basedir) if basedir
if(from.empty?)
recursive_collect('.', find_test_cases)
elsif(from.size == 1)
@@ -35,6 +37,8 @@ module Test
sort(suites).each{|s| suite << s}
suite
end
+ ensure
+ $:.delete_at($:.rindex(basedir)) if basedir
end
def find_test_cases(ignore=[])
@@ -77,7 +81,7 @@ module Test
end
def collect_file(name, suites, already_gathered)
- dir = File.dirname(name = File.expand_path(name, @base))
+ dir = @file.dirname(@file.expand_path(name, @base))
$:.unshift(dir)
if(@req)
@req.require(name)
diff --git a/test/testunit/collector/test_dir.rb b/test/testunit/collector/test_dir.rb
index e7ae414264..2de802c5e3 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