diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-10-01 16:25:37 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-10-01 16:25:37 +0000 |
commit | b23e88cd86828c330bcb69166976ba50f5fc4e70 (patch) | |
tree | 848e71dd50fc1f3535a283e9cba1980e40fbb462 /lib | |
parent | c9710f3bebfa3339811a2b7b4087839060526eaf (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/branches/ruby_1_8@11062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/test/unit/autorunner.rb | 23 | ||||
-rw-r--r-- | lib/test/unit/collector/dir.rb | 18 |
2 files changed, 33 insertions, 8 deletions
diff --git a/lib/test/unit/autorunner.rb b/lib/test/unit/autorunner.rb index d9720daa49..71dbccbced 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 1395cdf4e5..2cee7dde44 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 |