tests: bring brew update tests up to date
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
parent
a64f417f36
commit
5d84df0210
@ -1,26 +1,27 @@
|
||||
update_git_diff_output_without_formulae_changes: |
|
||||
M Library/Homebrew/ARGV+yeast.rb
|
||||
A Library/Homebrew/beer_events.rb
|
||||
A Library/Homebrew/hardware.rb
|
||||
D Library/Homebrew/hw.model.c
|
||||
M README
|
||||
M bin/brew
|
||||
:100644 100644 9dde0708e2db78e1aa697782bd2ab2ddfd8da984 ee0a81cbe3757e9a4b5aab1c41457f65fed9f258 M Library/Homebrew/ARGV+yeast.rb
|
||||
:100644 100644 741f11dcd29ec909a94fa54df4bcdd2c1d5bb47b 7535134e865994e8ad66ba02a924a1e6c1271b9e A Library/Homebrew/beer_events.rb
|
||||
:100644 100644 b4b6d4f7837585bea2608da6eac4864bc410b319 f2f02310189f2114c033fd50e453aabbaa5ec111 A Library/Homebrew/hardware.rb
|
||||
:100644 100644 69b22663da0e9060c18143d96d37ab2f5d618579 d18b0e7161b73e7e1a0090b6d1d42a2569efb682 D Library/Homebrew/hw.model.c
|
||||
:100644 100644 0bdadb080de7bfb1dd0d5ef5aafbc65da35791ae 39b3e237b773d7eed584996d7c2541de0f36996c M README
|
||||
:100644 100644 5bec138e6ce67d3d80446740c309ef40652cebc2 0955e96cb368c95a73f2b01bfd060e575c445152 M bin/brew
|
||||
update_git_diff_output_with_formulae_changes: |
|
||||
M Library/Contributions/brew_bash_completion.sh
|
||||
A Library/Formula/antiword.rb
|
||||
A Library/Formula/bash-completion.rb
|
||||
M Library/Formula/xar.rb
|
||||
M Library/Formula/yajl.rb
|
||||
M Library/Homebrew/ARGV+yeast.rb
|
||||
M Library/Homebrew/pathname+yeast.rb
|
||||
M Library/Homebrew/unittest.rb
|
||||
M Library/Homebrew/utils.rb
|
||||
M README
|
||||
M bin/brew
|
||||
A Library/Formula/ddrescue.rb
|
||||
A Library/Formula/dict.rb
|
||||
A Library/Formula/lua.rb
|
||||
A Library/Homebrew/beer_events.rb
|
||||
A Library/Homebrew/hardware.rb
|
||||
D Library/Homebrew/hw.model.c
|
||||
D Library/Homebrew/hw.model.rb
|
||||
:100644 100644 9dde0708e2db78e1aa697782bd2ab2ddfd8da984 ee0a81cbe3757e9a4b5aab1c41457f65fed9f258 M Library/Contributions/brew_bash_completion.sh
|
||||
:100644 100644 741f11dcd29ec909a94fa54df4bcdd2c1d5bb47b 7535134e865994e8ad66ba02a924a1e6c1271b9e A Library/Formula/antiword.rb
|
||||
:100644 100644 b4b6d4f7837585bea2608da6eac4864bc410b319 f2f02310189f2114c033fd50e453aabbaa5ec111 A Library/Formula/bash-completion.rb
|
||||
:100644 100644 9dde0708e2db78e1aa697782bd2ab2ddfd8da984 ee0a81cbe3757e9a4b5aab1c41457f65fed9f258 A Library/Formula/ddrescue.rb
|
||||
:100644 100644 a054cd648c85515484aee25ba22611423b603c69 e0b6354360bff68a6c5a612bf6e2918ceeb2ea0a A Library/Formula/dict.rb
|
||||
:100644 100644 741f11dcd29ec909a94fa54df4bcdd2c1d5bb47b 7535134e865994e8ad66ba02a924a1e6c1271b9e A Library/Formula/lua.rb
|
||||
:100644 100644 27740424d7cd046815eb67d253e08641d0c80fc7 d75a4b08302a9d0c741f969aa784878eb45d8366 R094 Library/Formula/shapefile.rb Library/Formula/shapelib.rb
|
||||
:100644 100644 69b22663da0e9060c18143d96d37ab2f5d618579 d18b0e7161b73e7e1a0090b6d1d42a2569efb682 M Library/Formula/xar.rb
|
||||
:100644 100644 0bdadb080de7bfb1dd0d5ef5aafbc65da35791ae 39b3e237b773d7eed584996d7c2541de0f36996c M Library/Formula/yajl.rb
|
||||
:100644 100644 5bec138e6ce67d3d80446740c309ef40652cebc2 0955e96cb368c95a73f2b01bfd060e575c445152 M Library/Homebrew/ARGV+yeast.rb
|
||||
:100644 100644 b4b6d4f7837585bea2608da6eac4864bc410b319 f2f02310189f2114c033fd50e453aabbaa5ec111 M Library/Homebrew/beer_events.rb
|
||||
:100644 100644 de9faee9b6859d0f4146b60caff1e7643af01a4c 47976729f566a14290d5efe061bbe4547e2d1b9e M Library/Homebrew/hardware.rb
|
||||
:100644 100644 69b22663da0e9060c18143d96d37ab2f5d618579 d18b0e7161b73e7e1a0090b6d1d42a2569efb682 M Library/Homebrew/hw.model.c
|
||||
:100644 100644 0bdadb080de7bfb1dd0d5ef5aafbc65da35791ae 39b3e237b773d7eed584996d7c2541de0f36996c M Library/Homebrew/hw.model.rb
|
||||
:100644 100644 0811641e6101d39b2d832539de01a104e052a97e dc66b94c51c1c2750d4a31e83c41f100c4d079b7 M Library/Homebrew/pathname+yeast.rb
|
||||
:100644 100644 440f1c9b10775150999264eb96e93fcfbd7727da 64bb503c712208d00d7cc2d0428d67d482685c22 M Library/Homebrew/unittest.rb
|
||||
:100644 100644 cc176d388507c7ed9381a36fd42ae0feceaad593 6a7a2385d89a12b5c7369fa0a87980b285ee5fd8 M Library/Homebrew/utils.rb
|
||||
:100644 100644 d1d9c62e6280bcb06c8b884c188d7bd37f8754e3 4aa0473705264cac864bd09f8a9d419d805e4774 M README
|
||||
:100644 100644 c0084b02faf7ab04abcffb3d5688e9d7c1ff7ae8 25cae981801e21cde048cd28747241d18093ca71 M bin/brew
|
||||
|
||||
@ -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!
|
||||
def test_update_homebrew_without_formulae_changes
|
||||
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')
|
||||
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)
|
||||
|
||||
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!
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user