determine-test-runners: add non-trivial tests

This commit is contained in:
Carlo Cabrera 2023-04-04 01:46:33 +08:00
parent 140e751ec6
commit 3dc66fae9f
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0

View File

@ -10,11 +10,15 @@ describe "brew determine-test-runners" do
end
# TODO: Generate this dynamically based on our supported macOS versions.
let(:all_runners) { %w[11 11-arm64 12 12-arm64 13 13-arm64 ubuntu-latest] }
let(:linux_runner) { "ubuntu-22.04" }
let(:all_runners) { ["11", "11-arm64", "12", "12-arm64", "13", "13-arm64", linux_runner] }
let(:intel_runners) { ["11", "12", "13", linux_runner] }
let(:arm64_runners) { %w[11-arm64 12-arm64 13-arm64] }
let(:macos_runners) { all_runners - [linux_runner] }
let(:github_output) { "#{TEST_TMPDIR}/github_output" }
let(:runner_env) do
{
"HOMEBREW_LINUX_RUNNER" => "ubuntu-latest",
"HOMEBREW_LINUX_RUNNER" => linux_runner,
"HOMEBREW_LINUX_CLEANUP" => "false",
"GITHUB_RUN_ID" => "12345",
"GITHUB_RUN_ATTEMPT" => "1",
@ -52,18 +56,90 @@ describe "brew determine-test-runners" do
expect(get_runners(github_output)).to eq(all_runners)
end
describe "--dependents" do
it "assigns no runners when a formula has no dependents", :integration_test, :needs_linux do
setup_test_formula "testball"
it "assigns `ubuntu-latest` when there are no testing formulae and no deleted formulae", :integration_test,
:needs_linux do
expect { brew "determine-test-runners", "", runner_env }
.to not_to_output.to_stdout
.and not_to_output.to_stderr
.and be_a_success
expect { brew "determine-test-runners", "--dependents", "testball", runner_env }
.to not_to_output.to_stdout
.and not_to_output.to_stderr
.and be_a_success
expect(File.read(github_output)).not_to be_empty
expect(get_runners(github_output)).to eq(["ubuntu-latest"])
end
expect(File.read(github_output)).not_to be_empty
expect(get_runners(github_output)).to be_empty
end
it "assigns only Intel runners when a formula `depends_on arch: :x86_64`", :integration_test, :needs_linux do
setup_test_formula "intel_depender", <<~RUBY
url "https://brew.sh/intel_depender-1.0.tar.gz"
depends_on arch: :x86_64
RUBY
expect { brew "determine-test-runners", "intel_depender", runner_env }
.to not_to_output.to_stdout
.and not_to_output.to_stderr
.and be_a_success
expect(File.read(github_output)).not_to be_empty
expect(get_runners(github_output)).to eq(intel_runners)
end
it "assigns only ARM64 runners when a formula `depends_on arch: :arm64`", :integration_test, :needs_linux do
setup_test_formula "fancy-m1-ml-framework", <<~RUBY
url "https://brew.sh/fancy-m1-ml-framework-1.0.tar.gz"
depends_on arch: :arm64
RUBY
expect { brew "determine-test-runners", "fancy-m1-ml-framework", runner_env }
.to not_to_output.to_stdout
.and not_to_output.to_stderr
.and be_a_success
expect(File.read(github_output)).not_to be_empty
expect(get_runners(github_output)).to eq(arm64_runners)
end
it "assigns only macOS runners when a formula `depends_on :macos`", :integration_test, :needs_linux do
setup_test_formula "xcode-helper", <<~RUBY
url "https://brew.sh/xcode-helper-1.0.tar.gz"
depends_on :macos
RUBY
expect { brew "determine-test-runners", "xcode-helper", runner_env }
.to not_to_output.to_stdout
.and not_to_output.to_stderr
.and be_a_success
expect(File.read(github_output)).not_to be_empty
expect(get_runners(github_output)).to eq(macos_runners)
end
it "assigns only Linux runners when a formula `depends_on :linux`", :integration_test, :needs_linux do
setup_test_formula "linux-kernel-requirer", <<~RUBY
url "https://brew.sh/linux-kernel-requirer-1.0.tar.gz"
depends_on :linux
RUBY
expect { brew "determine-test-runners", "linux-kernel-requirer", runner_env }
.to not_to_output.to_stdout
.and not_to_output.to_stderr
.and be_a_success
expect(File.read(github_output)).not_to be_empty
expect(get_runners(github_output)).to eq([linux_runner])
end
it "assigns only compatible runners when there is a versioned macOS requirement", :integration_test, :needs_linux do
setup_test_formula "needs-macos-13", <<~RUBY
url "https://brew.sh/needs-macos-13-1.0.tar.gz"
depends_on macos: :ventura
RUBY
expect { brew "determine-test-runners", "needs-macos-13", runner_env }
.to not_to_output.to_stdout
.and not_to_output.to_stderr
.and be_a_success
expect(File.read(github_output)).not_to be_empty
expect(get_runners(github_output)).to eq(["13", "13-arm64", linux_runner])
end
end