Merge pull request #10148 from SeekingMeaning/bottle-spec-reformat

bottle_spec: more cleanup
This commit is contained in:
Mike McQuaid 2020-12-28 09:20:01 +00:00 committed by GitHub
commit 47c584545d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 182 additions and 216 deletions

View File

@ -76,9 +76,7 @@ describe Homebrew do
subject(:homebrew) { described_class }
let(:hello_hash_big_sur) {
JSON.parse(
stub_hash(
{
JSON.parse stub_hash(
"name": "hello",
"version": "1.0",
"path": "/home/hello.rb",
@ -87,14 +85,10 @@ describe Homebrew do
"filename": "hello-1.0.big_sur.bottle.tar.gz",
"local_filename": "hello--1.0.big_sur.bottle.tar.gz",
"sha256": "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f",
},
),
)
}
let(:hello_hash_catalina) {
JSON.parse(
stub_hash(
{
JSON.parse stub_hash(
"name": "hello",
"version": "1.0",
"path": "/home/hello.rb",
@ -103,14 +97,10 @@ describe Homebrew do
"filename": "hello-1.0.catalina.bottle.tar.gz",
"local_filename": "hello--1.0.catalina.bottle.tar.gz",
"sha256": "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac",
},
),
)
}
let(:unzip_hash_big_sur) {
JSON.parse(
stub_hash(
{
JSON.parse stub_hash(
"name": "unzip",
"version": "2.0",
"path": "/home/unzip.rb",
@ -119,14 +109,10 @@ describe Homebrew do
"filename": "unzip-2.0.big_sur.bottle.tar.gz",
"local_filename": "unzip--2.0.big_sur.bottle.tar.gz",
"sha256": "16cf230afdfcb6306c208d169549cf8773c831c8653d2c852315a048960d7e72",
},
),
)
}
let(:unzip_hash_catalina) {
JSON.parse(
stub_hash(
{
JSON.parse stub_hash(
"name": "unzip",
"version": "2.0",
"path": "/home/unzip.rb",
@ -135,16 +121,12 @@ describe Homebrew do
"filename": "unzip-2.0.catalina.bottle.tar.gz",
"local_filename": "unzip--2.0.catalina.bottle.tar.gz",
"sha256": "d9cc50eec8ac243148a121049c236cba06af4a0b1156ab397d0a2850aa79c137",
},
),
)
}
specify "::parse_json_files" do
Tempfile.open("hello--1.0.big_sur.bottle.json") do |f|
f.write(
stub_hash(
{
f.write stub_hash(
"name": "hello",
"version": "1.0",
"path": "/home/hello.rb",
@ -153,8 +135,6 @@ describe Homebrew do
"filename": "hello-1.0.big_sur.bottle.tar.gz",
"local_filename": "hello--1.0.big_sur.bottle.tar.gz",
"sha256": "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f",
},
),
)
f.close
expect(
@ -206,7 +186,7 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
end
before do
Pathname("testball-1.0.big_sur.bottle.json").write stub_hash(
Pathname("#{TEST_TMPDIR}/testball-1.0.big_sur.bottle.json").write stub_hash(
"name": "testball",
"version": "1.0",
"path": "#{core_tap.path}/Formula/testball.rb",
@ -217,7 +197,7 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
"sha256": "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f",
)
Pathname("testball-1.0.catalina.bottle.json").write stub_hash(
Pathname("#{TEST_TMPDIR}/testball-1.0.catalina.bottle.json").write stub_hash(
"name": "testball",
"version": "1.0",
"path": "#{core_tap.path}/Formula/testball.rb",
@ -230,8 +210,8 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
end
after do
FileUtils.rm_f "testball-1.0.catalina.bottle.json"
FileUtils.rm_f "testball-1.0.big_sur.bottle.json"
FileUtils.rm_f "#{TEST_TMPDIR}/testball-1.0.catalina.bottle.json"
FileUtils.rm_f "#{TEST_TMPDIR}/testball-1.0.big_sur.bottle.json"
end
it "adds the bottle block to a formula that has none" do
@ -246,10 +226,9 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
brew "bottle",
"--merge",
"--write",
"testball-1.0.big_sur.bottle.json",
"testball-1.0.catalina.bottle.json"
}.to output(
<<~EOS,
"#{TEST_TMPDIR}/testball-1.0.big_sur.bottle.json",
"#{TEST_TMPDIR}/testball-1.0.catalina.bottle.json"
}.to output(<<~EOS).to_stdout
==> testball
bottle do
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
@ -258,10 +237,8 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina
end
EOS
).to_stdout
expect((core_tap.path/"Formula/testball.rb").read).to eq(
<<~EOS,
expect((core_tap.path/"Formula/testball.rb").read).to eq <<~EOS
class Testball < Formula
desc "Some test"
homepage "https://brew.sh/testball"
@ -292,13 +269,12 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
end
EOS
)
end
it "replaces the bottle block in a formula that already has a bottle block" do
core_tap.path.cd do
system "git", "init"
bottle_block = <<~EOS
setup_test_formula "testball", bottle_block: <<~EOS
bottle do
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
@ -307,7 +283,6 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
sha256 "16cf230afdfcb6306c208d169549cf8773c831c8653d2c852315a048960d7e72" => :catalina
end
EOS
setup_test_formula("testball", "", bottle_block)
system "git", "add", "--all"
system "git", "commit", "-m", "testball 0.1"
end
@ -316,10 +291,9 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
brew "bottle",
"--merge",
"--write",
"testball-1.0.big_sur.bottle.json",
"testball-1.0.catalina.bottle.json"
}.to output(
<<~EOS,
"#{TEST_TMPDIR}/testball-1.0.big_sur.bottle.json",
"#{TEST_TMPDIR}/testball-1.0.catalina.bottle.json"
}.to output(<<~EOS).to_stdout
==> testball
bottle do
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
@ -328,10 +302,8 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina
end
EOS
).to_stdout
expect((core_tap.path/"Formula/testball.rb").read).to eq(
<<~EOS,
expect((core_tap.path/"Formula/testball.rb").read).to eq <<~EOS
class Testball < Formula
desc "Some test"
homepage "https://brew.sh/testball"
@ -362,7 +334,6 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
end
EOS
)
end
it "fails to add the bottle block to a formula that has no bottle block when using --keep-old" do
@ -378,15 +349,15 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
"--merge",
"--write",
"--keep-old",
"testball-1.0.big_sur.bottle.json",
"testball-1.0.catalina.bottle.json"
"#{TEST_TMPDIR}/testball-1.0.big_sur.bottle.json",
"#{TEST_TMPDIR}/testball-1.0.catalina.bottle.json"
}.to output("Error: --keep-old was passed but there was no existing bottle block!\n").to_stderr
end
it "updates the bottle block in a formula that already has a bottle block when using --keep-old" do
core_tap.path.cd do
system "git", "init"
bottle_block = <<~EOS
setup_test_formula "testball", bottle_block: <<~EOS
bottle do
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
@ -394,7 +365,6 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
sha256 "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" => :high_sierra
end
EOS
setup_test_formula("testball", "", bottle_block)
system "git", "add", "--all"
system "git", "commit", "-m", "testball 0.1"
end
@ -404,10 +374,9 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
"--merge",
"--write",
"--keep-old",
"testball-1.0.big_sur.bottle.json",
"testball-1.0.catalina.bottle.json"
}.to output(
<<~EOS,
"#{TEST_TMPDIR}/testball-1.0.big_sur.bottle.json",
"#{TEST_TMPDIR}/testball-1.0.catalina.bottle.json"
}.to output(<<~EOS).to_stdout
==> testball
bottle do
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
@ -417,10 +386,8 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
sha256 "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" => :high_sierra
end
EOS
).to_stdout
expect((core_tap.path/"Formula/testball.rb").read).to eq(
<<~EOS,
expect((core_tap.path/"Formula/testball.rb").read).to eq <<~EOS
class Testball < Formula
desc "Some test"
homepage "https://brew.sh/testball"
@ -452,6 +419,5 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
end
EOS
)
end
end

View File

@ -123,7 +123,7 @@ RSpec.shared_context "integration test" do
end
end
def setup_test_formula(name, content = nil, bottle_block = nil)
def setup_test_formula(name, content = nil, bottle_block: nil)
case name
when /^testball/
tarball = if OS.linux?