From ee9e8f82d4baccd90e82d8a0acd75001aa495b0f Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 1 Sep 2010 08:40:53 +0000 Subject: Imported minitest 1.7.1 r5835 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/minitest/spec.rb | 15 ++++++++++++++- lib/minitest/unit.rb | 41 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/minitest/spec.rb b/lib/minitest/spec.rb index 59b4c6536c..43f1c6ca09 100644 --- a/lib/minitest/spec.rb +++ b/lib/minitest/spec.rb @@ -55,7 +55,7 @@ Object.infect_with_assertions(:must, :wont, /_in_/ => '_be_within_', /_operator/ => '_be', /_includes/ => '_include', - /(must|wont)_(.*_of|nil|empty)/ => '\1_be_\2', + /(must|wont)_(.*_of|nil|silent|empty)/ => '\1_be_\2', /must_raises/ => 'must_raise') class Object @@ -84,6 +84,7 @@ module Kernel stack.push cls cls.class_eval(&block) stack.pop + cls end private :describe end @@ -202,6 +203,10 @@ class MiniTest::Spec < MiniTest::Unit::TestCase # :method: must_be_same_as # See MiniTest::Assertions#assert_same + ## + # :method: must_be_silent + # See MiniTest::Assertions#assert_silent + ## # :method: must_be_within_delta # See MiniTest::Assertions#assert_in_delta @@ -222,6 +227,10 @@ class MiniTest::Spec < MiniTest::Unit::TestCase # :method: must_match # See MiniTest::Assertions#assert_match + ## + # :method: must_output + # See MiniTest::Assertions#assert_output + ## # :method: must_raise # See MiniTest::Assertions#assert_raises @@ -270,6 +279,10 @@ class MiniTest::Spec < MiniTest::Unit::TestCase # :method: wont_be_within_delta # See MiniTest::Assertions#refute_in_delta + ## + # :method: wont_be_within_delta + # See MiniTest::Assertions#refute_in_delta + ## # :method: wont_be_within_epsilon # See MiniTest::Assertions#refute_in_epsilon diff --git a/lib/minitest/unit.rb b/lib/minitest/unit.rb index 3e038c818f..c45dec3fc4 100644 --- a/lib/minitest/unit.rb +++ b/lib/minitest/unit.rb @@ -194,6 +194,24 @@ module MiniTest assert o1.__send__(op, o2), msg end + ## + # Fails if stdout or stderr do not output the expected results. + # Pass in nil if you don't care about that streams output. Pass in + # "" if you require it to be silent. + # + # See also: #assert_silent + + def assert_output stdout = nil, stderr = nil + out, err = capture_io do + yield + end + + x = assert_equal stdout, out, "In stdout" if stdout + y = assert_equal stderr, err, "In stderr" if stderr + + (!stdout || x) && (!stderr || y) + end + ## # Fails unless the block raises one of +exp+ @@ -251,6 +269,17 @@ module MiniTest assert recv.__send__(msg, *args), m end + ## + # Fails if the block outputs anything to stderr or stdout. + # + # See also: #assert_output + + def assert_silent + assert_output "", "" do + yield + end + end + ## # Fails unless the block throws +sym+ @@ -474,7 +503,7 @@ module MiniTest end class Unit - VERSION = "1.6.0" # :nodoc: + VERSION = "1.7.1" # :nodoc: attr_accessor :report, :failures, :errors, :skips # :nodoc: attr_accessor :test_count, :assertion_count # :nodoc: @@ -588,6 +617,12 @@ module MiniTest srand seed + help = ["--seed", seed] + help.push "--verbose" if @verbose + help.push("--name", options[:filter].inspect) if options[:filter] + + @@out.puts "Test run options: #{help.join(" ")}" + @@out.puts @@out.puts "Loaded suite #{$0.sub(/\.rb$/, '')}\nStarted" start = Time.now @@ -606,10 +641,6 @@ module MiniTest @@out.puts - help = ["--seed", seed] - help.push "--verbose" if @verbose - help.push("--name", options[:filter].inspect) if options[:filter] - @@out.puts "Test run options: #{help.join(" ")}" return failures + errors if @test_count > 0 # or return nil... -- cgit v1.2.3