summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-01 16:25:37 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-01 16:25:37 +0000
commit5cfcbb2aca708d96d3c46e22392eef45774a535c (patch)
treecfb2267e019c1053ee35128a01bacb8b19102680
parent536cbbb20034d19c70c710f2fb5cde8968fc7fe7 (diff)
* common.mk (test-all): separate directory where running test cases
from source tree. * lib/test/unit/autorunner.rb (options): added --basedir, --workdir and --load-path options. * lib/test/unit/collector/dir.rb (recursive_collect, collect_file): base directory support. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog11
-rw-r--r--common.mk5
-rw-r--r--lib/test/unit/autorunner.rb23
-rw-r--r--lib/test/unit/collector/dir.rb18
4 files changed, 48 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 801a7d4f107..9680bf58a50 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Mon Oct 2 01:24:26 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * common.mk (test-all): separate directory where running test cases
+ from source tree.
+
+ * lib/test/unit/autorunner.rb (options): added --basedir, --workdir
+ and --load-path options.
+
+ * lib/test/unit/collector/dir.rb (recursive_collect, collect_file):
+ base directory support.
+
Sun Oct 1 23:56:52 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* Makefile.in, common.mk, ext/extmk.rb, win{32,ce}/Makefile.in: keep
diff --git a/common.mk b/common.mk
index c837940aa41..673d0a95a5c 100644
--- a/common.mk
+++ b/common.mk
@@ -74,6 +74,9 @@ INSTRUBY_ARGS = $(SCRIPT_ARGS) --installed-list $(INSTALLED_LIST)
PRE_LIBRUBY_UPDATE = $(MINIRUBY) -e 'ARGV[1] or File.unlink(ARGV[0]) rescue nil' -- \
$(LIBRUBY_EXTS) $(LIBRUBY_SO_UPDATE)
+TESTSDIR = $(srcdir)/test
+TESTWORKDIR = testwork
+
all: $(MKFILES) $(PREP) $(RBCONFIG) $(LIBRUBY)
@$(MINIRUBY) $(srcdir)/ext/extmk.rb $(EXTMK_ARGS)
prog: $(PROGRAM) $(WPROGRAM)
@@ -278,7 +281,7 @@ test: miniruby$(EXEEXT) $(RBCONFIG) $(PROGRAM) PHONY
@$(MINIRUBY) $(srcdir)/rubytest.rb
test-all:
- $(RUNRUBY) -C "$(srcdir)/test" runner.rb --runner=$(TESTUI) $(TESTS)
+ $(RUNRUBY) "$(srcdir)/test/runner.rb" --basedir="$(TESTSDIR)" --runner=$(TESTUI) $(TESTS)
extconf:
$(MINIRUBY) -I$(srcdir)/lib -run -e mkdir -- -p "$(EXTCONFDIR)"
diff --git a/lib/test/unit/autorunner.rb b/lib/test/unit/autorunner.rb
index d9720daa498..71dbccbced2 100644
--- a/lib/test/unit/autorunner.rb
+++ b/lib/test/unit/autorunner.rb
@@ -7,9 +7,8 @@ module Test
class AutoRunner
def self.run(force_standalone=false, default_dir=nil, argv=ARGV, &block)
r = new(force_standalone || standalone?, &block)
- if((!r.process_args(argv)) && default_dir)
- r.to_run << default_dir
- end
+ r.base = default_dir
+ r.process_args(argv)
r.run
end
@@ -64,12 +63,14 @@ module Test
c.filter = r.filters
c.pattern.concat(r.pattern) if(r.pattern)
c.exclude.concat(r.exclude) if(r.exclude)
+ c.base = r.base
+ $:.unshift(r.base) if r.base
c.collect(*(r.to_run.empty? ? ['.'] : r.to_run))
end,
}
attr_reader :suite
- attr_accessor :output_level, :filters, :to_run, :pattern, :exclude
+ attr_accessor :output_level, :filters, :to_run, :pattern, :exclude, :base, :workdir
attr_writer :runner, :collector
def initialize(standalone)
@@ -110,6 +111,14 @@ module Test
end
if(@standalone)
+ o.on('-b', '--basedir=DIR', "Base directory of test suits.") do |b|
+ @base = b
+ end
+
+ o.on('-w', '--workdir=DIR', "Working directory to run tests.") do |w|
+ @workdir = w
+ end
+
o.on('-a', '--add=TORUN', Array,
"Add TORUN to the list of things to run;",
"can be a file or a directory.") do |a|
@@ -153,6 +162,11 @@ module Test
end
end
+ o.on('-I', "--load-path=DIR[#{File::PATH_SEPARATOR}DIR...]",
+ "Appends directory list to $LOAD_PATH.") do |dirs|
+ $LOAD_PATH.concat(dirs.split(File::PATH_SEPARATOR))
+ end
+
o.on('-v', '--verbose=[LEVEL]', OUTPUT_LEVELS,
"Set the output level (default is verbose).",
"(" + keyword_display(OUTPUT_LEVELS) + ")") do |l|
@@ -197,6 +211,7 @@ module Test
def run
@suite = @collector[self]
result = @runner[self] or return false
+ Dir.chdir(@workdir) if @workdir
result.run(@suite, @output_level).passed?
end
end
diff --git a/lib/test/unit/collector/dir.rb b/lib/test/unit/collector/dir.rb
index 1395cdf4e56..2cee7dde44c 100644
--- a/lib/test/unit/collector/dir.rb
+++ b/lib/test/unit/collector/dir.rb
@@ -8,6 +8,7 @@ module Test
include Collector
attr_reader :pattern, :exclude
+ attr_accessor :base
def initialize(dir=::Dir, file=::File, object_space=::ObjectSpace, req=nil)
super()
@@ -47,11 +48,12 @@ module Test
def recursive_collect(name, already_gathered)
sub_suites = []
- if(@file.directory?(name))
- @dir.entries(name).each do |e|
+ path = realdir(name)
+ if @file.directory?(path)
+ @dir.entries(path).each do |e|
next if(e == '.' || e == '..')
e_name = @file.join(name, e)
- if(@file.directory?(e_name))
+ if @file.directory?(realdir(e_name))
next if /\ACVS\z/ =~ e
sub_suite = recursive_collect(e_name, already_gathered)
sub_suites << sub_suite unless(sub_suite.empty?)
@@ -75,7 +77,7 @@ module Test
end
def collect_file(name, suites, already_gathered)
- dir = File.dirname(File.expand_path(name))
+ dir = File.dirname(File.expand_path(name, @base))
$:.unshift(dir)
if(@req)
@req.require(name)
@@ -86,6 +88,14 @@ module Test
ensure
$:.delete_at($:.rindex(dir)) if(dir)
end
+
+ def realdir(path)
+ if @base
+ @file.join(@base, path)
+ else
+ path
+ end
+ end
end
end
end