ruby-changes:56326
From: Hiroshi <ko1@a...>
Date: Tue, 2 Jul 2019 08:49:37 +0900 (JST)
Subject: [ruby-changes:56326] Hiroshi SHIBATA: c68781e918 (master): Split test files for test-framework that are test-unit and minitest to tool direcotry.
https://git.ruby-lang.org/ruby.git/commit/?id=c68781e918 From c68781e9181cb43af1bac29b3c974887205c3bf3 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA <hsbt@r...> Date: Mon, 1 Jul 2019 21:05:55 +0900 Subject: Split test files for test-framework that are test-unit and minitest to tool direcotry. diff --git a/common.mk b/common.mk index 8393541..a48e1c8 100755 --- a/common.mk +++ b/common.mk @@ -185,6 +185,7 @@ INSTALL_PROG_MODE = 0755 https://github.com/ruby/ruby/blob/trunk/common.mk#L185 INSTALL_DATA_MODE = 0644 TESTSDIR = $(srcdir)/test +TOOL_TESTSDIR = ${srcdir}/tool/test TEST_EXCLUDES = --excludes-dir=$(TESTSDIR)/excludes --name=!/memory_leak/ EXCLUDE_TESTFRAMEWORK = --exclude=/testunit/ --exclude=/minitest/ TESTWORKDIR = testwork @@ -753,7 +754,7 @@ yes-test-knownbug: prog PHONY https://github.com/ruby/ruby/blob/trunk/common.mk#L754 test-testframework: $(TEST_RUNNABLE)-test-testframework yes-test-testframework: prog PHONY - $(gnumake_recursive)$(Q)$(exec) $(RUNRUBY) "$(srcdir)/test/runner.rb" --ruby="$(RUNRUBY)" $(TESTOPTS) testunit minitest + $(gnumake_recursive)$(Q)$(exec) $(RUNRUBY) "$(srcdir)/test/runner.rb" --ruby="$(RUNRUBY)" --basedir=${TOOL_TESTSDIR} $(TESTOPTS) testunit minitest no-test-testframework: PHONY test-sample: test-basic # backward compatibility for mswin-build diff --git a/test/minitest/metametameta.rb b/test/minitest/metametameta.rb deleted file mode 100644 index a12717c..0000000 --- a/test/minitest/metametameta.rb +++ /dev/null @@ -1,71 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/common.mk#L0 -# encoding: utf-8 -# frozen_string_literal: false - -require 'tempfile' -require 'stringio' -require 'minitest/autorun' - -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/test/minitest/test_minitest_benchmark.rb b/test/minitest/test_minitest_benchmark.rb deleted file mode 100644 index a783e68..0000000 --- a/test/minitest/test_minitest_benchmark.rb +++ /dev/null @@ -1,131 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/common.mk#L0 -# encoding: utf-8 -# frozen_string_literal: false - -require 'minitest/autorun' -require 'minitest/benchmark' - -## -# Used to verify data: -# http://www.wolframalpha.com/examples/RegressionAnalysis.html - -class TestMiniTestBenchmark < MiniTest::Unit::TestCase - def test_cls_bench_exp - assert_equal [2, 4, 8, 16, 32], self.class.bench_exp(2, 32, 2) - end - - def test_cls_bench_linear - assert_equal [2, 4, 6, 8, 10], self.class.bench_linear(2, 10, 2) - end - - def test_cls_benchmark_methods - assert_equal [], self.class.benchmark_methods - - c = Class.new(MiniTest::Unit::TestCase) do - def bench_blah - end - end - - assert_equal ["bench_blah"], c.benchmark_methods - end - - def test_cls_bench_range - assert_equal [1, 10, 100, 1_000, 10_000], self.class.bench_range - end - - def test_fit_exponential_clean - x = [1.0, 2.0, 3.0, 4.0, 5.0] - y = x.map { |n| 1.1 * Math.exp(2.1 * n) } - - assert_fit :exponential, x, y, 1.0, 1.1, 2.1 - end - - def test_fit_exponential_noisy - x = [1.0, 1.9, 2.6, 3.4, 5.0] - y = [12, 10, 8.2, 6.9, 5.9] - - # verified with Numbers and R - assert_fit :exponential, x, y, 0.95, 13.81148, -0.1820 - end - - def test_fit_logarithmic_clean - x = [1.0, 2.0, 3.0, 4.0, 5.0] - y = x.map { |n| 1.1 + 2.1 * Math.log(n) } - - assert_fit :logarithmic, x, y, 1.0, 1.1, 2.1 - end - - def test_fit_logarithmic_noisy - x = [1.0, 2.0, 3.0, 4.0, 5.0] - # Generated with - # y = x.map { |n| jitter = 0.999 + 0.002 * rand; (Math.log(n) ) * jitter } - y = [0.0, 0.6935, 1.0995, 1.3873, 1.6097] - - assert_fit :logarithmic, x, y, 0.95, 0, 1 - end - - def test_fit_constant_clean - x = (1..5).to_a - y = [5.0, 5.0, 5.0, 5.0, 5.0] - - assert_fit :linear, x, y, nil, 5.0, 0 - end - - def test_fit_constant_noisy - x = (1..5).to_a - y = [1.0, 1.2, 1.0, 0.8, 1.0] - - # verified in numbers and R - assert_fit :linear, x, y, nil, 1.12, -0.04 - end - - def test_fit_linear_clean - # y = m * x + b where m = 2.2, b = 3.1 - x = (1..5).to_a - y = x.map { |n| 2.2 * n + 3.1 } - - assert_fit :linear, x, y, 1.0, 3.1, 2.2 - end - - def test_fit_linear_noisy - x = [ 60, 61, 62, 63, 65] - y = [3.1, 3.6, 3.8, 4.0, 4.1] - - # verified in numbers and R - assert_fit :linear, x, y, 0.8315, -7.9635, 0.1878 - end - - def test_fit_power_clean - # y = A x ** B, where B = b and A = e ** a - # if, A = 1, B = 2, then - - x = [1.0, 2.0, 3.0, 4.0, 5.0] - y = [1.0, 4.0, 9.0, 16.0, 25.0] - - assert_fit :power, x, y, 1.0, 1.0, 2.0 - end - - def test_fit_power_noisy - # from www.engr.uidaho.edu/thompson/courses/ME330/lecture/least_squares.html - x = [10, 12, 15, 17, 20, 22, 25, 27, 30, 32, 35] - y = [95, 105, 125, 141, 173, 200, 253, 298, 385, 459, 602] - - # verified in numbers - assert_fit :power, x, y, 0.90, 2.6217, 1.4556 - - # income to % of households below income amount - # http://library.wolfram.com/infocenter/Conferences/6461/PowerLaws.nb - x = [15000, 25000, 35000, 50000, 75000, 100000] - y = [0.154, 0.283, 0.402, 0.55, 0.733, 0.843] - - # verified in numbers - assert_fit :power, x, y, 0.96, 3.119e-5, 0.8959 - end - - def assert_fit msg, x, y, fit, exp_a, exp_b - a, b, rr = send "fit_#{msg}", x, y - - assert_operator rr, :>=, fit if fit - assert_in_delta exp_a, a - assert_in_delta exp_b, b - end -end diff --git a/test/minitest/test_minitest_mock.rb b/test/minitest/test_minitest_mock.rb deleted file mode 100644 index 6dcf39b..0000000 --- a/test/minitest/test_minitest_mock.rb +++ /dev/null @@ -1,404 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/common.mk#L0 -# encoding: utf-8 -# frozen_string_literal: false - -require 'minitest/autorun' - -class TestMiniTestMock < MiniTest::Unit::TestCase - def setup - @mock = MiniTest::Mock.new.expect(:foo, nil) - @mock.expect(:meaning_of_life, 42) - end - - def test_create_stub_method - assert_nil @mock.foo - end - - def test_allow_return_value_specification - assert_equal 42, @mock.meaning_of_life - end - - def test_blow_up_if_not_called - @mock.foo - - util_verify_bad "expected meaning_of_life() => 42, got []" - end - - def test_not_blow_up_if_everything_called - @mock.foo - @mock.meaning_of_life - - assert @mock.verify - end - - def test_allow_expectations_to_be_added_after_creation - @mock.expect(:bar, true) - assert @mock.bar - end - - def test_not_verify_if_new_expected_method_is_not_called - @mock.foo - @mock.meaning_of_life - @mock.expect(:bar, true) - - util_verify_bad "expected bar() => true, got []" - end - - def test_blow_up_on_wrong_number_of_arguments - @mock.foo - @mock.meaning_of_life - @mock.expect(:sum, 3, [1, 2]) - - e = assert_raises ArgumentError do - @mock.sum - end - - assert_equal "mocked method :sum expects 2 arguments, got 0", e.message - end - - def test_return_mock_does_not_raise - retval = MiniTest::Mock.new - mock = MiniTest::Mock.new - mock.expect(:foo, retval) - mock.foo - - assert mock.verify - end - - def test_mock_args_does_not_raise - skip "non-opaque use of ==" if maglev? - - arg = MiniTest::Mock.new - mock = MiniTest::Mock.new - mock.expect(:foo, nil, [arg]) - mock.foo(arg) - - assert mock.verify - end - - def test_blow_up_on_wrong_arguments - @mock.foo - @mock.meaning_of_life - @mock.expect(:sum, 3, [1, 2]) - - e = assert_raises MockExpectationError do - @mock.sum(2, 4) - end - - exp = "mocked method :sum called with unexpected arguments [2, 4]" - assert_equal exp, e.message - end - - def test_expect_with_non_array_args - e = assert_raises ArgumentError do - @mock.expect :blah, 3, false - end - - assert_equal "args must be an array", e.message - end - - def test_respond_appropriately - assert @mock.respond_to?(:foo) - assert @mock.respond_to?(:foo, true) - assert @mock.respond_to?('foo') - assert !@mock.respond_to?(:bar) - end - - def test_no_method_error_on_unexpected_methods - e = assert_raises NoMethodError do - @mock.bar - end - - expected = "unmocked method :bar, expected one of [:foo, :meaning_of_life]" - - assert_equal expected, e.message - end - - def test_assign_per_mock_return_values - a = MiniTest::Mock.new - b = MiniTest::Mock.new - - a.expect(:foo, :a) - b.expect(:foo, :b) - - assert_equal :a, a.foo - assert_equal :b, b.foo - end - - def test_do_not_create_stub_method_on_new_moc (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/