Skip to content

Commit

Permalink
Test officially supported cmd taps. (#390)
Browse files Browse the repository at this point in the history
All of these taps use Homebrew internal APIs (or will shortly) and we
autoinstall them all from `brew $CMD`. We should adjust our CI to ensure
that we never accidentally break these taps when making changes to core
code so that these taps can rely more on this core code rather than
having to e.g. vendor equivalent code that never changes on our end.
  • Loading branch information
MikeMcQuaid authored Jul 4, 2016
1 parent 0377293 commit 252c701
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 11 deletions.
14 changes: 12 additions & 2 deletions Library/Homebrew/cmd/tests.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#: @hide_from_man_page
#: * `tests` [`-v`] [`--coverage`] [`--generic`] [`--no-compat`] [`--only=`<test_script/test_method>] [`--seed` <seed>] [`--trace`] [`--online`]:
#: * `tests` [`-v`] [`--coverage`] [`--generic`] [`--no-compat`] [`--only=`<test_script/test_method>] [`--seed` <seed>] [`--trace`] [`--online`] [`--official-cmd-taps`]:
#: Run Homebrew's unit and integration tests.

require "fileutils"
require "tap"

module Homebrew
def tests
ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1"

if ARGV.include? "--official-cmd-taps"
ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"] = "1"
OFFICIAL_CMD_TAPS.each do |tap, _|
tap = Tap.fetch tap
tap.install unless tap.installed?
end
end

(HOMEBREW_LIBRARY/"Homebrew/test").cd do
ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1"
ENV["TESTOPTS"] = "-v" if ARGV.verbose?
ENV["HOMEBREW_NO_COMPAT"] = "1" if ARGV.include? "--no-compat"
ENV["HOMEBREW_TEST_GENERIC_OS"] = "1" if ARGV.include? "--generic"
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/dev-cmd/test-bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ def homebrew
test "brew", "tests", *tests_args
test "brew", "tests", "--no-compat"
test "brew", "readall", "--syntax"
test "brew", "tests", "--official-cmd-taps"
else
test "brew", "readall", "--aliases", @tap.name
end
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require "exceptions"
require "set"
require "rbconfig"
require "official_taps"

ARGV.extend(HomebrewArgvExtension)

Expand Down
8 changes: 7 additions & 1 deletion Library/Homebrew/official_taps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@
tex
versions
x11
]
].freeze

OFFICIAL_CMD_TAPS = {
"caskroom/cask" => ["cask"],
"homebrew/bundle" => ["bundle"],
"homebrew/services" => ["services"],
}.freeze
37 changes: 37 additions & 0 deletions Library/Homebrew/test/test_integration_cmds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def teardown
@formula_files.each(&:unlink)
end

def needs_test_cmd_taps
unless ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"]
skip "HOMEBREW_TEST_OFFICIAL_CMD_TAPS is not set"
end
end

def cmd_id_from_args(args)
args_pretty = args.join(" ").gsub(TEST_TMPDIR, "@TMPDIR@")
test_pretty = "#{self.class.name}\##{name}.#{@cmd_id_index += 1}"
Expand Down Expand Up @@ -668,4 +674,35 @@ def test_search
ensure
desc_cache.unlink
end

def test_bundle
needs_test_cmd_taps
HOMEBREW_REPOSITORY.cd do
shutup do
system "git", "init"
system "git", "commit", "--allow-empty", "-m", "This is a test commit"
end
end

mktmpdir do |path|
FileUtils.touch "#{path}/Brewfile"
Dir.chdir path do
assert_equal "The Brewfile's dependencies are satisfied.",
cmd("bundle", "check")
end
end
ensure
FileUtils.rm_rf HOMEBREW_REPOSITORY/".git"
end

def test_cask
needs_test_cmd_taps
assert_equal "Warning: nothing to list", cmd("cask", "list")
end

def test_services
needs_test_cmd_taps
assert_equal "Warning: No services available to control with `brew services`",
cmd("services", "list")
end
end
10 changes: 2 additions & 8 deletions Library/brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,8 @@ def require?(path)
exit Homebrew.failed? ? 1 : 0
else
require "tap"
possible_tap = case cmd
when "brewdle", "brewdler", "bundle", "bundler"
Tap.fetch("Homebrew", "bundle")
when "cask"
Tap.fetch("caskroom", "cask")
when "services"
Tap.fetch("Homebrew", "services")
end
possible_tap = OFFICIAL_CMD_TAPS.find { |_, cmds| cmds.include?(cmd) }
possible_tap = Tap.fetch(possible_tap.first) if possible_tap

if possible_tap && !possible_tap.installed?
brew_uid = HOMEBREW_BREW_FILE.stat.uid
Expand Down

0 comments on commit 252c701

Please sign in to comment.