aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/test_updater.rb
diff options
context:
space:
mode:
authorJack Nagel2012-04-13 23:21:00 -0500
committerJack Nagel2012-04-14 00:00:04 -0500
commite399fd70a10a727a202078f8148ca0421a7e6044 (patch)
tree2aae767992cee6f6966eaf8d1af853956f7a54a7 /Library/Homebrew/test/test_updater.rb
parent8e38d050cf8c39afb9e1a80fc5caf6b7ca8b37b6 (diff)
downloadhomebrew-e399fd70a10a727a202078f8148ca0421a7e6044.tar.bz2
tests: bring `brew update` tests up to date
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Diffstat (limited to 'Library/Homebrew/test/test_updater.rb')
-rw-r--r--Library/Homebrew/test/test_updater.rb151
1 files changed, 58 insertions, 93 deletions
diff --git a/Library/Homebrew/test/test_updater.rb b/Library/Homebrew/test/test_updater.rb
index c8f50f5ef..b47c0c052 100644
--- a/Library/Homebrew/test/test_updater.rb
+++ b/Library/Homebrew/test/test_updater.rb
@@ -1,7 +1,6 @@
abort if ARGV.include? "--skip-update"
require 'testing_env'
-HOMEBREW_CELLAR.mkpath
require 'extend/ARGV' # needs to be after test/unit to avoid conflict with OptionsParser
ARGV.extend(HomebrewArgvExtension)
@@ -10,50 +9,37 @@ require 'formula'
require 'utils'
require 'cmd/update'
-class RefreshBrewMock < RefreshBrew
- def git_repo?
- @git_repo
- end
- attr_writer :git_repo
-
- def in_prefix_expect(cmd, output = '')
+class UpdaterMock < Updater
+ def in_repo_expect(cmd, output = '')
@outputs ||= Hash.new { |h,k| h[k] = [] }
@expected ||= []
@expected << cmd
@outputs[cmd] << output
end
-
- def `(cmd)
- if Dir.pwd == HOMEBREW_PREFIX.to_s and @expected.include?(cmd) and !@outputs[cmd].empty?
+
+ def `(cmd, *args)
+ cmd = "#{cmd} #{args*' '}".strip
+ if @expected.include?(cmd) and !@outputs[cmd].empty?
@called ||= []
@called << cmd
@outputs[cmd].shift
else
- raise "#{inspect} Unexpectedly called backticks in pwd `#{HOMEBREW_PREFIX}' and command `#{cmd}'"
+ raise "#<#{self.class.name} #{object_id}> unexpectedly called backticks: `#{cmd}'"
end
end
- alias safe_system `
-
+ alias safe_system ` #`
+
def expectations_met?
@expected == @called
end
-
- def inspect
- "#<#{self.class.name} #{object_id}>"
- end
end
class UpdaterTests < Test::Unit::TestCase
- OUTSIDE_PREFIX = '/tmp'
- def outside_prefix
- Dir.chdir(OUTSIDE_PREFIX) { yield }
- end
-
def fixture(name)
self.class.fixture_data[name]
end
-
+
def self.fixture_data
unless @fixture_data
require 'yaml'
@@ -62,86 +48,65 @@ class UpdaterTests < Test::Unit::TestCase
@fixture_data
end
- def test_init_homebrew
- outside_prefix do
- updater = RefreshBrewMock.new
- updater.git_repo = false
- updater.in_prefix_expect("git init")
- updater.in_prefix_expect("git config core.autocrlf false")
- updater.in_prefix_expect("git remote add origin #{RefreshBrewMock::REPOSITORY_URL}")
- updater.in_prefix_expect("git fetch origin")
- updater.in_prefix_expect("git reset --hard origin/master")
- updater.in_prefix_expect("git config core.autocrlf false")
- updater.in_prefix_expect("git pull origin refs/heads/master:refs/remotes/origin/master")
- updater.in_prefix_expect("git rev-parse HEAD", "1234abcd")
-
- assert_equal false, updater.update_from_masterbrew!
- assert updater.expectations_met?
- assert updater.updated_formulae.empty?
- assert updater.added_formulae.empty?
- end
- end
-
def test_update_homebrew_without_any_changes
- outside_prefix do
- updater = RefreshBrewMock.new
- updater.git_repo = true
- updater.in_prefix_expect("git checkout -q master")
- updater.in_prefix_expect("git rev-parse HEAD", "1234abcd")
- updater.in_prefix_expect("git remote", "origin")
- updater.in_prefix_expect("git config core.autocrlf false")
- updater.in_prefix_expect("git pull origin refs/heads/master:refs/remotes/origin/master")
- updater.in_prefix_expect("git rev-parse HEAD", "3456cdef")
- updater.in_prefix_expect("git diff-tree -r --name-status -z 1234abcd 3456cdef", "")
-
- assert_equal false, updater.update_from_masterbrew!
+ HOMEBREW_REPOSITORY.cd do
+ updater = UpdaterMock.new
+ 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")
+ updater.pull!
+ report = Report.new
+ report.merge!(updater.report)
+
assert updater.expectations_met?
- assert updater.updated_formulae.empty?
- assert updater.added_formulae.empty?
+ assert report.empty?
end
end
-
+
def test_update_homebrew_without_formulae_changes
- outside_prefix do
- updater = RefreshBrewMock.new
- updater.git_repo = true
- diff_output = fixture('update_git_diff_output_without_formulae_changes')
-
- updater.in_prefix_expect("git checkout -q master")
- updater.in_prefix_expect("git rev-parse HEAD", "1234abcd")
- updater.in_prefix_expect("git remote", "origin")
- updater.in_prefix_expect("git config core.autocrlf false")
- updater.in_prefix_expect("git pull origin refs/heads/master:refs/remotes/origin/master")
- updater.in_prefix_expect("git rev-parse HEAD", "3456cdef")
- updater.in_prefix_expect("git diff-tree -r --name-status -z 1234abcd 3456cdef", diff_output.gsub(/\s+/, "\0"))
-
- assert_equal true, updater.update_from_masterbrew!
+ diff_output = fixture('update_git_diff_output_without_formulae_changes')
+
+ HOMEBREW_REPOSITORY.cd do
+ updater = UpdaterMock.new
+ 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 = Report.new
+ report.merge!(updater.report)
+
assert updater.expectations_met?
- assert !updater.pending_formulae_changes?
- assert updater.updated_formulae.empty?
- assert updater.added_formulae.empty?
+ assert report.select_formula(:M).empty?
+ assert report.select_formula(:A).empty?
+ assert report.select_formula(:R).empty?
end
end
def test_update_homebrew_with_formulae_changes
- outside_prefix do
- updater = RefreshBrewMock.new
- updater.git_repo = true
- diff_output = fixture('update_git_diff_output_with_formulae_changes')
-
- updater.in_prefix_expect("git checkout -q master")
- updater.in_prefix_expect("git rev-parse HEAD", "1234abcd")
- updater.in_prefix_expect("git remote", "origin")
- updater.in_prefix_expect("git config core.autocrlf false")
- updater.in_prefix_expect("git pull origin refs/heads/master:refs/remotes/origin/master")
- updater.in_prefix_expect("git rev-parse HEAD", "3456cdef")
- updater.in_prefix_expect("git diff-tree -r --name-status -z 1234abcd 3456cdef", diff_output.gsub(/\s+/, "\0"))
-
- assert_equal true, updater.update_from_masterbrew!
+ diff_output = fixture('update_git_diff_output_with_formulae_changes')
+
+ HOMEBREW_REPOSITORY.cd do
+ updater = UpdaterMock.new
+ 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 = Report.new
+ report.merge!(updater.report)
+
assert updater.expectations_met?
- assert updater.pending_formulae_changes?
- assert_equal %w{ xar yajl }, updater.updated_formulae
- assert_equal %w{ antiword bash-completion ddrescue dict lua }, updater.added_formulae
+ 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
end
end