Skip to content

Commit 0cc7fc6

Browse files
authored
Merge pull request #21177 from Homebrew/test-reinstall-with-bottle
test/cmd: use bottle pour for faster test run
2 parents a4ebb86 + 9b2f3bf commit 0cc7fc6

File tree

6 files changed

+152
-120
lines changed

6 files changed

+152
-120
lines changed

Library/Homebrew/test/cmd/install_spec.rb

Lines changed: 103 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -6,98 +6,118 @@
66
RSpec.describe Homebrew::Cmd::InstallCmd do
77
include FileUtils
88

9-
let(:testball1_rack) { HOMEBREW_CELLAR/"testball1" }
10-
119
it_behaves_like "parseable arguments"
1210

13-
it "installs a Formula", :integration_test do
14-
setup_test_formula "testball1"
15-
16-
expect { brew "install", "testball1" }
17-
.to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}o).to_stdout
18-
.and output(/✔︎.*/m).to_stderr
19-
.and be_a_success
20-
expect(testball1_rack/"0.1/foo/test").not_to be_a_file
21-
22-
uninstall_test_formula "testball1"
23-
24-
expect { brew "install", "testball1", "--with-foo" }
25-
.to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}o).to_stdout
26-
.and output(/✔︎.*/m).to_stderr
27-
.and be_a_success
28-
expect(testball1_rack/"0.1/foo/test").to be_a_file
29-
30-
uninstall_test_formula "testball1"
31-
32-
expect { brew "install", "testball1", "--debug-symbols", "--build-from-source" }
33-
.to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}o).to_stdout
34-
.and output(/✔︎.*/m).to_stderr
35-
.and be_a_success
36-
expect(testball1_rack/"0.1/bin/test").to be_a_file
37-
expect(testball1_rack/"0.1/bin/test.dSYM/Contents/Resources/DWARF/test").to be_a_file if OS.mac?
38-
expect(HOMEBREW_CACHE/"Sources/testball1").to be_a_directory
39-
40-
uninstall_test_formula "testball1"
41-
42-
expect { brew "install", "--ask", "testball1" }
43-
.to output(/.*Formula\s*\(1\):\s*testball1.*/).to_stdout
44-
.and output(/✔︎.*/m).to_stderr
45-
.and be_a_success
46-
expect(testball1_rack/"0.1/bin/test").to be_a_file
47-
48-
uninstall_test_formula "testball1"
11+
context "when using a bottle" do
12+
let(:formula_name) { "testball_bottle" }
13+
let(:formula_prefix) { HOMEBREW_CELLAR/formula_name/"0.1" }
14+
let(:formula_prefix_regex) { /#{Regexp.escape(formula_prefix)}/o }
15+
let(:option_file) { formula_prefix/"foo/test" }
16+
let(:bottle_file) { formula_prefix/"bin/helloworld" }
17+
18+
it "installs a Formula", :integration_test do
19+
setup_test_formula formula_name
20+
21+
expect { brew "install", formula_name }
22+
.to output(formula_prefix_regex).to_stdout
23+
.and output(/✔︎.*/m).to_stderr
24+
.and be_a_success
25+
expect(option_file).not_to be_a_file
26+
expect(bottle_file).to be_a_file
27+
28+
uninstall_test_formula formula_name
29+
30+
expect { brew "install", "--ask", formula_name }
31+
.to output(/.*Formula\s*\(1\):\s*#{formula_name}.*/).to_stdout
32+
.and output(/✔︎.*/m).to_stderr
33+
.and be_a_success
34+
expect(option_file).not_to be_a_file
35+
expect(bottle_file).to be_a_file
36+
37+
uninstall_test_formula formula_name
38+
39+
expect { brew "install", formula_name, { "HOMEBREW_FORBIDDEN_FORMULAE" => formula_name } }
40+
.to not_to_output(formula_prefix_regex).to_stdout
41+
.and output(/#{formula_name} was forbidden/).to_stderr
42+
.and be_a_failure
43+
expect(formula_prefix).not_to exist
44+
end
4945

50-
expect { brew "install", "testball1", { "HOMEBREW_FORBIDDEN_FORMULAE" => "testball1" } }
51-
.to not_to_output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}o).to_stdout
52-
.and output(/testball1 was forbidden/).to_stderr
53-
.and be_a_failure
54-
expect(testball1_rack).not_to exist
46+
it "installs a keg-only Formula", :integration_test do
47+
setup_test_formula formula_name, <<~RUBY
48+
keg_only "test reason"
49+
RUBY
50+
51+
expect { brew "install", formula_name }
52+
.to output(formula_prefix_regex).to_stdout
53+
.and output(/✔︎.*/m).to_stderr
54+
.and be_a_success
55+
expect(option_file).not_to be_a_file
56+
expect(bottle_file).to be_a_file
57+
expect(HOMEBREW_PREFIX/"bin/helloworld").not_to be_a_file
58+
end
5559
end
5660

57-
it "installs a keg-only Formula", :integration_test do
58-
setup_test_formula "testball1", <<~RUBY
59-
version "1.0"
60-
61-
keg_only "test reason"
62-
RUBY
61+
context "when building from source" do
62+
let(:formula_name) { "testball1" }
63+
64+
it "installs a Formula", :integration_test do
65+
formula_prefix = HOMEBREW_CELLAR/formula_name/"0.1"
66+
formula_prefix_regex = /#{Regexp.escape(formula_prefix)}/o
67+
option_file = formula_prefix/"foo/test"
68+
always_built_file = formula_prefix/"bin/test"
69+
70+
setup_test_formula formula_name
71+
72+
expect { brew "install", formula_name, "--with-foo" }
73+
.to output(formula_prefix_regex).to_stdout
74+
.and output(/✔︎.*/m).to_stderr
75+
.and be_a_success
76+
expect(option_file).to be_a_file
77+
expect(always_built_file).to be_a_file
78+
79+
uninstall_test_formula formula_name
80+
81+
expect { brew "install", formula_name, "--debug-symbols", "--build-from-source" }
82+
.to output(formula_prefix_regex).to_stdout
83+
.and output(/✔︎.*/m).to_stderr
84+
.and be_a_success
85+
expect(option_file).not_to be_a_file
86+
expect(always_built_file).to be_a_file
87+
expect(formula_prefix/"bin/test.dSYM/Contents/Resources/DWARF/test").to be_a_file if OS.mac?
88+
expect(HOMEBREW_CACHE/"Sources/#{formula_name}").to be_a_directory
89+
end
6390

64-
expect { brew "install", "testball1" }
65-
.to output(%r{#{testball1_rack}/1\.0}o).to_stdout
66-
.and output(/✔︎.*/m).to_stderr
67-
.and be_a_success
68-
expect(testball1_rack/"1.0/foo/test").not_to be_a_file
69-
end
91+
it "installs a HEAD Formula", :integration_test do
92+
testball1_prefix = HOMEBREW_CELLAR/"testball1/HEAD-d5eb689"
93+
repo_path = HOMEBREW_CACHE/"repo"
94+
(repo_path/"bin").mkpath
95+
96+
repo_path.cd do
97+
system "git", "-c", "init.defaultBranch=master", "init"
98+
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
99+
FileUtils.touch "bin/something.bin"
100+
FileUtils.touch "README"
101+
system "git", "add", "--all"
102+
system "git", "commit", "-m", "Initial repo commit"
103+
end
70104

71-
it "installs a HEAD Formula", :integration_test do
72-
repo_path = HOMEBREW_CACHE/"repo"
73-
(repo_path/"bin").mkpath
74-
75-
repo_path.cd do
76-
system "git", "-c", "init.defaultBranch=master", "init"
77-
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
78-
FileUtils.touch "bin/something.bin"
79-
FileUtils.touch "README"
80-
system "git", "add", "--all"
81-
system "git", "commit", "-m", "Initial repo commit"
82-
end
105+
setup_test_formula "testball1", <<~RUBY
106+
version "1.0"
83107
84-
setup_test_formula "testball1", <<~RUBY
85-
version "1.0"
108+
head "file://#{repo_path}", using: :git
86109
87-
head "file://#{repo_path}", :using => :git
110+
def install
111+
prefix.install Dir["*"]
112+
end
113+
RUBY
88114

89-
def install
90-
prefix.install Dir["*"]
91-
end
92-
RUBY
93-
94-
# Ignore dependencies, because we'll try to resolve requirements in build.rb
95-
# and there will be the git requirement, but we cannot instantiate git
96-
# formula since we only have testball1 formula.
97-
expect { brew "install", "testball1", "--HEAD", "--ignore-dependencies", "HOMEBREW_DOWNLOAD_CONCURRENCY" => "1" }
98-
.to output(%r{#{testball1_rack}/HEAD-d5eb689}o).to_stdout
99-
.and output(/Cloning into/).to_stderr
100-
.and be_a_success
101-
expect(testball1_rack/"HEAD-d5eb689/foo/test").not_to be_a_file
115+
expect { brew "install", formula_name, "--HEAD", "HOMEBREW_DOWNLOAD_CONCURRENCY" => "1" }
116+
.to output(/#{Regexp.escape(testball1_prefix)}/o).to_stdout
117+
.and output(/Cloning into/).to_stderr
118+
.and be_a_success
119+
expect(testball1_prefix/"foo/test").not_to be_a_file
120+
expect(testball1_prefix/"bin/something.bin").to be_a_file
121+
end
102122
end
103123
end

Library/Homebrew/test/cmd/reinstall_spec.rb

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,35 @@
88
it_behaves_like "parseable arguments"
99

1010
it "reinstalls a Formula", :aggregate_failures, :integration_test do
11-
setup_test_formula "testball", tab_attributes: { installed_on_request: true }
11+
formula_name = "testball_bottle"
12+
formula_prefix = HOMEBREW_CELLAR/formula_name/"0.1"
13+
formula_bin = formula_prefix/"bin"
1214

13-
testball_bin = HOMEBREW_CELLAR/"testball/0.1/bin"
14-
expect(testball_bin).not_to exist
15+
setup_test_formula formula_name, tab_attributes: { installed_on_request: true }
16+
Keg.new(formula_prefix).link
1517

16-
expect { brew "reinstall", "testball" }
17-
.to output(/Reinstalling testball/).to_stdout
18+
expect(formula_bin).not_to exist
19+
20+
expect { brew "reinstall", formula_name }
21+
.to output(/Reinstalling #{formula_name}/).to_stdout
1822
.and output(/✔︎.*/m).to_stderr
1923
.and be_a_success
20-
expect(testball_bin).to exist
24+
expect(formula_bin).to exist
2125

22-
FileUtils.rm_r(testball_bin)
26+
FileUtils.rm_r(formula_bin)
2327

24-
expect { brew "reinstall", "--ask", "testball" }
25-
.to output(/.*Formula\s*\(1\):\s*testball.*/).to_stdout
28+
expect { brew "reinstall", "--ask", formula_name }
29+
.to output(/.*Formula\s*\(1\):\s*#{formula_name}.*/).to_stdout
2630
.and output(/✔︎.*/m).to_stderr
2731
.and be_a_success
28-
expect(testball_bin).to exist
32+
expect(formula_bin).to exist
2933

30-
FileUtils.rm_r(testball_bin)
34+
FileUtils.rm_r(formula_bin)
3135

32-
expect { brew "reinstall", "testball", { "HOMEBREW_FORBIDDEN_FORMULAE" => "testball" } }
33-
.to not_to_output(%r{#{HOMEBREW_CELLAR}/testball/0\.1}o).to_stdout
34-
.and output(/testball was forbidden/).to_stderr
36+
expect { brew "reinstall", formula_name, { "HOMEBREW_FORBIDDEN_FORMULAE" => formula_name } }
37+
.to not_to_output(/#{Regexp.escape(formula_prefix)}/o).to_stdout
38+
.and output(/#{formula_name} was forbidden/).to_stderr
3539
.and be_a_failure
36-
37-
expect(testball_bin).not_to exist
40+
expect(formula_bin).not_to exist
3841
end
3942
end

Library/Homebrew/test/cmd/upgrade_spec.rb

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,51 @@
1010
it_behaves_like "parseable arguments"
1111

1212
it "upgrades a Formula", :integration_test do
13-
setup_test_formula "testball"
13+
formula_name = "testball_bottle"
14+
formula_rack = HOMEBREW_CELLAR/formula_name
1415

15-
testball_rack = HOMEBREW_CELLAR/"testball"
16+
setup_test_formula formula_name
1617

17-
(testball_rack/"0.0.1/foo").mkpath
18+
(formula_rack/"0.0.1/foo").mkpath
1819

1920
expect { brew "upgrade" }.to be_a_success
2021

21-
expect(testball_rack/"0.1").to be_a_directory
22-
expect(testball_rack/"0.0.1").not_to exist
22+
expect(formula_rack/"0.1").to be_a_directory
23+
expect(formula_rack/"0.0.1").not_to exist
2324

24-
uninstall_test_formula "testball"
25+
uninstall_test_formula formula_name
2526

2627
# links newer version when upgrade was interrupted
27-
(testball_rack/"0.1/foo").mkpath
28+
(formula_rack/"0.1/foo").mkpath
2829

2930
expect { brew "upgrade" }.to be_a_success
3031

31-
expect(testball_rack/"0.1").to be_a_directory
32-
expect(HOMEBREW_PREFIX/"opt/testball").to be_a_symlink
33-
expect(HOMEBREW_PREFIX/"var/homebrew/linked/testball").to be_a_symlink
32+
expect(formula_rack/"0.1").to be_a_directory
33+
expect(HOMEBREW_PREFIX/"opt/#{formula_name}").to be_a_symlink
34+
expect(HOMEBREW_PREFIX/"var/homebrew/linked/#{formula_name}").to be_a_symlink
3435

35-
uninstall_test_formula "testball"
36+
uninstall_test_formula formula_name
3637

3738
# upgrades with asking for user prompts
38-
(testball_rack/"0.0.1/foo").mkpath
39+
(formula_rack/"0.0.1/foo").mkpath
3940

4041
expect { brew "upgrade", "--ask" }
41-
.to output(/.*Formula\s*\(1\):\s*testball.*/).to_stdout
42+
.to output(/.*Formula\s*\(1\):\s*#{formula_name}.*/).to_stdout
4243
.and output(/✔︎.*/m).to_stderr
4344

44-
expect(testball_rack/"0.1").to be_a_directory
45-
expect(testball_rack/"0.0.1").not_to exist
45+
expect(formula_rack/"0.1").to be_a_directory
46+
expect(formula_rack/"0.0.1").not_to exist
4647

47-
uninstall_test_formula "testball"
48+
uninstall_test_formula formula_name
4849

4950
# refuses to upgrade a forbidden formula
50-
(testball_rack/"0.0.1/foo").mkpath
51+
(formula_rack/"0.0.1/foo").mkpath
5152

52-
expect { brew "upgrade", "testball", { "HOMEBREW_FORBIDDEN_FORMULAE" => "testball" } }
53-
.to not_to_output(%r{#{HOMEBREW_CELLAR}/testball/0\.1}o).to_stdout
54-
.and output(/testball was forbidden/).to_stderr
53+
expect { brew "upgrade", formula_name, { "HOMEBREW_FORBIDDEN_FORMULAE" => formula_name } }
54+
.to not_to_output(%r{#{formula_rack}/0\.1}o).to_stdout
55+
.and output(/#{formula_name} was forbidden/).to_stderr
5556
.and be_a_failure
56-
expect(testball_rack/"0.1").not_to exist
57+
expect(formula_rack/"0.1").not_to exist
5758
end
5859

5960
it_behaves_like "reinstall_pkgconf_if_needed"

Library/Homebrew/test/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
HOMEBREW_LOCKS,
6767
HOMEBREW_LOGS,
6868
HOMEBREW_TEMP,
69+
HOMEBREW_TEMP_CELLAR,
6970
HOMEBREW_ALIASES,
7071
].freeze
7172

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
testball_bottle-0.1.yosemite.bottle.tar.gz

Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ def setup_test_formula(name, content = nil, tap: CoreTap.instance,
144144
else
145145
TEST_FIXTURE_DIR/"tarballs/#{prefix}-0.1.tbz"
146146
end
147+
bottle_block ||= <<~RUBY if name == "testball_bottle"
148+
bottle do
149+
root_url "file://#{TEST_FIXTURE_DIR}/bottles"
150+
sha256 cellar: :any_skip_relocation, all: "d7b9f4e8bf83608b71fe958a99f19f2e5e68bb2582965d32e41759c24f1aef97"
151+
end
152+
RUBY
147153
content = <<~RUBY
148154
desc "Some test"
149155
homepage "https://brew.sh/#{name}"

0 commit comments

Comments
 (0)