Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev-cmd: only one integration test per command. #5928

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Library/Homebrew/extend/os/linux/keg_relocate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def change_rpath(file, old_prefix, new_prefix)
return if !file.elf? || !file.dynamic_elf?

patchelf = DevelopmentTools.locate "patchelf"

cmd_rpath = [patchelf, "--print-rpath", file]
old_rpath = Utils.popen_read(*cmd_rpath, err: :out).strip

Expand Down
5 changes: 5 additions & 0 deletions Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require "linkage_checker"
require "install"
require "messages"
require "cask/cask_loader"

class FormulaInstaller
include FormulaCellarChecks
Expand Down Expand Up @@ -68,6 +69,10 @@ def self.attempted
@attempted ||= Set.new
end

def self.clear_attempted
@attempted = Set.new
end

# When no build tools are available and build flags are passed through ARGV,
# it's necessary to interrupt the user before any sort of installation
# can proceed. Only invoked when the user has no developer tools.
Expand Down
49 changes: 21 additions & 28 deletions Library/Homebrew/test/dev-cmd/bottle_spec.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
describe "brew bottle", :integration_test do
it "builds a bottle for the given Formula" do
begin
expect { brew "install", "--build-bottle", testball }
.to be_a_success

# create stub patchelf
if OS.linux?
setup_test_formula "patchelf"
(HOMEBREW_CELLAR/"patchelf/1.0/bin").mkpath

expect { brew "bottle", "--no-rebuild", testball }
.to output(/Formula not from core or any installed taps/).to_stderr
.and not_to_output.to_stdout
.and be_a_failure

expect { brew "bottle", "--root-url" }
.to output(/missing argument: --root-url/).to_stderr
.and not_to_output.to_stdout
.and be_a_failure

setup_test_formula "testball"
patchelf = HOMEBREW_CELLAR/"patchelf/1.0/bin/patchelf"
patchelf.dirname.mkpath
patchelf.write <<~EOS
#!/bin/sh
exit 0
EOS
FileUtils.chmod "+x", patchelf
FileUtils.ln_s patchelf, HOMEBREW_PREFIX/"bin/patchelf"
end

# `brew bottle` should not fail with dead symlink
# https://github.com/Homebrew/legacy-homebrew/issues/49007
(HOMEBREW_CELLAR/"testball/0.1").cd do
FileUtils.ln_s "not-exist", "symlink"
end
install_test_formula "testball", build_bottle: true

expect { brew "bottle", "--no-rebuild", "testball" }
.to output(/testball--0\.1.*\.bottle\.tar\.gz/).to_stdout
.and not_to_output.to_stderr
.and be_a_success
ensure
FileUtils.rm_f Dir.glob("testball--0.1*.bottle.tar.gz")
# `brew bottle` should not fail with dead symlink
# https://github.com/Homebrew/legacy-homebrew/issues/49007
(HOMEBREW_CELLAR/"testball/0.1").cd do
FileUtils.ln_s "not-exist", "symlink"
end

expect { brew "bottle", "--no-rebuild", "testball" }
.to output(/testball--0\.1.*\.bottle\.tar\.gz/).to_stdout
.and not_to_output.to_stderr
.and be_a_success
end
end
6 changes: 0 additions & 6 deletions Library/Homebrew/test/dev-cmd/extract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
system "git", "add", "--all"
system "git", "commit", "-m", "testball 0.2"
end
expect { brew "extract", "testball", target.name }
.to be_a_success

expect(path/"Formula/testball@0.2.rb").to exist

expect(Formulary.factory(path/"Formula/testball@0.2.rb").version).to be == "0.2"

expect { brew "extract", "testball", target.name, "--version=0.1" }
.to be_a_success
Expand Down
7 changes: 0 additions & 7 deletions Library/Homebrew/test/dev-cmd/irb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,4 @@
.and not_to_output.to_stderr
.and be_a_success
end

specify "--examples" do
expect { brew "irb", "--examples" }
.to output(/'v8'\.f # => instance of the v8 formula/).to_stdout
.and not_to_output.to_stderr
.and be_a_success
end
end
6 changes: 0 additions & 6 deletions Library/Homebrew/test/dev-cmd/linkage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,4 @@
.and not_to_output.to_stdout
.and not_to_output.to_stderr
end

it "works when one argument is provided" do
expect { brew "linkage", "testball" }
.to be_a_success
.and not_to_output.to_stderr
end
end
18 changes: 0 additions & 18 deletions Library/Homebrew/test/dev-cmd/pull_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,6 @@
system "git", "checkout", "-b", "new-branch"
end

expect { brew "pull", "https://jenkins.brew.sh/job/Homebrew\%20Testing/1028/" }
.to output(/Testing URLs require `\-\-bottle`!/).to_stderr
.and not_to_output.to_stdout
.and be_a_failure

# Needs Homebrew/homebrew-core
if OS.mac?
expect { brew "pull", "1" }
.to output(/Fetching patch/).to_stdout
.and output(/Current branch is new\-branch/).to_stderr
.and be_a_failure
end

expect { brew "pull", "--bump", "https://api.github.com/repos/Homebrew/homebrew-core/pulls/122" }
.to output(/Fetching patch/).to_stdout
.and output(/Can only bump one changed formula/).to_stderr
.and be_a_failure

expect { brew "pull", "https://github.com/Homebrew/brew/pull/1249" }
.to output(/Fetching patch/).to_stdout
.and output(/Patch failed to apply/).to_stderr
Expand Down
21 changes: 3 additions & 18 deletions Library/Homebrew/test/dev-cmd/test_spec.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
describe "brew test", :integration_test do
it "tests a given Formula" do
setup_test_formula "testball", <<~RUBY
head "https://github.com/example/testball2.git"

devel do
url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
sha256 "#{TESTBALL_SHA256}"
end

keg_only "just because"

install_test_formula "testball", <<~'RUBY'
test do
assert_equal "test", shell_output("#{bin}/test")
end
RUBY

expect { brew "install", "testball" }.to be_a_success

expect { brew "test", "--HEAD", "testball" }
.to output(/Testing testball/).to_stdout
.and not_to_output.to_stderr
.and be_a_success

expect { brew "test", "--devel", "testball" }
expect { brew "test", "--verbose", "testball" }
.to output(/Testing testball/).to_stdout
.and not_to_output.to_stderr
.and be_a_success
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/test/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def find_files

begin
Tap.clear_cache
FormulaInstaller.clear_attempted

TEST_DIRECTORIES.each(&:mkpath)

Expand Down Expand Up @@ -189,6 +190,7 @@ def find_files
CoreTap.instance.path/".git",
CoreTap.instance.alias_dir,
CoreTap.instance.path/"formula_renames.json",
*Pathname.glob("#{HOMEBREW_CELLAR}/*/"),
]

files_after_test = find_files
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require "open3"

require "formula_installer"

RSpec::Matchers.define_negated_matcher :be_a_failure, :be_a_success

RSpec.shared_context "integration test" do
Expand Down Expand Up @@ -140,7 +142,7 @@ def install
(prefix/"foo"/"test").write("test") if build.with? "foo"
prefix.install Dir["*"]
(buildpath/"test.c").write \
"#include <stdio.h>\\nint main(){return printf(\\"test\\");}"
"#include <stdio.h>\\nint main(){printf(\\"test\\");return 0;}"
bin.mkpath
system ENV.cc, "test.c", "-o", bin/"test"
end
Expand Down Expand Up @@ -173,6 +175,15 @@ class #{Formulary.class_s(name)} < Formula
end
end

def install_test_formula(name, content = nil, build_bottle: false)
setup_test_formula(name, content)
fi = FormulaInstaller.new(Formula[name])
fi.build_bottle = build_bottle
fi.prelude
fi.install
fi.finish
end

def setup_remote_tap(name)
Tap.fetch(name).tap do |tap|
next if tap.installed?
Expand Down