ruby-changes:37062
From: nobu <ko1@a...>
Date: Sun, 4 Jan 2015 22:33:40 +0900 (JST)
Subject: [ruby-changes:37062] nobu:r49143 (trunk): test/unit.rb: ExcludesOption
nobu 2015-01-04 22:33:35 +0900 (Sun, 04 Jan 2015) New Revision: 49143 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49143 Log: test/unit.rb: ExcludesOption * test/lib/test/unit.rb (ExcludesOption): add "excludes" support to test suite, for alternative implementations and platforms. [Feature #10682] Modified files: trunk/ChangeLog trunk/test/lib/test/unit.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 49142) +++ ChangeLog (revision 49143) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Jan 4 22:33:33 2015 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * test/lib/test/unit.rb (Test::Unit): reorder modules and merge Index: test/lib/test/unit.rb =================================================================== --- test/lib/test/unit.rb (revision 49142) +++ test/lib/test/unit.rb (revision 49143) @@ -835,6 +835,59 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L835 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 https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit.rb#L896 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/