diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-01 01:12:31 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-12-01 01:12:31 +0000 |
commit | 54fd6de064142633f3bb592b0bd6486d262cd2b2 (patch) | |
tree | c86d22ef1ed214ecc725f261aa313993e08d041d /test/minitest | |
parent | 22b2c638553c26e265a88a6b68ec31d132361ec7 (diff) | |
download | ruby-54fd6de064142633f3bb592b0bd6486d262cd2b2.tar.gz |
Revert r29986: "Imported minitest 2.0.0 r5952"
This breaks test-all:
* two test-all errors (test_run_passing and test_run_failing_filtered).
* -v option to test-all is ignored
Additional to say, please describe summary of the change when you
import from external repository.
And, RUN test-all BEFORE COMMIT.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/minitest')
-rw-r--r-- | test/minitest/test_mini_mock.rb (renamed from test/minitest/test_minitest_mock.rb) | 49 | ||||
-rw-r--r-- | test/minitest/test_mini_spec.rb (renamed from test/minitest/test_minitest_spec.rb) | 14 | ||||
-rw-r--r-- | test/minitest/test_mini_test.rb (renamed from test/minitest/test_minitest_unit.rb) | 124 | ||||
-rw-r--r-- | test/minitest/test_minitest_benchmark.rb | 104 |
4 files changed, 85 insertions, 206 deletions
diff --git a/test/minitest/test_minitest_mock.rb b/test/minitest/test_mini_mock.rb index bb4279c7d1..0f16ae930e 100644 --- a/test/minitest/test_minitest_mock.rb +++ b/test/minitest/test_mini_mock.rb @@ -9,39 +9,39 @@ require 'minitest/unit' MiniTest::Unit.autorun -class TestMiniTestMock < MiniTest::Unit::TestCase +class TestMiniMock < MiniTest::Unit::TestCase def setup @mock = MiniTest::Mock.new.expect(:foo, nil) @mock.expect(:meaning_of_life, 42) end - def test_create_stub_method + def test_should_create_stub_method assert_nil @mock.foo end - def test_allow_return_value_specification + def test_should_allow_return_value_specification assert_equal 42, @mock.meaning_of_life end - def test_blow_up_if_not_called + def test_should_blow_up_if_not_called @mock.foo util_verify_bad end - def test_not_blow_up_if_everything_called + def test_should_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 + def test_should_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 + def test_should_not_verify_if_new_expected_method_is_not_called @mock.foo @mock.meaning_of_life @mock.expect(:bar, true) @@ -49,13 +49,13 @@ class TestMiniTestMock < MiniTest::Unit::TestCase util_verify_bad end - def test_not_verify_if_unexpected_method_is_called + def test_should_not_verify_if_unexpected_method_is_called assert_raises NoMethodError do @mock.unexpected end end - def test_blow_up_on_wrong_number_of_arguments + def test_should_blow_up_on_wrong_number_of_arguments @mock.foo @mock.meaning_of_life @mock.expect(:sum, 3, [1, 2]) @@ -65,7 +65,7 @@ class TestMiniTestMock < MiniTest::Unit::TestCase end end - def test_blow_up_on_wrong_arguments + def test_should_blow_up_on_wrong_arguments @mock.foo @mock.meaning_of_life @mock.expect(:sum, 3, [1, 2]) @@ -75,35 +75,6 @@ class TestMiniTestMock < MiniTest::Unit::TestCase util_verify_bad end - def test_respond_appropriately - assert @mock.respond_to?(:foo) - assert !@mock.respond_to?(:bar) - end - - def test_no_method_error_on_unexpected_methods - assert_raises NoMethodError do - @mock.bar - end - 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_mocks - a = MiniTest::Mock.new - a.expect(:foo, :a) - - assert !MiniTest::Mock.new.respond_to?(:foo) - end - def util_verify_bad assert_raises MockExpectationError do @mock.verify diff --git a/test/minitest/test_minitest_spec.rb b/test/minitest/test_mini_spec.rb index 733ce0f5c7..f2e30c66d0 100644 --- a/test/minitest/test_minitest_spec.rb +++ b/test/minitest/test_mini_spec.rb @@ -203,7 +203,7 @@ end class TestMeta < MiniTest::Unit::TestCase def test_structure - x = y = z = nil + x = y = nil x = describe "top-level thingy" do before {} after {} @@ -213,23 +213,13 @@ class TestMeta < MiniTest::Unit::TestCase y = describe "inner thingy" do before {} it "inner-it" do end - - z = describe "very inner thingy" do - before {} - it "inner-it" do end - end end end - assert_equal "top-level thingy", x.to_s - assert_equal "top-level thingy::inner thingy", y.to_s - assert_equal "top-level thingy::inner thingy::very inner thingy", z.to_s - top_methods = %w(setup teardown test_0001_top_level_it) inner_methods = %w(setup test_0001_inner_it) - assert_equal top_methods, x.instance_methods(false).sort.map {|o| o.to_s } + assert_equal top_methods, x.instance_methods(false).sort.map {|o| o.to_s } assert_equal inner_methods, y.instance_methods(false).sort.map {|o| o.to_s } - assert_equal inner_methods, z.instance_methods(false).sort.map {|o| o.to_s } end end diff --git a/test/minitest/test_minitest_unit.rb b/test/minitest/test_mini_test.rb index a8187f2275..176f6ec26f 100644 --- a/test/minitest/test_minitest_unit.rb +++ b/test/minitest/test_mini_test.rb @@ -10,31 +10,35 @@ require 'minitest/unit' MiniTest::Unit.autorun -module MyModule; end -class AnError < StandardError; include MyModule; end +module M; end +class E < StandardError; include M; end -class TestMiniTestUnit < MiniTest::Unit::TestCase +class TestMiniTest < MiniTest::Unit::TestCase pwd = Pathname.new(File.expand_path(Dir.pwd)) basedir = Pathname.new(File.expand_path(MiniTest::MINI_DIR)) + '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'", + BT_MIDDLE = ["#{MINITEST_BASE_DIR}/test.rb:165:in `run_test_suites'", + "#{MINITEST_BASE_DIR}/test.rb:161:in `each'", + "#{MINITEST_BASE_DIR}/test.rb:161:in `run_test_suites'", "#{MINITEST_BASE_DIR}/test.rb:158:in `each'", + "#{MINITEST_BASE_DIR}/test.rb:158:in `run_test_suites'", "#{MINITEST_BASE_DIR}/test.rb:139:in `run'", "#{MINITEST_BASE_DIR}/test.rb:106:in `run'"] def assert_report expected = nil - expected ||= "Run options: --seed 42 - -# Running tests: + expected ||= "Test run options: --seed 42 +Loaded suite blah +Started . - -Finished tests in 0.00 +Finished in 0.00 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips + +Test run options: --seed 42 " - output = @output.string.sub(/Finished tests in .*/, "Finished tests in 0.00") + output = @output.string.sub(/Finished in .*/, "Finished in 0.00") output.sub!(/Loaded suite .*/, 'Loaded suite blah') output.sub!(/^(\s+)(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+:/o, '\1FILE:LINE:') output.sub!(/\[(?:#{Regexp.union(__FILE__, File.expand_path(__FILE__))}):\d+\]/o, '[FILE:LINE]') @@ -47,6 +51,7 @@ Finished tests in 0.00 @tu = MiniTest::Unit.new @output = StringIO.new("") MiniTest::Unit.output = @output + assert_equal [0, 0], @tu.run_test_suites end def teardown @@ -146,6 +151,18 @@ Finished tests in 0.00 assert_match(/^Exception.*Oh no again!/m, @tu.report.first) end + def test_class_run_test_suites + tc = Class.new(MiniTest::Unit::TestCase) do + def test_something + assert true + end + end + + Object.const_set(:ATestCase, tc) + + assert_equal [1, 1], @tu.run_test_suites + end + def test_filter_backtrace # this is a semi-lame mix of relative paths. # I cheated by making the autotest parts not have ./ @@ -201,15 +218,14 @@ Finished tests in 0.00 Object.const_set(:ATestCase, tc) - @tu.run %w[--seed 42] - - expected = "Run options: --seed 42 + @tu.run %w[-s 42] -# Running tests: + expected = "Test run options: --seed 42 +Loaded suite blah +Started E. - -Finished tests in 0.00 +Finished in 0.00 1) Error: test_error(ATestCase): @@ -217,6 +233,8 @@ RuntimeError: unhandled exception FILE:LINE:in `test_error' 2 tests, 1 assertions, 0 failures, 1 errors, 0 skips + +Test run options: --seed 42 " assert_report expected end @@ -234,15 +252,14 @@ RuntimeError: unhandled exception Object.const_set(:ATestCase, tc) - @tu.run %w[--seed 42] + @tu.run %w[-s 42] - expected = "Run options: --seed 42 - -# Running tests: + expected = "Test run options: --seed 42 +Loaded suite blah +Started E - -Finished tests in 0.00 +Finished in 0.00 1) Error: test_something(ATestCase): @@ -250,6 +267,8 @@ RuntimeError: unhandled exception FILE:LINE:in `teardown' 1 tests, 1 assertions, 0 failures, 1 errors, 0 skips + +Test run options: --seed 42 " assert_report expected end @@ -267,21 +286,22 @@ RuntimeError: unhandled exception Object.const_set(:ATestCase, tc) - @tu.run %w[--seed 42] - - expected = "Run options: --seed 42 + @tu.run %w[-s 42] -# Running tests: + expected = "Test run options: --seed 42 +Loaded suite blah +Started F. - -Finished tests in 0.00 +Finished in 0.00 1) Failure: test_failure(ATestCase) [FILE:LINE]: Failed assertion, no message given. 2 tests, 2 assertions, 1 failures, 0 errors, 0 skips + +Test run options: --seed 42 " assert_report expected end @@ -299,17 +319,18 @@ Failed assertion, no message given. Object.const_set(:ATestCase, tc) - @tu.run %w[--name /some|thing/ --seed 42] - - expected = "Run options: --name \"/some|thing/\" --seed 42 + @tu.run %w[-n /something/ -s 42] -# Running tests: + expected = "Test run options: --seed 42 --name \"/something/\" +Loaded suite blah +Started . - -Finished tests in 0.00 +Finished in 0.00 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips + +Test run options: --seed 42 --name \"/something/\" " assert_report expected end @@ -323,7 +344,7 @@ Finished tests in 0.00 Object.const_set(:ATestCase, tc) - @tu.run %w[--seed 42] + @tu.run %w[-s 42] assert_report end @@ -341,21 +362,22 @@ Finished tests in 0.00 Object.const_set(:ATestCase, tc) - @tu.run %w[--seed 42] + @tu.run %w[-s 42] - expected = "Run options: --seed 42 - -# Running tests: + expected = "Test run options: --seed 42 +Loaded suite blah +Started S. - -Finished tests in 0.00 +Finished in 0.00 1) Skipped: test_skip(ATestCase) [FILE:LINE]: not yet 2 tests, 1 assertions, 0 failures, 0 errors, 1 skips + +Test run options: --seed 42 " assert_report expected end @@ -369,7 +391,7 @@ not yet end end -class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase +class TestMiniTestTestCase < MiniTest::Unit::TestCase def setup MiniTest::Unit::TestCase.reset @@ -526,9 +548,9 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase pattern = Object.new def pattern.=~(other) false end - def pattern.inspect; "[Object]" end + def pattern.inspect; "<<Object>>" end - util_assert_triggered 'Expected [Object] to match 5.' do + util_assert_triggered 'Expected <<Object>> to match 5.' do @tc.assert_match pattern, 5 end end @@ -641,8 +663,8 @@ class TestMiniTestUnitTestCase < MiniTest::Unit::TestCase end def test_assert_raises_module - @tc.assert_raises MyModule do - raise AnError + @tc.assert_raises M do + raise E end end @@ -714,13 +736,13 @@ FILE:LINE:in `test_assert_raises_triggered_different_msg' def test_assert_raises_triggered_subclass e = assert_raises MiniTest::Assertion do @tc.assert_raises StandardError do - raise AnError + raise E end end expected = "[StandardError] exception expected, not -Class: <AnError> -Message: <\"AnError\"> +Class: <E> +Message: <\"E\"> ---Backtrace--- FILE:LINE:in `test_assert_raises_triggered_subclass' ---------------" @@ -1001,9 +1023,9 @@ FILE:LINE:in `test_assert_raises_triggered_subclass' pattern = Object.new def pattern.=~(other) true end - def pattern.inspect; "[Object]" end + def pattern.inspect; "<<Object>>" end - util_assert_triggered 'Expected [Object] to not match 5.' do + util_assert_triggered 'Expected <<Object>> to not match 5.' do @tc.refute_match pattern, 5 end end diff --git a/test/minitest/test_minitest_benchmark.rb b/test/minitest/test_minitest_benchmark.rb deleted file mode 100644 index 089d0b3ce0..0000000000 --- a/test/minitest/test_minitest_benchmark.rb +++ /dev/null @@ -1,104 +0,0 @@ -############################################################ -# This file is imported from a different project. -# DO NOT make modifications in this repo. -# File a patch instead and assign it to Ryan Davis -############################################################ - -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_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 - assert_in_delta exp_a, a - assert_in_delta exp_b, b - end -end - |