Hello community, here is the log from the commit of package rubygem-test-unit for openSUSE:Factory checked in at 2016-04-28 16:53:09 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-test-unit (Old) and /work/SRC/openSUSE:Factory/.rubygem-test-unit.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-test-unit" Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-test-unit/rubygem-test-unit.changes 2015-10-14 16:44:57.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.rubygem-test-unit.new/rubygem-test-unit.changes 2016-04-28 16:56:23.000000000 +0200 @@ -1,0 +2,75 @@ +Sun Mar 20 05:32:38 UTC 2016 - co...@suse.com + +- updated to version 3.1.8 + see installed news.md + + ## 3.1.8 - 2016-03-19 {#version-3-1-8} + + ### Improvements + + * Added `--stop-on-failure` command line option. With this option, + running test suite is stopped immediately when one test is failed + or an error is raised in one test. + +------------------------------------------------------------------- +Mon Jan 18 06:04:03 UTC 2016 - co...@suse.com + +- updated to version 3.1.7 + see installed news.md + + ## 3.1.7 - 2016-01-17 {#version-3-1-7} + + ### Fixes + + * Added a missing require. + + ## 3.1.6 - 2016-01-17 {#version-3-1-6} + + It's a Ruby on Rails integration improvement release. + + ### Improvements + + * Filtered backtrace of power\_assert. + [GitHub#114] + * Improved performance to retrieve test defined location. + * Improved performance to run fixtures in a test. + * Supported running a test by `yield` in `setup`: + + Before: + + def setup + @file = File.open("x") + end + + def teardown + @file.close + end + + After: + + def setup + File.open("x") do |file| + @file = file + yield + end + end + + * Added `--default-test-path` option that specifies the default path + that has tests. + * Made auto runner registration more lazily. Auto runner isn't + registered automatically until user defines a test. In the + previous releases, auto runner is registered automatically when + user defines a test case. + * Supported specifying a test by location in command line. For + example, the following command line runs a test that is defined in + /tmp/test_a.rb at line 10: + + % ruby -r test-unit -e run_test /tmp/test_a.rb:10 + + ### Fixes + + * Fixed a bug that test isn't ran. The test has the same name as + data driven test that is defined in parent test case. + [GitHub#115] + +------------------------------------------------------------------- Old: ---- test-unit-3.1.5.gem New: ---- test-unit-3.1.8.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-test-unit.spec ++++++ --- /var/tmp/diff_new_pack.CdN6lm/_old 2016-04-28 16:56:24.000000000 +0200 +++ /var/tmp/diff_new_pack.CdN6lm/_new 2016-04-28 16:56:24.000000000 +0200 @@ -1,7 +1,7 @@ # # spec file for package rubygem-test-unit # -# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -24,7 +24,7 @@ # Name: rubygem-test-unit -Version: 3.1.5 +Version: 3.1.8 Release: 0 %define mod_name test-unit %define mod_full_name %{mod_name}-%{version} ++++++ test-unit-3.1.5.gem -> test-unit-3.1.8.gem ++++++ Files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/doc/text/news.md new/doc/text/news.md --- old/doc/text/news.md 2015-10-09 16:35:53.000000000 +0200 +++ new/doc/text/news.md 2016-03-19 15:20:52.000000000 +0100 @@ -1,5 +1,68 @@ # News +## 3.1.8 - 2016-03-19 {#version-3-1-8} + +### Improvements + + * Added `--stop-on-failure` command line option. With this option, + running test suite is stopped immediately when one test is failed + or an error is raised in one test. + +## 3.1.7 - 2016-01-17 {#version-3-1-7} + +### Fixes + + * Added a missing require. + +## 3.1.6 - 2016-01-17 {#version-3-1-6} + +It's a Ruby on Rails integration improvement release. + +### Improvements + + * Filtered backtrace of power\_assert. + [GitHub#114] + * Improved performance to retrieve test defined location. + * Improved performance to run fixtures in a test. + * Supported running a test by `yield` in `setup`: + + Before: + + def setup + @file = File.open("x") + end + + def teardown + @file.close + end + + After: + + def setup + File.open("x") do |file| + @file = file + yield + end + end + + * Added `--default-test-path` option that specifies the default path + that has tests. + * Made auto runner registration more lazily. Auto runner isn't + registered automatically until user defines a test. In the + previous releases, auto runner is registered automatically when + user defines a test case. + * Supported specifying a test by location in command line. For + example, the following command line runs a test that is defined in + /tmp/test_a.rb at line 10: + + % ruby -r test-unit -e run_test /tmp/test_a.rb:10 + +### Fixes + + * Fixed a bug that test isn't ran. The test has the same name as + data driven test that is defined in parent test case. + [GitHub#115] + ## 3.1.5 - 2015-10-09 {#version-3-1-5} It's a Rack integration improvement release. @@ -7,8 +70,8 @@ ### Improvements * Renamed experimental top-level `run` method to `run_test` method - because `run` is conflicted with Rack. - [GitHub#32][GitHub:basecamp/pow#303] [Reported by Yevhen Viktorov] + because `run` is conflicted with Rack. + [GitHub#32][GitHub:basecamp/pow#303] [Reported by Yevhen Viktorov] ### Thanks diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/test/unit/assertions.rb new/lib/test/unit/assertions.rb --- old/lib/test/unit/assertions.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/lib/test/unit/assertions.rb 2016-03-19 15:20:52.000000000 +0100 @@ -635,7 +635,6 @@ raise end end - nil end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/test/unit/attribute.rb new/lib/test/unit/attribute.rb --- old/lib/test/unit/attribute.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/lib/test/unit/attribute.rb 2016-03-19 15:20:52.000000000 +0100 @@ -111,7 +111,10 @@ attributes || StringifyKeyHash.new end - def find_attribute(method_name, name) + def find_attribute(method_name, name, options={}) + recursive_p = options[:recursive] + recursive_p = true if recursive_p.nil? + @attributes_table ||= StringifyKeyHash.new if @attributes_table.key?(method_name) attributes = @attributes_table[method_name] @@ -120,6 +123,7 @@ end end + return nil unless recursive_p return nil if self == TestCase @cached_parent_test_case ||= ancestors.find do |ancestor| @@ -128,7 +132,7 @@ ancestor < Test::Unit::Attribute end - @cached_parent_test_case.find_attribute(method_name, name) + @cached_parent_test_case.find_attribute(method_name, name, options) end @@attribute_observers = StringifyKeyHash.new diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/test/unit/auto-runner-loader.rb new/lib/test/unit/auto-runner-loader.rb --- old/lib/test/unit/auto-runner-loader.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/test/unit/auto-runner-loader.rb 2016-03-19 15:20:52.000000000 +0100 @@ -0,0 +1,17 @@ +require "test/unit/test-suite-creator" + +module Test + module Unit + module AutoRunnerLoader + @loaded = false + class << self + def check(test_case, method_name) + return if @loaded + return unless TestSuiteCreator.test_method?(test_case, method_name) + require "test/unit" + @loaded = true + end + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/test/unit/autorunner.rb new/lib/test/unit/autorunner.rb --- old/lib/test/unit/autorunner.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/lib/test/unit/autorunner.rb 2016-03-19 15:20:52.000000000 +0100 @@ -1,7 +1,10 @@ -require 'test/unit/color-scheme' -require 'test/unit/priority' -require 'test/unit/attribute-matcher' -require 'optparse' +require "English" + +require "test/unit/color-scheme" +require "test/unit/priority" +require "test/unit/attribute-matcher" +require "test/unit/testcase" +require "optparse" module Test module Unit @@ -78,14 +81,14 @@ end register_collector(:descendant) do |auto_runner| - require 'test/unit/collector/descendant' + require "test/unit/collector/descendant" collector = Collector::Descendant.new collector.filter = auto_runner.filters - collector.collect($0.sub(/\.rb\Z/, '')) + collector.collect($0.sub(/\.rb\Z/, "")) end register_collector(:load) do |auto_runner| - require 'test/unit/collector/load' + require "test/unit/collector/load" collector = Collector::Load.new unless auto_runner.pattern.empty? collector.patterns.replace(auto_runner.pattern) @@ -94,13 +97,14 @@ collector.excludes.replace(auto_runner.exclude) end collector.base = auto_runner.base + collector.default_test_paths = auto_runner.default_test_paths collector.filter = auto_runner.filters collector.collect(*auto_runner.to_run) end # JUST TEST! # register_collector(:xml) do |auto_runner| - # require 'test/unit/collector/xml' + # require "test/unit/collector/xml" # collector = Collector::XML.new # collector.filter = auto_runner.filters # collector.collect(auto_runner.to_run[0]) @@ -108,15 +112,15 @@ # deprecated register_collector(:object_space) do |auto_runner| - require 'test/unit/collector/objectspace' + require "test/unit/collector/objectspace" c = Collector::ObjectSpace.new c.filter = auto_runner.filters - c.collect($0.sub(/\.rb\Z/, '')) + c.collect($0.sub(/\.rb\Z/, "")) end # deprecated register_collector(:dir) do |auto_runner| - require 'test/unit/collector/dir' + require "test/unit/collector/dir" c = Collector::Dir.new c.filter = auto_runner.filters unless auto_runner.pattern.empty? @@ -127,12 +131,15 @@ end c.base = auto_runner.base $:.push(auto_runner.base) if auto_runner.base - c.collect(*(auto_runner.to_run.empty? ? ['.'] : auto_runner.to_run)) + c.collect(*(auto_runner.to_run.empty? ? ["."] : auto_runner.to_run)) end attr_reader :suite, :runner_options - attr_accessor :filters, :to_run, :pattern, :exclude, :base, :workdir + attr_accessor :filters, :to_run + attr_accessor :default_test_paths + attr_accessor :pattern, :exclude, :base, :workdir attr_accessor :color_scheme, :listeners + attr_writer :stop_on_failuere attr_writer :runner, :collector def initialize(standalone) @@ -141,11 +148,13 @@ @collector = default_collector @filters = [] @to_run = [] + @default_test_paths = [] @color_scheme = ColorScheme.default @runner_options = {} @default_arguments = [] @workdir = nil @listeners = [] + @stop_on_failure = false config_file = "test-unit.yml" if File.exist?(config_file) load_config(config_file) @@ -155,6 +164,10 @@ yield(self) if block_given? end + def stop_on_failure? + @stop_on_failure + end + def prepare PREPARE_HOOKS.each do |handler| handler.call(self) @@ -164,7 +177,7 @@ def process_args(args=ARGV) begin args.unshift(*@default_arguments) - options.order!(args) {|arg| @to_run << arg} + options.order!(args) {|arg| add_test_path(arg)} rescue OptionParser::ParseError => e puts e puts options @@ -178,47 +191,56 @@ o.banner = "Test::Unit automatic runner." o.banner << "\nUsage: #{$0} [options] [-- untouched arguments]" - o.on('-r', '--runner=RUNNER', RUNNERS, + o.on("-r", "--runner=RUNNER", RUNNERS, "Use the given RUNNER.", "(" + keyword_display(RUNNERS) + ")") do |r| @runner = r end - o.on('--collector=COLLECTOR', COLLECTORS, + o.on("--collector=COLLECTOR", COLLECTORS, "Use the given COLLECTOR.", "(" + keyword_display(COLLECTORS) + ")") do |collector| @collector = collector end if (@standalone) - o.on('-b', '--basedir=DIR', "Base directory of test suites.") do |b| + o.on("-b", "--basedir=DIR", "Base directory of test suites.") do |b| @base = b end - o.on('-w', '--workdir=DIR', "Working directory to run tests.") do |w| + o.on("-w", "--workdir=DIR", "Working directory to run tests.") do |w| @workdir = w end - o.on('-a', '--add=TORUN', Array, + o.on("--default-test-path=PATH", + "Add PATH to the default test paths.", + "The PATH is used when user doesn't specify any test path.", + "You can specify this option multiple times.") do |path| + @default_test_paths << path + 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| - @to_run.concat(a) + "can be a file or a directory.") do |paths| + paths.each do |path| + add_test_path(path) + end end @pattern = [] - o.on('-p', '--pattern=PATTERN', Regexp, + o.on("-p", "--pattern=PATTERN", Regexp, "Match files to collect against PATTERN.") do |e| @pattern << e end @exclude = [] - o.on('-x', '--exclude=PATTERN', Regexp, + o.on("-x", "--exclude=PATTERN", Regexp, "Ignore files to collect against PATTERN.") do |e| @exclude << e end end - o.on('-n', '--name=NAME', String, + o.on("-n", "--name=NAME", String, "Runs tests matching NAME.", "Use '/PATTERN/' for NAME to use regular expression.") do |name| name = (%r{\A/(.*)/\Z} =~ name ? Regexp.new($1) : name) @@ -232,7 +254,7 @@ end end - o.on('--ignore-name=NAME', String, + o.on("--ignore-name=NAME", String, "Ignores tests matching NAME.", "Use '/PATTERN/' for NAME to use regular expression.") do |n| n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) @@ -244,7 +266,7 @@ end end - o.on('-t', '--testcase=TESTCASE', String, + o.on("-t", "--testcase=TESTCASE", String, "Runs tests in TestCases matching TESTCASE.", "Use '/PATTERN/' for TESTCASE to use regular expression.") do |n| n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) @@ -253,7 +275,7 @@ end end - o.on('--ignore-testcase=TESTCASE', String, + o.on("--ignore-testcase=TESTCASE", String, "Ignores tests in TestCases matching TESTCASE.", "Use '/PATTERN/' for TESTCASE to use regular expression.") do |n| n = (%r{\A/(.*)/\Z} =~ n ? Regexp.new($1) : n) @@ -262,7 +284,7 @@ end end - o.on('--location=LOCATION', String, + o.on("--location=LOCATION", String, "Runs tests that defined in LOCATION.", "LOCATION is one of PATH:LINE, PATH or LINE") do |location| if /\A\d+\z/ =~ location @@ -272,14 +294,10 @@ path, line, = location.split(/:(\d+)/, 2) line = line.to_i unless line.nil? end - @filters << lambda do |test| - test.class.test_defined?(:path => path, - :line => line, - :method_name => test.method_name) - end + add_location_filter(path, line) end - o.on('--attribute=EXPRESSION', String, + o.on("--attribute=EXPRESSION", String, "Runs tests that matches EXPRESSION.", "EXPRESSION is evaluated as Ruby's expression.", "Test attribute name can be used with no receiver in EXPRESSION.", @@ -317,7 +335,7 @@ Priority.default = priority end - o.on('-I', "--load-path=DIR[#{File::PATH_SEPARATOR}DIR...]", + 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 @@ -349,27 +367,33 @@ assertion_message_class.max_diff_target_string_size = size end + o.on("--[no-]stop-on-failure", + "Stops immediately on the first non success test", + "(#{@stop_on_failure})") do |boolean| + @stop_on_failure = boolean + end + ADDITIONAL_OPTIONS.each do |option_builder| option_builder.call(self, o) end - o.on('--', + o.on("--", "Stop processing options so that the", "remaining options will be passed to the", "test."){o.terminate} - o.on('-h', '--help', 'Display this help.'){puts o; exit} + o.on("-h", "--help", "Display this help."){puts o; exit} o.on_tail - o.on_tail('Deprecated options:') + o.on_tail("Deprecated options:") - o.on_tail('--console', 'Console runner (use --runner).') do + o.on_tail("--console", "Console runner (use --runner).") do warn("Deprecated option (--console).") @runner = self.class.runner(:console) end if RUNNERS[:fox] - o.on_tail('--fox', 'Fox runner (use --runner).') do + o.on_tail("--fox", "Fox runner (use --runner).") do warn("Deprecated option (--fox).") @runner = self.class.runner(:fox) end @@ -407,13 +431,16 @@ @runner_options[:color_scheme] ||= @color_scheme @runner_options[:listeners] ||= [] @runner_options[:listeners].concat(@listeners) + if @stop_on_failure + @runner_options[:listeners] << StopOnFailureListener.new + end change_work_directory do runner.run(suite, @runner_options).passed? end end def load_config(file) - require 'yaml' + require "yaml" config = YAML.load(File.read(file)) runner_name = config["runner"] @runner = self.class.runner(runner_name) || @runner @@ -475,10 +502,35 @@ end false end + + def add_test_path(path) + if /:(\d+)\z/ =~ path + line = $1.to_i + path = $PREMATCH + add_location_filter(path, line) + end + @to_run << path + end + + def add_location_filter(path, line) + @filters << lambda do |test| + test.class.test_defined?(:path => path, + :line => line, + :method_name => test.method_name) + end + end + + class StopOnFailureListener + def attach_to_mediator(mediator) + mediator.add_listener(TestResult::FINISHED) do |result| + result.stop unless result.passed? + end + end + end end end end -require 'test/unit/runner/console' -require 'test/unit/runner/emacs' -require 'test/unit/runner/xml' +require "test/unit/runner/console" +require "test/unit/runner/emacs" +require "test/unit/runner/xml" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/test/unit/collector/load.rb new/lib/test/unit/collector/load.rb --- old/lib/test/unit/collector/load.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/lib/test/unit/collector/load.rb 2016-03-19 15:20:52.000000000 +0100 @@ -10,6 +10,7 @@ include Collector attr_reader :patterns, :excludes, :base + attr_reader :default_test_paths def initialize super @@ -18,6 +19,7 @@ @patterns = [/\Atest[_\-].+\.rb\z/m, /[_\-]test\.rb\z/] @excludes = [] @base = nil + @default_test_paths = [] @require_failed_infos = [] end @@ -26,8 +28,15 @@ @base = base end + def default_test_paths=(paths) + @default_test_paths = paths.collect do |path| + Pathname(path) + end + end + def collect(*froms) add_load_path(@base) do + froms = @default_test_paths if froms.empty? froms = ["."] if froms.empty? test_suites = [] already_gathered = find_test_cases diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/test/unit/fixture.rb new/lib/test/unit/fixture.rb --- old/lib/test/unit/fixture.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/lib/test/unit/fixture.rb 2016-03-19 15:20:52.000000000 +0100 @@ -24,9 +24,11 @@ attr_reader :teardown def initialize(test_case) @test_case = test_case - @setup = HookPoint.new(:after => :append) - @cleanup = HookPoint.new(:before => :prepend) - @teardown = HookPoint.new(:before => :prepend) + @setup = HookPoint.new(@test_case, :setup, :after => :append) + @cleanup = HookPoint.new(@test_case, :cleanup, :before => :prepend) + @teardown = HookPoint.new(@test_case, :teardown, :before => :prepend) + @cached_before_callbacks = {} + @cached_after_callbacks = {} end def [](type) @@ -41,6 +43,19 @@ end def before_callbacks(type) + @cached_before_callbacks[type] ||= collect_before_callbacks(type) + end + + def after_callbacks(type) + @cached_after_callbacks[type] ||= collect_after_callbacks(type) + end + + private + def target_test_cases + @cached_target_test_cases ||= collect_target_test_cases + end + + def collect_before_callbacks(type) prepend_callbacks = [] append_callbacks = [] target_test_cases.each do |ancestor| @@ -51,7 +66,7 @@ merge_callbacks(prepend_callbacks, append_callbacks) end - def after_callbacks(type) + def collect_after_callbacks(type) prepend_callbacks = [] append_callbacks = [] target_test_cases.each do |ancestor| @@ -62,11 +77,6 @@ merge_callbacks(prepend_callbacks, append_callbacks) end - private - def target_test_cases - @cached_target_test_cases ||= collect_target_test_cases - end - def collect_target_test_cases ancestors = @test_case.ancestors base_index = ancestors.index(::Test::Unit::Fixture) @@ -89,7 +99,9 @@ end class HookPoint - def initialize(default_options) + def initialize(test_case, type, default_options) + @test_case = test_case + @type = type @default_options = default_options @before_prepend_callbacks = [] @before_append_callbacks = [] @@ -112,11 +124,24 @@ end before_how = options[:before] after_how = options[:after] - add_callback(method_name_or_callback, before_how, after_how) + if method_name_or_callback.respond_to?(:call) + callback = method_name_or_callback + method_name = callback_method_name(callback) + @test_case.__send__(:define_method, method_name, &callback) + else + method_name = method_name_or_callback + end + add_callback(method_name, before_how, after_how) end def unregister(method_name_or_callback) - @unregistered_callbacks << method_name_or_callback + if method_name_or_callback.respond_to?(:call) + callback = method_name_or_callback + method_name = callback_method_name(callback) + else + method_name = method_name_or_callback + end + @unregistered_callbacks << method_name end def before_prepend_callbacks @@ -145,6 +170,10 @@ [:prepend, :append].include?(options[key]) end + def callback_method_name(callback) + "#{@type}_#{callback.object_id}" + end + def add_callback(method_name_or_callback, before_how, after_how) case before_how when :prepend @@ -208,38 +237,50 @@ end private - def run_fixture(type, options={}) - [ + def run_fixture(type, options={}, &block) + fixtures = [ self.class.fixture.before_callbacks(type), type, self.class.fixture.after_callbacks(type), - ].flatten.each do |method_name_or_callback| - run_fixture_callback(method_name_or_callback, options) + ].flatten + if block + runner = create_fixtures_runner(fixtures, options, &block) + runner.call + else + fixtures.each do |method_name| + run_fixture_callback(method_name, options) + end end end - def run_fixture_callback(method_name_or_callback, options) - if method_name_or_callback.respond_to?(:call) - callback = lambda do - instance_eval(&method_name_or_callback) - end + def create_fixtures_runner(fixtures, options, &block) + if fixtures.empty? + block else - return unless respond_to?(method_name_or_callback, true) - callback = lambda do - __send__(method_name_or_callback) + last_fixture = fixtures.pop + create_fixtures_runner(fixtures, options) do + block_is_called = false + run_fixture_callback(last_fixture, options) do + block_is_called = true + block.call + end + block.call unless block_is_called end end + end + def run_fixture_callback(method_name, options, &block) + return unless respond_to?(method_name, true) begin - callback.call + __send__(method_name, &block) rescue Exception raise unless options[:handle_exception] raise unless handle_exception($!) end end - def run_setup - run_fixture(:setup) + def run_setup(&block) + run_fixture(:setup, &block) end def run_cleanup diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/test/unit/test-suite-creator.rb new/lib/test/unit/test-suite-creator.rb --- old/lib/test/unit/test-suite-creator.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/lib/test/unit/test-suite-creator.rb 2016-03-19 15:20:52.000000000 +0100 @@ -8,6 +8,13 @@ module Test module Unit class TestSuiteCreator # :nodoc: + class << self + def test_method?(test_case, method_name) + /\Atest./ =~ method_name.to_s or + test_case.find_attribute(method_name, :test) + end + end + def initialize(test_case) @test_case = test_case end @@ -15,7 +22,8 @@ def create suite = TestSuite.new(@test_case.name, @test_case) collect_test_names.each do |test_name| - data_sets = @test_case.find_attribute(test_name, :data) + data_sets = @test_case.find_attribute(test_name, :data, + :recursive => false) if data_sets data_sets.each do |data_set| data_set = data_set.call if data_set.respond_to?(:call) @@ -47,8 +55,7 @@ methods |= @test_case.public_instance_methods(false) method_names = methods.collect(&:to_s) test_names = method_names.find_all do |method_name| - /\Atest./ =~ method_name or - @test_case.find_attribute(method_name, :test) + self.class.test_method?(@test_case, method_name) end __send__("sort_test_names_in_#{@test_case.test_order}_order", test_names) end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/test/unit/testcase.rb new/lib/test/unit/testcase.rb --- old/lib/test/unit/testcase.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/lib/test/unit/testcase.rb 2016-03-19 15:20:52.000000000 +0100 @@ -20,6 +20,7 @@ require 'test/unit/testsuite' require 'test/unit/test-suite-creator' require 'test/unit/assertion-failed-error' +require 'test/unit/auto-runner-loader' require 'test/unit/util/backtracefilter' require 'test/unit/util/output' require 'test/unit/util/method-owner-finder' @@ -104,7 +105,6 @@ class << self def inherited(sub_class) # :nodoc: - require "test/unit" DESCENDANTS << sub_class super end @@ -120,7 +120,12 @@ source_location = find_attribute(stringified_name, :source_location) if source_location path, line = source_location + elsif respond_to?(:caller_locations, true) + location = caller_locations(1, 1)[0] + path = location.absolute_path || location.path + line = location.lineno else + # TODO: Remove me when Ruby 1.9 support is dropped path, line, = caller[0].split(/:(\d+)/, 2) line = line.to_i if line end @@ -130,6 +135,7 @@ :line => line, } added_method_names[stringified_name] = true + AutoRunnerLoader.check(self, stringified_name) end def added_method_names # :nodoc: @@ -281,6 +287,9 @@ else targets = test_description_or_targets attribute(:test, true, {}, *targets) + targets.each do |target| + AutoRunnerLoader.check(self, target) + end end end @@ -453,14 +462,31 @@ @internal_data.test_started yield(STARTED, name) yield(STARTED_OBJECT, self) + processed_exception_in_setup = false begin - run_setup - run_test - run_cleanup - add_pass + catch do |tag| + run_setup do + begin + run_test + run_cleanup + add_pass + rescue Exception + @internal_data.interrupted + unless handle_exception($!) + processed_exception_in_setup = true + raise + end + throw(tag) + end + end + end rescue Exception - @internal_data.interrupted - raise unless handle_exception($!) + if processed_exception_in_setup + raise + else + @internal_data.interrupted + raise unless handle_exception($!) + end ensure begin run_teardown diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/test/unit/testresult.rb new/lib/test/unit/testresult.rb --- old/lib/test/unit/testresult.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/lib/test/unit/testresult.rb 2016-03-19 15:20:52.000000000 +0100 @@ -38,12 +38,15 @@ attr_reader :run_count, :pass_count, :assertion_count, :faults + attr_accessor :stop_tag + # Constructs a new, empty TestResult. def initialize @run_count, @pass_count, @assertion_count = 0, 0, 0 @summary_generators = [] @problem_checkers = [] @faults = [] + @stop_tag = nil initialize_containers end @@ -92,6 +95,10 @@ end end + def stop + throw @stop_tag + end + def to_s summary end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/test/unit/ui/testrunnermediator.rb new/lib/test/unit/ui/testrunnermediator.rb --- old/lib/test/unit/ui/testrunnermediator.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/lib/test/unit/ui/testrunnermediator.rb 2016-03-19 15:20:52.000000000 +0100 @@ -4,7 +4,6 @@ # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved. # License:: Ruby license. -require 'test/unit' require 'test/unit/util/observable' require 'test/unit/testresult' @@ -18,9 +17,9 @@ RESET = name + "::RESET" STARTED = name + "::STARTED" FINISHED = name + "::FINISHED" - + include Util::Observable - + # Creates a new TestRunnerMediator initialized to run # the passed suite. def initialize(suite) @@ -37,11 +36,14 @@ Test::Unit.run_at_start_hooks start_time = Time.now begin - with_listener(result) do - notify_listeners(RESET, @suite.size) - notify_listeners(STARTED, result) + catch do |stop_tag| + result.stop_tag = stop_tag + with_listener(result) do + notify_listeners(RESET, @suite.size) + notify_listeners(STARTED, result) - run_suite(result) + run_suite(result) + end end ensure elapsed_time = Time.now - start_time diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/test/unit/util/backtracefilter.rb new/lib/test/unit/util/backtracefilter.rb --- old/lib/test/unit/util/backtracefilter.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/lib/test/unit/util/backtracefilter.rb 2016-03-19 15:20:52.000000000 +0100 @@ -1,3 +1,8 @@ +begin + require 'power_assert' +rescue LoadError, SyntaxError +end + module Test module Unit module Util @@ -6,21 +11,28 @@ TESTUNIT_PREFIX = __FILE__.split(TESTUNIT_FILE_SEPARATORS)[0..-3] TESTUNIT_RB_FILE = /\.rb\Z/ + POWERASSERT_PREFIX = + defined?(PowerAssert) ? + PowerAssert.method(:start).source_location[0].split(TESTUNIT_FILE_SEPARATORS)[0..-2] : + nil + module_function def filter_backtrace(backtrace, prefix=nil) return ["No backtrace"] unless backtrace return backtrace if ENV["TEST_UNIT_ALL_BACKTRACE"] if prefix - split_prefix = prefix.split(TESTUNIT_FILE_SEPARATORS) + split_prefixes = [prefix.split(TESTUNIT_FILE_SEPARATORS)] else - split_prefix = TESTUNIT_PREFIX + split_prefixes = [TESTUNIT_PREFIX, POWERASSERT_PREFIX].compact end test_unit_internal_p = lambda do |entry| components = entry.split(TESTUNIT_FILE_SEPARATORS) - split_entry = components[0, split_prefix.size] - next false unless split_entry[0..-2] == split_prefix[0..-2] - split_entry[-1].sub(TESTUNIT_RB_FILE, '') == split_prefix[-1] + split_prefixes.any? do |split_prefix| + split_entry = components[0, split_prefix.size] + next false unless split_entry[0..-2] == split_prefix[0..-2] + split_entry[-1].sub(TESTUNIT_RB_FILE, '') == split_prefix[-1] + end end in_user_code = false diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/test/unit/version.rb new/lib/test/unit/version.rb --- old/lib/test/unit/version.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/lib/test/unit/version.rb 2016-03-19 15:20:52.000000000 +0100 @@ -1,5 +1,5 @@ module Test module Unit - VERSION = '3.1.5' + VERSION = '3.1.8' end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2015-10-09 16:35:53.000000000 +0200 +++ new/metadata 2016-03-19 15:20:52.000000000 +0100 @@ -1,7 +1,7 @@ --- !ruby/object:Gem::Specification name: test-unit version: !ruby/object:Gem::Version - version: 3.1.5 + version: 3.1.8 platform: ruby authors: - Kouhei Sutou @@ -9,7 +9,7 @@ autorequire: bindir: bin cert_chain: [] -date: 2015-10-09 00:00:00.000000000 Z +date: 2016-03-19 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: power_assert @@ -121,6 +121,7 @@ - lib/test/unit/assertions.rb - lib/test/unit/attribute-matcher.rb - lib/test/unit/attribute.rb +- lib/test/unit/auto-runner-loader.rb - lib/test/unit/autorunner.rb - lib/test/unit/code-snippet-fetcher.rb - lib/test/unit/collector.rb @@ -228,49 +229,49 @@ version: '0' requirements: [] rubyforge_project: -rubygems_version: 2.2.2 +rubygems_version: 2.5.1 signing_key: specification_version: 4 summary: An xUnit family unit testing framework for Ruby. test_files: -- test/test-assertions.rb -- test/test-color.rb - test/test-code-snippet.rb +- test/test-fault-location-detector.rb +- test/test-attribute.rb +- test/test-priority.rb +- test/test-color-scheme.rb +- test/test-failure.rb +- test/test-color.rb +- test/ui/test_testrunmediator.rb +- test/test-attribute-matcher.rb +- test/test-test-suite.rb - test/test-test-suite-creator.rb +- test/test-diff.rb +- test/test-emacs-runner.rb +- test/test-data.rb +- test/fixtures/header.csv +- test/fixtures/header.tsv +- test/fixtures/no-header.tsv +- test/fixtures/plus.csv +- test/fixtures/no-header.csv +- test/fixtures/header-label.tsv +- test/fixtures/header-label.csv +- test/test-assertions.rb - test/test-test-result.rb +- test/testunit-test-util.rb +- test/collector/test-load.rb +- test/collector/test_dir.rb +- test/collector/test_objectspace.rb +- test/collector/test-descendant.rb - test/test-error.rb -- test/test-failure.rb - test/run-test.rb - test/test-pending.rb -- test/test-color-scheme.rb -- test/test-attribute-matcher.rb -- test/testunit-test-util.rb -- test/test-data.rb -- test/ui/test_testrunmediator.rb -- test/util/test-method-owner-finder.rb +- test/test-fixture.rb - test/util/test-output.rb +- test/util/test-method-owner-finder.rb - test/util/test_observable.rb -- test/util/test_backtracefilter.rb - test/util/test_procwrapper.rb +- test/util/test_backtracefilter.rb +- test/test-notification.rb - test/test-omission.rb - test/test-test-case.rb -- test/test-fixture.rb -- test/fixtures/no-header.csv -- test/fixtures/header-label.tsv -- test/fixtures/plus.csv -- test/fixtures/no-header.tsv -- test/fixtures/header-label.csv -- test/fixtures/header.csv -- test/fixtures/header.tsv -- test/collector/test-descendant.rb -- test/collector/test_objectspace.rb -- test/collector/test-load.rb -- test/collector/test_dir.rb -- test/test-priority.rb -- test/test-test-suite.rb -- test/test-diff.rb -- test/test-emacs-runner.rb -- test/test-attribute.rb -- test/test-fault-location-detector.rb -- test/test-notification.rb has_rdoc: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test-assertions.rb new/test/test-assertions.rb --- old/test/test-assertions.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/test/test-assertions.rb 2016-03-19 15:20:52.000000000 +0100 @@ -68,7 +68,10 @@ "Incorrect expected message type in assert_nothing_failed") end else - if return_value_expected + case return_value_expected + when :dont_care + # do nothing + when true check(!return_value.nil?, "Should return a value") else check(return_value.nil?, @@ -812,22 +815,22 @@ end def test_assert_nothing_raised - check_nothing_fails { + check_nothing_fails(:dont_care) { assert_nothing_raised { 1 + 1 } } - check_nothing_fails { + check_nothing_fails(:dont_care) { assert_nothing_raised("successful assert_nothing_raised") { 1 + 1 } } - check_nothing_fails { + check_nothing_fails(:dont_care) { assert_nothing_raised("successful assert_nothing_raised") { 1 + 1 } } - check_nothing_fails { + check_nothing_fails(:dont_care) { begin assert_nothing_raised(RuntimeError, StandardError, Comparable, "successful assert_nothing_raised") { raise ZeroDivisionError.new("ArgumentError") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test-data.rb new/test/test-data.rb --- old/test/test-data.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/test/test-data.rb 2016-03-19 15:20:52.000000000 +0100 @@ -75,6 +75,21 @@ @calc.plus(data["augend"], data["addend"])) end end + + class TestSuperclass < TestCalc + data("positive positive" => {:expected => 4, :augend => 3, :addend => 1}, + "positive negative" => {:expected => -1, :augend => 1, :addend => -2}) + def test_plus(data) + assert_equal(data[:expected], + @calc.plus(data[:augend], data[:addend])) + end + + class TestNormalTestInSubclass < self + def test_plus + assert_equal(2, @calc.plus(1, 1)) + end + end + end end def setup @@ -168,13 +183,20 @@ data("data set" => TestCalc::TestDataSet, "n-data" => TestCalc::TestNData, "dynamic-data-set" => TestCalc::TestDynamicDataSet, - "load-data-set" => TestCalc::TestLoadDataSet) + "load-data-set" => TestCalc::TestLoadDataSet, + "superclass" => TestCalc::TestSuperclass) def test_run(test_case) result = _run_test(test_case) assert_equal("2 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, " \ "0 omissions, 0 notifications", result.to_s) end + def test_run_normal_test_in_subclass + result = _run_test(TestCalc::TestSuperclass::TestNormalTestInSubclass) + assert_equal("1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, " \ + "0 omissions, 0 notifications", result.to_s) + end + data("data set" => TestCalc::TestDataSet, "n-data" => TestCalc::TestNData, "dynamic-data-set" => TestCalc::TestDynamicDataSet, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/test-fixture.rb new/test/test-fixture.rb --- old/test/test-fixture.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/test/test-fixture.rb 2016-03-19 15:20:52.000000000 +0100 @@ -535,6 +535,60 @@ called) end + def test_setup_with_block + test_case = Class.new(Test::Unit::TestCase) do + def called_ids + @called_ids ||= [] + end + + def called(id) + called_ids << id + end + + setup + def setup1 + called(:setup1) + begin + yield + called(:setup1_after_yield) + ensure + called(:setup1_teardown) + end + end + + setup + def setup2 + called(:setup2) + begin + yield + called(:setup2_after_yield) + ensure + called(:setup2_teardown) + end + end + + def teardown + called(:teardown) + end + + def test_nothing + called(:test) + flunk + called(:test_after_failure) + end + end + + assert_called_fixtures([ + :setup1, + :setup2, + :test, + :setup2_teardown, + :setup1_teardown, + :teardown, + ], + test_case) + end + private def assert_teardown_customizable(expected, parent, options) test_case = Class.new(parent || Test::Unit::TestCase) do diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/test/util/test_backtracefilter.rb new/test/util/test_backtracefilter.rb --- old/test/util/test_backtracefilter.rb 2015-10-09 16:35:53.000000000 +0200 +++ new/test/util/test_backtracefilter.rb 2016-03-19 15:20:52.000000000 +0100 @@ -16,7 +16,7 @@ %q{tc_thing.rb:3}] assert_equal(backtrace[1..2], filter_backtrace(backtrace, %q{C:\some\old\path\test\unit}), "Should filter out all TestUnit-specific lines") -backtrace = [%q{tc_thing.rb:4:in 'a'}, + backtrace = [%q{tc_thing.rb:4:in 'a'}, %q{tc_thing.rb:4:in 'test_stuff'}, %q{tc_thing.rb:3}] assert_equal(backtrace, filter_backtrace(backtrace, %q{C:\some\old\path\test\unit}), "Shouldn't filter too much") @@ -37,5 +37,16 @@ def test_nil_backtrace assert_equal(["No backtrace"], filter_backtrace(nil)) end + + def test_power_assert_backtrace + omit('test for power_assert') unless defined?(PowerAssert) + blk = Proc.new {caller.find {|i| /power_assert.*in \`start\'/ =~ i}} + PowerAssert.start(blk) do |pa| + backtrace = [pa.yield, + %q{tc_thing.rb:4:in 'a'}, + %q{tc_thing.rb:4:in 'test_stuff'}] + assert_equal(backtrace[1..2], filter_backtrace(backtrace)) + end + end end end