Skip to content

Commit c8b2f7a

Browse files
committed
Add regression specs for TestBot strict typing fixes
Test through public run! interfaces where practical (BottlesFetch, CleanupAfter); use send for deeply internal methods without a reasonable public entry point.
1 parent 471c947 commit c8b2f7a

File tree

6 files changed

+69
-14
lines changed

6 files changed

+69
-14
lines changed

Library/Homebrew/test/test_bot/bottles_fetch_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
require "dev-cmd/test-bot"
55

66
RSpec.describe Homebrew::TestBot::BottlesFetch do
7-
describe "#fetch_bottles!" do
7+
describe "#run!" do
88
it "accepts Utils::Bottles::Tag objects from the bottle collector" do
99
# Regression test: bottle_specification.collector.tags returns Utils::Bottles::Tag objects,
1010
# not Symbols. The fetch_bottles! signature must accept Tag, not Symbol.
1111
fetch = described_class.new(tap: nil, git: nil, dry_run: true, fail_fast: false, verbose: false)
12-
allow(fetch).to receive(:cleanup_during!)
12+
fetch.testing_formulae = ["some-formula"]
1313
tag = Utils::Bottles::Tag.new(system: :sequoia, arch: :arm64)
14+
allow(fetch).to receive(:formulae_by_tag).and_return({ tag => Set["some-formula"] })
15+
allow(fetch).to receive(:cleanup_during!)
1416

15-
fetch.send(:fetch_bottles!, tag, Set["some-formula"], args: instance_double(Homebrew::Cmd::TestBotCmd::Args))
17+
fetch.run!(args: instance_double(Homebrew::Cmd::TestBotCmd::Args))
1618

1719
expect(fetch.steps.last).to be_passed
1820
expect(fetch.steps.last.command).to include("--bottle-tag=#{tag}")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
require "test_bot"
4+
5+
RSpec.describe Homebrew::TestBot::Formulae do
6+
describe "#testing_portable_ruby?" do
7+
it "returns false (not nil) when tap is nil" do
8+
# Regression test: without `!!`, tap&.core_tap? returns nil when tap is nil,
9+
# and `nil && ...` evaluates to nil, violating the T::Boolean return type.
10+
Dir.mktmpdir do |tmpdir|
11+
output_paths = {
12+
bottle: Pathname.new("#{tmpdir}/bottle.txt"),
13+
linkage: Pathname.new("#{tmpdir}/linkage.txt"),
14+
skipped_or_failed_formulae: Pathname.new("#{tmpdir}/skipped.txt"),
15+
}
16+
formulae = described_class.new(
17+
tap: nil, git: "git", dry_run: true, fail_fast: false, verbose: false,
18+
output_paths:
19+
)
20+
21+
result = formulae.send(:testing_portable_ruby?)
22+
expect(result).to be(false)
23+
end
24+
end
25+
end
26+
27+
describe "#verify_local_bottles" do
28+
it "returns false (not nil) when testing portable ruby" do
29+
# Regression test: the early return for portable ruby must be `return false`,
30+
# not bare `return` (which returns nil), to satisfy the T::Boolean return type.
31+
Dir.mktmpdir do |tmpdir|
32+
output_paths = {
33+
bottle: Pathname.new("#{tmpdir}/bottle.txt"),
34+
linkage: Pathname.new("#{tmpdir}/linkage.txt"),
35+
skipped_or_failed_formulae: Pathname.new("#{tmpdir}/skipped.txt"),
36+
}
37+
formulae = described_class.new(
38+
tap: CoreTap.instance, git: "git", dry_run: true, fail_fast: false, verbose: false,
39+
output_paths:
40+
)
41+
formulae.testing_formulae = ["portable-ruby"]
42+
43+
result = formulae.send(:verify_local_bottles)
44+
expect(result).to be(false)
45+
end
46+
end
47+
end
48+
end

Library/Homebrew/test/test_bot/junit_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require "dev-cmd/test-bot"
3+
require "test_bot"
44

55
RSpec.describe Homebrew::TestBot::Junit do
66
# Regression test: Junit requires REXML before use. Without the require calls in #initialize,

Library/Homebrew/test/test_bot/test_cleanup_spec.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,38 @@
22

33
require "dev-cmd/test-bot"
44

5-
RSpec.describe Homebrew::TestBot::TestCleanup do
5+
RSpec.describe Homebrew::TestBot::CleanupAfter do
66
# Regression test: checkout_branch_if_needed, reset_if_needed, and clean_if_needed
7-
# expect a String (repository path). Passing HOMEBREW_REPOSITORY (Pathname) causes
7+
# expect a String (repository path). Passing HOMEBREW_REPOSITORY (Pathname) would cause
88
# "Parameter 'repository': Expected type String, got type Pathname" in strict typing.
9-
describe "cleanup_shared" do
9+
describe "#run!" do
1010
it "passes a String to checkout_branch_if_needed, reset_if_needed, and clean_if_needed when tap is set" do
1111
cleanup = described_class.new(
1212
tap: CoreTap.instance,
1313
git: "git",
14-
dry_run: false,
14+
dry_run: true,
1515
fail_fast: false,
1616
verbose: false,
1717
)
1818

19-
# Stub so we reach the "if tap" block without running git or deleting files.
20-
allow(cleanup).to receive(:repository).and_return(Pathname.new("/nonexistent_brew_repo_#{SecureRandom.hex(8)}"))
19+
# Stub to avoid actual filesystem and process operations.
20+
allow(FileUtils).to receive(:chmod_R)
2121
allow(cleanup).to receive(:info_header)
2222
allow(cleanup).to receive(:delete_or_move)
23+
allow(cleanup).to receive(:test)
24+
allow(cleanup).to receive_messages(repository: Pathname.new("/nonexistent_#{SecureRandom.hex(8)}"),
25+
quiet_system: false)
2326
allow(Keg).to receive(:must_be_writable_directories).and_return([])
2427
allow(Pathname).to receive(:glob).and_return([])
25-
allow(cleanup).to receive(:test)
2628

2729
expect(cleanup).to receive(:checkout_branch_if_needed).with(String)
2830
expect(cleanup).to receive(:reset_if_needed).with(String)
2931
expect(cleanup).to receive(:clean_if_needed).with(String)
3032

31-
cleanup.send(:cleanup_shared)
33+
args = double(test_default_formula?: false, local?: false)
34+
with_env("HOMEBREW_GITHUB_ACTIONS" => nil, "GITHUB_ACTIONS" => nil) do
35+
cleanup.run!(args:)
36+
end
3237
end
3338
end
3439
end

Library/Homebrew/test/test_bot/test_formulae_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require "dev-cmd/test-bot"
3+
require "test_bot"
44
require "utils/github/artifacts"
55

66
RSpec.describe Homebrew::TestBot::TestFormulae do

Library/Homebrew/test_bot/bottles_fetch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# typed: true # rubocop:todo Sorbet/StrictSigil
1+
# typed: strict
22
# frozen_string_literal: true
33

44
module Homebrew

0 commit comments

Comments
 (0)