brew/Library/Homebrew/test/test_updater.rb

105 lines
3.3 KiB
Ruby
Raw Normal View History

2010-02-12 14:56:01 -08:00
require 'testing_env'
require 'cmd/update'
require 'yaml'
2010-02-12 14:56:01 -08:00
class UpdaterTests < Homebrew::TestCase
class UpdaterMock < ::Updater
2014-06-23 18:41:50 -05:00
def initialize(*)
super
@outputs = Hash.new { |h, k| h[k] = [] }
@expected = []
@called = []
end
def in_repo_expect(cmd, output = '')
@expected << cmd
@outputs[cmd] << output
end
def `(cmd, *args)
cmd = "#{cmd} #{args*' '}".strip
if @expected.include?(cmd) and !@outputs[cmd].empty?
@called << cmd
@outputs[cmd].shift
else
raise "#{inspect} unexpectedly called backticks: `#{cmd}`"
end
2010-02-12 14:56:01 -08:00
end
alias safe_system ` #`
def expectations_met?
@expected == @called
end
2010-02-12 14:56:01 -08:00
end
def fixture(name)
self.class.fixture_data[name]
end
def self.fixture_data
2014-06-10 21:49:41 -05:00
@fixture_data ||= YAML.load_file("#{TEST_DIRECTORY}/fixtures/updater_fixture.yaml")
end
2013-07-09 22:12:08 -05:00
def setup
2014-06-23 18:41:50 -05:00
@updater = UpdaterMock.new(HOMEBREW_REPOSITORY)
2013-07-09 22:12:08 -05:00
@report = Report.new
end
2013-07-09 22:12:08 -05:00
def perform_update(diff_output="")
HOMEBREW_REPOSITORY.cd do
2013-07-09 22:12:08 -05:00
@updater.in_repo_expect("git checkout -q master")
@updater.in_repo_expect("git rev-parse -q --verify HEAD", "1234abcd")
@updater.in_repo_expect("git config core.autocrlf false")
@updater.in_repo_expect("git pull -q origin refs/heads/master:refs/remotes/origin/master")
@updater.in_repo_expect("git rev-parse -q --verify HEAD", "3456cdef")
@updater.in_repo_expect("git diff-tree -r --raw -M85% 1234abcd 3456cdef", diff_output)
@updater.pull!
@report.merge!(@updater.report)
end
end
2013-07-09 22:12:08 -05:00
def test_update_homebrew_without_any_changes
perform_update
2014-06-11 12:21:03 -05:00
assert_predicate @updater, :expectations_met?
2014-06-11 12:22:29 -05:00
assert_empty @report
2013-07-09 22:12:08 -05:00
end
2013-07-09 22:12:08 -05:00
def test_update_homebrew_without_formulae_changes
perform_update(fixture('update_git_diff_output_without_formulae_changes'))
2014-06-11 12:21:03 -05:00
assert_predicate @updater, :expectations_met?
2014-06-11 12:22:29 -05:00
assert_empty @report.select_formula(:M)
assert_empty @report.select_formula(:A)
assert_empty @report.select_formula(:R)
2013-07-09 22:12:08 -05:00
end
2013-07-09 22:12:08 -05:00
def test_update_homebrew_with_formulae_changes
perform_update(fixture('update_git_diff_output_with_formulae_changes'))
2014-06-11 12:21:03 -05:00
assert_predicate @updater, :expectations_met?
2013-07-09 22:12:08 -05:00
assert_equal %w{ xar yajl }, @report.select_formula(:M)
assert_equal %w{ antiword bash-completion ddrescue dict lua }, @report.select_formula(:A)
assert_equal %w{ shapelib }, @report.select_formula(:R)
end
def test_update_homebrew_with_tapped_formula_changes
2013-07-09 22:12:08 -05:00
perform_update(fixture('update_git_diff_output_with_tapped_formulae_changes'))
2014-06-11 12:21:03 -05:00
assert_predicate @updater, :expectations_met?
2013-07-09 22:12:08 -05:00
assert_equal [
HOMEBREW_LIBRARY.join("Taps", "someuser/sometap/Formula/antiword.rb"),
HOMEBREW_LIBRARY.join("Taps", "someuser/sometap/HomebrewFormula/lua.rb"),
HOMEBREW_LIBRARY.join("Taps", "someuser/sometap/custom-formula.rb"),
2013-07-09 22:12:08 -05:00
], @report.tapped_formula_for(:A)
end
def test_update_homebrew_with_removed_formulae
perform_update(fixture('update_git_diff_output_with_removed_formulae'))
2014-06-11 12:21:03 -05:00
assert_predicate @updater, :expectations_met?
assert_equal %w{libgsasl}, @report.select_formula(:D)
end
def test_update_homebrew_with_changed_filetype
perform_update(fixture('update_git_diff_output_with_changed_filetype'))
2014-06-11 12:21:03 -05:00
assert_predicate @updater, :expectations_met?
end
end