From 1b7efc132acb0c28ead3784f88089462ffa86691 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 4 Jan 2015 13:33:35 +0000 Subject: test/unit.rb: ExcludesOption * test/lib/test/unit.rb (ExcludesOption): add "excludes" support to test suite, for alternative implementations and platforms. [Feature #10682] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/lib/test/unit.rb | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'test') 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 -- cgit v1.2.3