bottle: add test for writing part

In preparation for https://github.com/Homebrew/brew/issues/9315
This commit is contained in:
Michka Popoff 2020-12-09 23:02:31 +01:00
parent d08da30ed3
commit 4afcae58c3
2 changed files with 134 additions and 30 deletions

View File

@ -11,6 +11,7 @@
RSpec/ExampleLength:
Exclude:
- 'rubocops/patches_spec.rb'
- 'dev-cmd/bottle_spec.rb'
# Offense count: 6
# Configuration parameters: AssignmentOnly.

View File

@ -42,9 +42,6 @@ describe "brew bottle", :integration_test do
end
end
describe Homebrew do
subject(:homebrew) { described_class }
def stub_hash(parameters)
<<~EOS
{
@ -54,7 +51,7 @@ describe Homebrew do
"path":"#{parameters[:path]}"
},
"bottle":{
"root_url":"https://homebrew.bintray.com/bottles",
"root_url":"#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}",
"prefix":"/usr/local",
"cellar":"#{parameters[:cellar]}",
"rebuild":0,
@ -75,6 +72,9 @@ describe Homebrew do
EOS
end
describe Homebrew do
subject(:homebrew) { described_class }
let(:hello_hash_big_sur) {
JSON.parse(
stub_hash(
@ -194,3 +194,106 @@ describe Homebrew do
)
end
end
describe "brew bottle --merge", :integration_test, :needs_linux do
it "adds the bottle block to a formula that has none" do
core_tap = CoreTap.new
core_tap.path.cd do
system "git", "init"
setup_test_formula "testball"
system "git", "add", "--all"
system "git", "commit", "-m", "testball 0.1"
end
Pathname("testball-1.0.big_sur.bottle.json").write(
stub_hash(
{
"name": "testball",
"version": "1.0",
"path": "#{core_tap.path}/Formula/testball.rb",
"cellar": "any_skip_relocation",
"os": "big_sur",
"filename": "hello-1.0.big_sur.bottle.tar.gz",
"local_filename": "hello--1.0.big_sur.bottle.tar.gz",
"sha256": "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f",
},
),
)
Pathname("testball-1.0.catalina.bottle.json").write(
stub_hash(
{
"name": "testball",
"version": "1.0",
"path": "#{core_tap.path}/Formula/testball.rb",
"cellar": "any_skip_relocation",
"os": "catalina",
"filename": "testball-1.0.catalina.bottle.tar.gz",
"local_filename": "testball--1.0.catalina.bottle.tar.gz",
"sha256": "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac",
},
),
)
expect {
brew "bottle",
"--merge",
"--write",
"testball-1.0.big_sur.bottle.json",
"testball-1.0.catalina.bottle.json"
}.to output(
<<~EOS,
==> testball
bottle do
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
cellar :any_skip_relocation
sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina
end
EOS
).to_stdout
FileUtils.rm_f "testball-1.0.catalina.bottle.json"
FileUtils.rm_f "testball-1.0.big_sur.bottle.json"
tarball = if OS.linux?
TEST_FIXTURE_DIR/"tarballs/testball-0.1-linux.tbz"
else
TEST_FIXTURE_DIR/"tarballs/testball-0.1.tbz"
end
expect((core_tap.path/"Formula/testball.rb").read).to eq(
<<~EOS,
class Testball < Formula
desc "Some test"
homepage "https://brew.sh/testball"
url "file://#{tarball}"
sha256 "#{tarball.sha256}"
bottle do
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
cellar :any_skip_relocation
sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina
end
option "with-foo", "Build with foo"
def install
(prefix/"foo"/"test").write("test") if build.with? "foo"
prefix.install Dir["*"]
(buildpath/"test.c").write \
"#include <stdio.h>\\nint main(){printf(\\"test\\");return 0;}"
bin.mkpath
system ENV.cc, "test.c", "-o", bin/"test"
end
# something here
end
EOS
)
end
end