diff --git a/Library/Homebrew/test/.rubocop_todo.yml b/Library/Homebrew/test/.rubocop_todo.yml index e3f0383a8a..7e7fa024f6 100644 --- a/Library/Homebrew/test/.rubocop_todo.yml +++ b/Library/Homebrew/test/.rubocop_todo.yml @@ -11,6 +11,7 @@ RSpec/ExampleLength: Exclude: - 'rubocops/patches_spec.rb' + - 'dev-cmd/bottle_spec.rb' # Offense count: 6 # Configuration parameters: AssignmentOnly. diff --git a/Library/Homebrew/test/dev-cmd/bottle_spec.rb b/Library/Homebrew/test/dev-cmd/bottle_spec.rb index 2b25ef624e..05ea62bb76 100644 --- a/Library/Homebrew/test/dev-cmd/bottle_spec.rb +++ b/Library/Homebrew/test/dev-cmd/bottle_spec.rb @@ -42,39 +42,39 @@ describe "brew bottle", :integration_test do end end +def stub_hash(parameters) + <<~EOS + { + "#{parameters[:name]}":{ + "formula":{ + "pkg_version":"#{parameters[:version]}", + "path":"#{parameters[:path]}" + }, + "bottle":{ + "root_url":"#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}", + "prefix":"/usr/local", + "cellar":"#{parameters[:cellar]}", + "rebuild":0, + "tags":{ + "#{parameters[:os]}":{ + "filename":"#{parameters[:filename]}", + "local_filename":"#{parameters[:local_filename]}", + "sha256":"#{parameters[:sha256]}" + } + } + }, + "bintray":{ + "package":"#{parameters[:name]}", + "repository":"bottles" + } + } + } + EOS +end + describe Homebrew do subject(:homebrew) { described_class } - def stub_hash(parameters) - <<~EOS - { - "#{parameters[:name]}":{ - "formula":{ - "pkg_version":"#{parameters[:version]}", - "path":"#{parameters[:path]}" - }, - "bottle":{ - "root_url":"https://homebrew.bintray.com/bottles", - "prefix":"/usr/local", - "cellar":"#{parameters[:cellar]}", - "rebuild":0, - "tags":{ - "#{parameters[:os]}":{ - "filename":"#{parameters[:filename]}", - "local_filename":"#{parameters[:local_filename]}", - "sha256":"#{parameters[:sha256]}" - } - } - }, - "bintray":{ - "package":"#{parameters[:name]}", - "repository":"bottles" - } - } - } - EOS - end - 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 \\nint main(){printf(\\"test\\");return 0;}" + bin.mkpath + system ENV.cc, "test.c", "-o", bin/"test" + end + + + + # something here + + end + EOS + ) + end +end