| 
									
										
										
										
											2023-04-03 22:42:00 +08:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-04 00:05:29 +08:00
										 |  |  | require "dev-cmd/determine-test-runners" | 
					
						
							| 
									
										
										
										
											2023-04-03 22:42:00 +08:00
										 |  |  | require "cmd/shared_examples/args_parse" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 08:10:59 -07:00
										 |  |  | RSpec.describe Homebrew::DevCmd::DetermineTestRunners do | 
					
						
							| 
									
										
										
										
											2024-01-26 11:36:08 -08:00
										 |  |  |   def get_runners(file) | 
					
						
							|  |  |  |     runner_line = File.open(file).first | 
					
						
							|  |  |  |     json_text = runner_line[/runners=(.*)/, 1] | 
					
						
							|  |  |  |     runner_hash = JSON.parse(json_text) | 
					
						
							|  |  |  |     runner_hash.map { |item| item["runner"].delete_suffix(ephemeral_suffix) } | 
					
						
							|  |  |  |                .sort | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-04 01:12:05 +08:00
										 |  |  |   after do | 
					
						
							|  |  |  |     FileUtils.rm_f github_output | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2023-04-04 00:05:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-04 01:46:33 +08:00
										 |  |  |   let(:linux_runner) { "ubuntu-22.04" } | 
					
						
							| 
									
										
										
										
											2023-04-04 12:15:23 +08:00
										 |  |  |   # We need to make sure we write to a different path for each example. | 
					
						
							| 
									
										
										
										
											2023-04-04 13:20:03 +08:00
										 |  |  |   let(:github_output) { "#{TEST_TMPDIR}/github_output#{DetermineRunnerTestHelper.new.number}" } | 
					
						
							| 
									
										
										
										
											2023-05-29 23:04:58 +08:00
										 |  |  |   let(:ephemeral_suffix) { "-12345" } | 
					
						
							| 
									
										
										
										
											2023-04-04 01:12:05 +08:00
										 |  |  |   let(:runner_env) do | 
					
						
							| 
									
										
										
										
											2023-04-04 00:05:29 +08:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-05-12 04:38:16 +08:00
										 |  |  |       "HOMEBREW_LINUX_RUNNER"       => linux_runner, | 
					
						
							|  |  |  |       "HOMEBREW_MACOS_LONG_TIMEOUT" => "false", | 
					
						
							|  |  |  |       "GITHUB_RUN_ID"               => ephemeral_suffix.split("-").second, | 
					
						
							| 
									
										
										
										
											2023-04-04 02:28:56 +08:00
										 |  |  |     }.freeze | 
					
						
							| 
									
										
										
										
											2023-04-04 00:05:29 +08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2023-04-07 22:21:46 +08:00
										 |  |  |   let(:all_runners) do | 
					
						
							|  |  |  |     out = [] | 
					
						
							| 
									
										
										
										
											2023-05-09 02:15:28 +02:00
										 |  |  |     MacOSVersion::SYMBOLS.each_value do |v| | 
					
						
							|  |  |  |       macos_version = MacOSVersion.new(v) | 
					
						
							| 
									
										
										
										
											2023-04-07 22:21:46 +08:00
										 |  |  |       next if macos_version.unsupported_release? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-12 02:09:37 +08:00
										 |  |  |       out << "#{v}-x86_64" | 
					
						
							| 
									
										
										
										
											2023-04-07 22:21:46 +08:00
										 |  |  |       out << "#{v}-arm64" | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2023-04-04 00:05:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-07 22:21:46 +08:00
										 |  |  |     out << linux_runner | 
					
						
							| 
									
										
										
										
											2023-04-04 01:12:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-07 22:21:46 +08:00
										 |  |  |     out | 
					
						
							| 
									
										
										
										
											2023-04-04 00:05:29 +08:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-07 22:21:46 +08:00
										 |  |  |   it_behaves_like "parseable arguments" | 
					
						
							| 
									
										
										
										
											2023-04-04 02:28:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-04 13:54:35 +08:00
										 |  |  |   it "assigns all runners for formulae without any requirements", :integration_test do | 
					
						
							| 
									
										
										
										
											2023-04-04 00:05:29 +08:00
										 |  |  |     setup_test_formula "testball" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-04 12:15:23 +08:00
										 |  |  |     expect { brew "determine-test-runners", "testball", runner_env.merge({ "GITHUB_OUTPUT" => github_output }) } | 
					
						
							| 
									
										
										
										
											2023-04-29 11:36:31 +08:00
										 |  |  |       .to not_to_output.to_stderr | 
					
						
							| 
									
										
										
										
											2023-04-04 00:05:29 +08:00
										 |  |  |       .and be_a_success | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(File.read(github_output)).not_to be_empty | 
					
						
							| 
									
										
										
										
											2023-04-07 22:21:46 +08:00
										 |  |  |     expect(get_runners(github_output).sort).to eq(all_runners.sort) | 
					
						
							| 
									
										
										
										
											2023-04-04 13:54:35 +08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2023-04-04 00:05:29 +08:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-04 13:20:03 +08:00
										 |  |  | class DetermineRunnerTestHelper | 
					
						
							| 
									
										
										
										
											2023-04-04 12:15:23 +08:00
										 |  |  |   @instances = 0
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class << self | 
					
						
							|  |  |  |     attr_accessor :instances | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   attr_reader :number | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def initialize | 
					
						
							|  |  |  |     self.class.instances += 1
 | 
					
						
							|  |  |  |     @number = self.class.instances | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |