diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | test/lib/test/unit.rb | 54 |
2 files changed, 60 insertions, 0 deletions
@@ -1,3 +1,9 @@ +Sun Jan 4 22:33:33 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * test/lib/test/unit.rb (ExcludesOption): add "excludes" support + to test suite, for alternative implementations and platforms. + [Feature #10682] + Sun Jan 4 22:32:42 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> * test/lib/test/unit.rb (Test::Unit): reorder modules and merge diff --git a/test/lib/test/unit.rb b/test/lib/test/unit.rb index 048fc19332..8f6cecf32a 100644 --- a/test/lib/test/unit.rb +++ b/test/lib/test/unit.rb @@ -835,6 +835,59 @@ module Test end end + module ExcludesOption # :nodoc: all + class ExcludedMethods < Struct.new(:excludes) + def exclude(name, reason) + excludes[name] = reason + end + + def exclude_from(klass) + excludes = self.excludes + klass.class_eval do + public_instance_methods(false).each do |method| + if excludes[method] + remove_method(method) + end + end + public_instance_methods(true).each do |method| + if excludes[method] + undef_method(method) + end + end + end + end + + def self.load(dir, name) + return unless dir and name + path = File.join(dir, name.gsub(/::/, '/') + ".rb") + begin + src = File.read(path) + rescue Errno::ENOENT + nil + else + instance = new({}) + instance.instance_eval(src) + instance + end + end + end + + def setup_options(parser, options) + super + options[:excludes] = ENV["EXCLUDES"] + parser.on '-X', '--excludes-dir DIRECTORY', "Directory name of exclude files" do |d| + options[:excludes] = d + end + end + + def _run_suite(suite, type) + if ex = ExcludedMethods.load(@options[:excludes], suite.name) + ex.exclude_from(suite) + end + super + end + end + class Runner < MiniTest::Unit # :nodoc: all include Test::Unit::Options include Test::Unit::StatusLine @@ -843,6 +896,7 @@ module Test include Test::Unit::GlobOption include Test::Unit::LoadPathOption include Test::Unit::GCStressOption + include Test::Unit::ExcludesOption include Test::Unit::RunCount class << self; undef autorun; end |