2024-07-04 23:59:32 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# typed: strict
							 | 
						
					
						
							
								
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# frozen_string_literal: true
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-27 10:34:22 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								module Homebrew
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-17 05:15:22 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  # Helper functions available in formula `test` blocks.
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-27 10:34:22 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  module Assertions
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-02 14:32:31 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    include Context
							 | 
						
					
						
							
								
									
										
										
										
											2024-08-20 19:10:14 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    extend T::Helpers
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    requires_ancestor { Kernel }
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-02 14:32:31 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-24 18:01:47 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    require "minitest"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    require "minitest/assertions"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    include ::Minitest::Assertions
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-04 23:59:32 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    sig { params(assertions: Integer).returns(Integer) }
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-24 18:01:47 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    attr_writer :assertions
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-04 23:59:32 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    sig { returns(Integer) }
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-24 18:01:47 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    def assertions
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-04 23:59:32 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      @assertions ||= T.let(0, T.nilable(Integer))
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-24 18:01:47 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-30 11:10:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    # Returns the output of running cmd and asserts the exit status.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    #
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-17 05:15:22 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    # @api public
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-12 16:28:35 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    sig { params(cmd: T.any(Pathname, String), result: Integer).returns(String) }
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    def shell_output(cmd, result = 0)
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-29 21:59:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      ohai cmd
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-27 10:34:22 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      output = `#{cmd}`
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-10 20:12:55 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      assert_equal result, $CHILD_STATUS.exitstatus
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-27 10:34:22 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      output
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-24 18:01:47 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    rescue Minitest::Assertion
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-02 14:32:31 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      puts output if verbose?
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-10 09:21:30 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      raise
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-27 10:34:22 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-30 11:10:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    # Returns the output of running the cmd with the optional input and
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-17 05:15:22 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    # optionally asserts the exit status.
							 | 
						
					
						
							
								
									
										
										
										
											2024-04-30 11:10:23 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    #
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-17 05:15:22 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    # @api public
							 | 
						
					
						
							
								
									
										
										
										
											2024-07-16 22:07:31 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    sig { params(cmd: T.any(String, Pathname), input: T.nilable(String), result: T.nilable(Integer)).returns(String) }
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    def pipe_output(cmd, input = nil, result = nil)
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-29 21:59:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      ohai cmd
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-19 10:20:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      output = IO.popen(cmd, "w+") do |pipe|
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-27 10:34:22 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        pipe.write(input) unless input.nil?
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        pipe.close_write
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        pipe.read
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      end
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-10 20:12:55 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      assert_equal result, $CHILD_STATUS.exitstatus unless result.nil?
							 | 
						
					
						
							
								
									
										
										
										
											2015-01-19 10:20:49 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      output
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-24 18:01:47 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    rescue Minitest::Assertion
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-02 14:32:31 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      puts output if verbose?
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-10 09:21:30 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      raise
							 | 
						
					
						
							
								
									
										
										
										
											2014-07-27 10:34:22 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								end
							 |