add helpers for formula tests
This commit is contained in:
		
							parent
							
								
									f4ae1c9e1b
								
							
						
					
					
						commit
						c003e805be
					
				@ -25,6 +25,8 @@ module Homebrew
 | 
				
			|||||||
    FailedAssertion = Test::Unit::AssertionFailedError
 | 
					    FailedAssertion = Test::Unit::AssertionFailedError
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  require "formula_assertions"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def test
 | 
					  def test
 | 
				
			||||||
    raise FormulaUnspecifiedError if ARGV.named.empty?
 | 
					    raise FormulaUnspecifiedError if ARGV.named.empty?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -47,6 +49,7 @@ module Homebrew
 | 
				
			|||||||
      puts "Testing #{f.name}"
 | 
					      puts "Testing #{f.name}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      f.extend(Test::Unit::Assertions)
 | 
					      f.extend(Test::Unit::Assertions)
 | 
				
			||||||
 | 
					      f.extend(Homebrew::Assertions)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      begin
 | 
					      begin
 | 
				
			||||||
        # tests can also return false to indicate failure
 | 
					        # tests can also return false to indicate failure
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										23
									
								
								Library/Homebrew/formula_assertions.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								Library/Homebrew/formula_assertions.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					require 'test/unit/assertions'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module Homebrew
 | 
				
			||||||
 | 
					  module Assertions
 | 
				
			||||||
 | 
					    include Test::Unit::Assertions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Returns the output of running cmd, and asserts the exit status
 | 
				
			||||||
 | 
					    def shell_output(cmd, result=0)
 | 
				
			||||||
 | 
					      output = `#{cmd}`
 | 
				
			||||||
 | 
					      assert_equal result, $?.exitstatus
 | 
				
			||||||
 | 
					      output
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Returns the output of running the cmd, with the optional input
 | 
				
			||||||
 | 
					    def pipe_output(cmd, input=nil)
 | 
				
			||||||
 | 
					      IO.popen(cmd, "w+") do |pipe|
 | 
				
			||||||
 | 
					        pipe.write(input) unless input.nil?
 | 
				
			||||||
 | 
					        pipe.close_write
 | 
				
			||||||
 | 
					        pipe.read
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user