tests: use unique identifiers w/ integration tests
Commands executed during integration testing are executed in a separate process and thus generate a new result set for each command. To avoid that these results override each other, they need to have a unique `command_name`. Derive this name from the test class/name and the index of the command inside that test, resulting in identifiers like `IntegrationCommandTests#test_prefix.1 brew --prefix`. Also replaces `TEST_TMPDIR` in the arguments with `"@TMPDIR@"` to get a cleaner command identifier that is independent of the temporary directory that changes with every run.
This commit is contained in:
		
							parent
							
								
									5786f36b62
								
							
						
					
					
						commit
						274640c97a
					
				@ -13,8 +13,8 @@ SimpleCov.start do
 | 
			
		||||
  add_filter "Homebrew/vendor/"
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if name = ENV["HOMEBREW_INTEGRATION_TEST"]
 | 
			
		||||
  SimpleCov.command_name "brew #{name}"
 | 
			
		||||
if ENV["HOMEBREW_INTEGRATION_TEST"]
 | 
			
		||||
  SimpleCov.command_name ENV["HOMEBREW_INTEGRATION_TEST"]
 | 
			
		||||
  SimpleCov.at_exit do
 | 
			
		||||
    exit_code = $!.nil? ? 0 : $!.status
 | 
			
		||||
    $stdout.reopen("/dev/null")
 | 
			
		||||
 | 
			
		||||
@ -4,6 +4,16 @@ require "core_formula_repository"
 | 
			
		||||
require "fileutils"
 | 
			
		||||
 | 
			
		||||
class IntegrationCommandTests < Homebrew::TestCase
 | 
			
		||||
  def setup
 | 
			
		||||
    @cmd_id_index = 0 # Assign unique IDs to invocations of `cmd_output`.
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def cmd_id_from_args(args)
 | 
			
		||||
    args_pretty = args.join(" ").gsub(TEST_TMPDIR, "@TMPDIR@")
 | 
			
		||||
    test_pretty = "#{self.class.name}\##{name}.#{@cmd_id_index += 1}"
 | 
			
		||||
    "[#{test_pretty}] brew #{args_pretty}"
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def cmd_output(*args)
 | 
			
		||||
    # 1.8-compatible way of writing def cmd_output(*args, **env)
 | 
			
		||||
    env = args.last.is_a?(Hash) ? args.pop : {}
 | 
			
		||||
@ -18,7 +28,7 @@ class IntegrationCommandTests < Homebrew::TestCase
 | 
			
		||||
    cmd_args += args
 | 
			
		||||
    Bundler.with_original_env do
 | 
			
		||||
      ENV["HOMEBREW_BREW_FILE"] = HOMEBREW_PREFIX/"bin/brew"
 | 
			
		||||
      ENV["HOMEBREW_INTEGRATION_TEST"] = args.join " "
 | 
			
		||||
      ENV["HOMEBREW_INTEGRATION_TEST"] = cmd_id_from_args(args)
 | 
			
		||||
      ENV["HOMEBREW_TEST_TMPDIR"] = TEST_TMPDIR
 | 
			
		||||
      env.each_pair { |k,v| ENV[k] = v }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user