ruby-changes:67885
From: Hiroshi <ko1@a...>
Date: Sat, 11 Sep 2021 08:48:27 +0900 (JST)
Subject: [ruby-changes:67885] 8aaa40e55f (master): Move test of minitest to testunit
https://git.ruby-lang.org/ruby.git/commit/?id=8aaa40e55f From 8aaa40e55fa2812755dec33db265745c77cdb3ed Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA <hsbt@r...> Date: Thu, 9 Sep 2021 13:56:02 +0900 Subject: Move test of minitest to testunit --- tool/test/minitest/metametameta.rb | 70 -- tool/test/minitest/test_minitest_unit.rb | 1793 ------------------------------ tool/test/testunit/metametameta.rb | 70 ++ tool/test/testunit/test_minitest_unit.rb | 1793 ++++++++++++++++++++++++++++++ 4 files changed, 1863 insertions(+), 1863 deletions(-) delete mode 100644 tool/test/minitest/metametameta.rb delete mode 100644 tool/test/minitest/test_minitest_unit.rb create mode 100644 tool/test/testunit/metametameta.rb create mode 100644 tool/test/testunit/test_minitest_unit.rb diff --git a/tool/test/minitest/metametameta.rb b/tool/test/minitest/metametameta.rb deleted file mode 100644 index dbc422f..0000000 --- a/tool/test/minitest/metametameta.rb +++ /dev/null @@ -1,70 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/#L0 -# encoding: utf-8 -# frozen_string_literal: false - -require 'tempfile' -require 'stringio' - -class MiniTest::Unit::TestCase - def clean s - s.gsub(/^ {6}/, '') - end -end - -class MetaMetaMetaTestCase < MiniTest::Unit::TestCase - def assert_report expected, flags = %w[--seed 42] - header = clean <<-EOM - Run options: #{flags.map { |s| s =~ /\|/ ? s.inspect : s }.join " "} - - # Running tests: - - EOM - - with_output do - @tu.run flags - end - - output = @output.string.dup - output.sub!(/Finished tests in .*/, "Finished tests in 0.00") - output.sub!(/Loaded suite .*/, 'Loaded suite blah') - - output.gsub!(/ = \d+.\d\d s = /, ' = 0.00 s = ') - output.gsub!(/0x[A-Fa-f0-9]+/, '0xXXX') - - if windows? then - output.gsub!(/\[(?:[A-Za-z]:)?[^\]:]+:\d+\]/, '[FILE:LINE]') - output.gsub!(/^(\s+)(?:[A-Za-z]:)?[^:]+:\d+:in/, '\1FILE:LINE:in') - else - output.gsub!(/\[[^\]:]+:\d+\]/, '[FILE:LINE]') - output.gsub!(/^(\s+)[^:]+:\d+:in/, '\1FILE:LINE:in') - end - - assert_equal header + expected, output - end - - def setup - super - srand 42 - MiniTest::Unit::TestCase.reset - @tu = MiniTest::Unit.new - - MiniTest::Unit.runner = nil # protect the outer runner from the inner tests - end - - def teardown - super - end - - def with_output - synchronize do - begin - save = MiniTest::Unit.output - @output = StringIO.new("") - MiniTest::Unit.output = @output - - yield - ensure - MiniTest::Unit.output = save - end - end - end -end diff --git a/tool/test/minitest/test_minitest_unit.rb b/tool/test/minitest/test_minitest_unit.rb deleted file mode 100644 index 5476cf9..0000000 --- a/tool/test/minitest/test_minitest_unit.rb +++ /dev/null @@ -1,1793 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/#L0 -# encoding: utf-8 -# frozen_string_literal: false - -require 'pathname' -require_relative 'metametameta' - -module MyModule; end -class AnError < StandardError; include MyModule; end -class ImmutableString < String; def inspect; super.freeze; end; end - -class TestMiniTestUnit < MetaMetaMetaTestCase - pwd = Pathname.new File.expand_path Dir.pwd - basedir = Pathname.new(File.expand_path "lib/minitest") + 'mini' - basedir = basedir.relative_path_from(pwd).to_s - MINITEST_BASE_DIR = basedir[/\A\./] ? basedir : "./#{basedir}" - BT_MIDDLE = ["#{MINITEST_BASE_DIR}/test.rb:161:in `each'", - "#{MINITEST_BASE_DIR}/test.rb:158:in `each'", - "#{MINITEST_BASE_DIR}/test.rb:139:in `run'", - "#{MINITEST_BASE_DIR}/test.rb:106:in `run'"] - - def test_class_puke_with_assertion_failed - exception = MiniTest::Assertion.new "Oh no!" - exception.set_backtrace ["unhappy"] - assert_equal 'F', @tu.puke('SomeClass', 'method_name', exception) - assert_equal 1, @tu.failures - assert_match(/^Failure.*Oh no!/m, @tu.report.first) - assert_match("SomeClass#method_name [unhappy]", @tu.report.first) - end - - def test_class_puke_with_assertion_failed_and_long_backtrace - bt = (["test/test_some_class.rb:615:in `method_name'", - "#{MINITEST_BASE_DIR}/unit.rb:140:in `assert_raises'", - "test/test_some_class.rb:615:in `each'", - "test/test_some_class.rb:614:in `test_method_name'", - "#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] + - BT_MIDDLE + - ["#{MINITEST_BASE_DIR}/test.rb:29"]) - bt = util_expand_bt bt - - ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first - - exception = MiniTest::Assertion.new "Oh no!" - exception.set_backtrace bt - assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception) - assert_equal 1, @tu.failures - assert_match(/^Failure.*Oh no!/m, @tu.report.first) - assert_match("TestSomeClass#test_method_name [#{ex_location}]", @tu.report.first) - end - - def test_class_puke_with_assertion_failed_and_user_defined_assertions - bt = (["lib/test/my/util.rb:16:in `another_method_name'", - "#{MINITEST_BASE_DIR}/unit.rb:140:in `assert_raises'", - "lib/test/my/util.rb:15:in `block in assert_something'", - "lib/test/my/util.rb:14:in `each'", - "lib/test/my/util.rb:14:in `assert_something'", - "test/test_some_class.rb:615:in `each'", - "test/test_some_class.rb:614:in `test_method_name'", - "#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] + - BT_MIDDLE + - ["#{MINITEST_BASE_DIR}/test.rb:29"]) - bt = util_expand_bt bt - - ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first - - exception = MiniTest::Assertion.new "Oh no!" - exception.set_backtrace bt - assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception) - assert_equal 1, @tu.failures - assert_match(/^Failure.*Oh no!/m, @tu.report.first) - assert_match("TestSomeClass#test_method_name [#{ex_location}]", @tu.report.first) - end - - def test_class_puke_with_failure_and_flunk_in_backtrace - exception = begin - MiniTest::Unit::TestCase.new('fake tc').flunk - rescue MiniTest::Assertion => failure - failure - end - assert_equal 'F', @tu.puke('SomeClass', 'method_name', exception) - refute @tu.report.any?{|line| line =~ /in .flunk/} - end - - def test_class_puke_with_flunk_and_user_defined_assertions - bt = (["lib/test/my/util.rb:16:in `flunk'", - "#{MINITEST_BASE_DIR}/unit.rb:140:in `assert_raises'", - "lib/test/my/util.rb:15:in `block in assert_something'", - "lib/test/my/util.rb:14:in `each'", - "lib/test/my/util.rb:14:in `assert_something'", - "test/test_some_class.rb:615:in `each'", - "test/test_some_class.rb:614:in `test_method_name'", - "#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] + - BT_MIDDLE + - ["#{MINITEST_BASE_DIR}/test.rb:29"]) - bt = util_expand_bt bt - - ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first - - exception = MiniTest::Assertion.new "Oh no!" - exception.set_backtrace bt - assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception) - assert_equal 1, @tu.failures - assert_match(/^Failure.*Oh no!/m, @tu.report.first) - assert_match("TestSomeClass#test_method_name [#{ex_location}]", @tu.report.first) - end - - def test_class_puke_with_non_failure_exception - exception = Exception.new("Oh no again!") - assert_equal 'E', @tu.puke('SomeClass', 'method_name', exception) - assert_equal 1, @tu.errors - assert_match(/^Exception.*Oh no again!/m, @tu.report.first) - end - - def test_filter_backtrace - # this is a semi-lame mix of relative paths. - # I cheated by making the autotest parts not have ./ - bt = (["lib/autotest.rb:571:in `add_exception'", - "test/test_autotest.rb:62:in `test_add_exception'", - "#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] + - BT_MIDDLE + - ["#{MINITEST_BASE_DIR}/test.rb:29", - "test/test_autotest.rb:422"]) - bt = util_expand_bt bt - - ex = ["lib/autotest.rb:571:in `add_exception'", - "test/test_autotest.rb:62:in `test_add_exception'"] - ex = util_expand_bt ex - - fu = MiniTest::filter_backtrace(bt) - - assert_equal ex, fu - end - - def test_filter_backtrace_all_unit - bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] + - BT_MIDDLE + - ["#{MINITEST_BASE_DIR}/test.rb:29"]) - ex = bt.clone - fu = MiniTest::filter_backtrace(bt) - assert_equal ex, fu - end - - def test_filter_backtrace_unit_starts - bt = (["#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] + - BT_MIDDLE + - ["#{MINITEST_BASE_DIR}/mini/test.rb:29", - "-e:1"]) - - bt = util_expand_bt bt - - ex = ["-e:1"] - fu = MiniTest::filter_backtrace bt - assert_equal ex, fu - end - - def test_default_runner_is_minitest_unit - assert_instance_of MiniTest::Unit, MiniTest::Unit.runner - end - - - def test_passed_eh_teardown_good - test_class = Class.new MiniTest::Unit::TestCase do - def teardown; assert true; end - def test_omg; assert true; end - end - - test = test_class.new :test_omg - test.run @tu - assert test.passed? - end - - def test_passed_eh_teardown_skipped - test_class = Class.new MiniTest::Unit::TestCase do - def teardown; assert true; end - def test_omg; skip "bork"; end - end - - test = test_class.new :test_omg - test.run @tu - assert test.passed? - end - - def test_passed_eh_teardown_flunked - test_class = Class.new MiniTest::Unit::TestCase do - def teardown; flunk; end - def test_omg; assert true; end - end - - test = test_class.new :test_omg - test.run @tu - refute test.passed? - end - - def util_expand_bt bt - bt.map { |f| (f =~ /^\./) ? File.ex (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/