mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	test/unit/assertions.rb: all_assertions
* test/lib/test/unit/assertions.rb (all_assertions): try all assertions and check if all passed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									6b52b88d46
								
							
						
					
					
						commit
						71730b4243
					
				
					 4 changed files with 42 additions and 29 deletions
				
			
		| 
						 | 
				
			
			@ -351,22 +351,19 @@ module Test
 | 
			
		|||
          raise "test_stderr ignored, use block only or without block" if test_stderr != []
 | 
			
		||||
          yield(stdout.lines.map {|l| l.chomp }, stderr.lines.map {|l| l.chomp }, status)
 | 
			
		||||
        else
 | 
			
		||||
          errs = []
 | 
			
		||||
          [[test_stdout, stdout], [test_stderr, stderr]].each do |exp, act|
 | 
			
		||||
            begin
 | 
			
		||||
              if exp.is_a?(Regexp)
 | 
			
		||||
                assert_match(exp, act, message)
 | 
			
		||||
              elsif exp.all? {|e| String === e}
 | 
			
		||||
                assert_equal(exp, act.lines.map {|l| l.chomp }, message)
 | 
			
		||||
              else
 | 
			
		||||
                assert_pattern_list(exp, act, message)
 | 
			
		||||
          all_assertions(message) do |a|
 | 
			
		||||
            [["stdout", test_stdout, stdout], ["stderr", test_stderr, stderr]].each do |key, exp, act|
 | 
			
		||||
              a.for(key) do
 | 
			
		||||
                if exp.is_a?(Regexp)
 | 
			
		||||
                  assert_match(exp, act)
 | 
			
		||||
                elsif exp.all? {|e| String === e}
 | 
			
		||||
                  assert_equal(exp, act.lines.map {|l| l.chomp })
 | 
			
		||||
                else
 | 
			
		||||
                  assert_pattern_list(exp, act)
 | 
			
		||||
                end
 | 
			
		||||
              end
 | 
			
		||||
            rescue MiniTest::Assertion => e
 | 
			
		||||
              errs << e.message
 | 
			
		||||
              message = nil
 | 
			
		||||
            end
 | 
			
		||||
          end
 | 
			
		||||
          raise MiniTest::Assertion, errs.join("\n---\n") unless errs.empty?
 | 
			
		||||
          status
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -442,6 +442,28 @@ EOT
 | 
			
		|||
        assert(failed.empty?, message(m) {failed.pretty_inspect})
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      class AllFailures
 | 
			
		||||
        attr_reader :failures
 | 
			
		||||
 | 
			
		||||
        def initialize
 | 
			
		||||
          @failures = {}
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        def for(key)
 | 
			
		||||
          yield
 | 
			
		||||
        rescue Exception => e
 | 
			
		||||
          @failures[key] = e
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      def all_assertions(msg = nil)
 | 
			
		||||
        all = AllFailures.new
 | 
			
		||||
        yield all
 | 
			
		||||
      ensure
 | 
			
		||||
        failures = all.failures
 | 
			
		||||
        assert(failures.empty?, message(msg) {mu_pp(failures)})
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      def build_message(head, template=nil, *arguments) #:nodoc:
 | 
			
		||||
        template &&= template.chomp
 | 
			
		||||
        template.gsub(/\G((?:[^\\]|\\.)*?)(\\)?\?/) { $1 + ($2 ? "?" : mu_pp(arguments.shift)) }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,15 +10,13 @@ class TestEnv < Test::Unit::TestCase
 | 
			
		|||
  ]
 | 
			
		||||
 | 
			
		||||
  def assert_invalid_env(msg = nil)
 | 
			
		||||
    failed = {}
 | 
			
		||||
    INVALID_ENVVARS.select do |v|
 | 
			
		||||
      begin
 | 
			
		||||
        assert_raise(ArgumentError) {yield v}
 | 
			
		||||
      rescue MiniTest::Assertion => e
 | 
			
		||||
        failed[v] = e
 | 
			
		||||
    all_assertions(msg) do |a|
 | 
			
		||||
      INVALID_ENVVARS.each do |v|
 | 
			
		||||
        a.for(v) do
 | 
			
		||||
          assert_raise(ArgumentError) {yield v}
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
    assert(failed.empty?, message(msg) {mu_pp(failed)})
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def setup
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -356,16 +356,12 @@ class TestRubyYieldGen < Test::Unit::TestCase
 | 
			
		|||
  end
 | 
			
		||||
 | 
			
		||||
  def assert_all_sentences(syntax, *args)
 | 
			
		||||
    fails = []
 | 
			
		||||
    syntax = Sentence.expand_syntax(syntax)
 | 
			
		||||
    Sentence.each(syntax, *args) {|t|
 | 
			
		||||
      begin
 | 
			
		||||
        yield t
 | 
			
		||||
      rescue MiniTest::Assertion => e
 | 
			
		||||
        fails << e.message
 | 
			
		||||
      end
 | 
			
		||||
    }
 | 
			
		||||
    assert(fails.empty?, proc {fails.join("\n--------\n")})
 | 
			
		||||
    all_assertions do |a|
 | 
			
		||||
      Sentence.each(syntax, *args) {|t|
 | 
			
		||||
        a.for(t) {yield t}
 | 
			
		||||
      }
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_yield
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue