From 9dda84ad6be7fbc48c10e54f9c1af0c3a6b4afa6 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 22 Feb 2017 07:19:16 +0100 Subject: [PATCH] Add integration test helper methods. --- Library/Homebrew/extend/pathname.rb | 2 +- Library/Homebrew/test/spec_helper.rb | 4 + .../spec/shared_context/integration_test.rb | 74 +++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index cfb0287041..9f6861a9ae 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -335,7 +335,7 @@ class Pathname alias to_str to_s unless method_defined?(:to_str) def cd - Dir.chdir(self) { yield } + Dir.chdir(self) { yield self } end def subdirs diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 547ec3f7bf..48ddc975c0 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -37,6 +37,10 @@ RSpec.configure do |config| skip "not on macOS" unless OS.mac? end + if example.metadata[:needs_official_cmd_taps] + skip "Needs official command Taps." unless ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"] + end + if example.metadata[:needs_python] skip "Python not installed." unless which("python") end diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index dd2271a3a4..fc7b49fa4d 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -87,6 +87,80 @@ RSpec.shared_context "integration test" do status end end + + def setup_test_formula(name, content = nil) + case name + when /^testball/ + content = <<-EOS.undent + desc "Some test" + homepage "https://example.com/#{name}" + url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" + sha256 "#{TESTBALL_SHA256}" + + 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(){return printf(\\"test\\");}" + bin.mkpath + system ENV.cc, "test.c", "-o", bin/"test" + end + + #{content} + + # something here + EOS + when "foo" + content = <<-EOS.undent + url "https://example.com/#{name}-1.0" + EOS + when "bar" + content = <<-EOS.undent + url "https://example.com/#{name}-1.0" + depends_on "foo" + EOS + end + + Formulary.core_path(name).tap do |formula_path| + formula_path.write <<-EOS.undent + class #{Formulary.class_s(name)} < Formula + #{content} + end + EOS + end + end + + def setup_remote_tap(name) + Tap.fetch(name).tap do |tap| + tap.install(full_clone: false, quiet: true) unless tap.installed? + end + end + + def install_and_rename_coretap_formula(old_name, new_name) + shutup do + CoreTap.instance.path.cd do |tap_path| + system "git", "init" + system "git", "add", "--all" + system "git", "commit", "-m", + "#{old_name.capitalize} has not yet been renamed" + + brew "install", old_name + + (tap_path/"Formula/#{old_name}.rb").unlink + (tap_path/"formula_renames.json").write JSON.generate(old_name => new_name) + + system "git", "add", "--all" + system "git", "commit", "-m", + "#{old_name.capitalize} has been renamed to #{new_name.capitalize}" + end + end + end + + def testball + "#{TEST_FIXTURE_DIR}/testball.rb" + end end RSpec.configure do |config|