From 4da905b7fb61a48392aee18a8a2b0bf757cdab22 Mon Sep 17 00:00:00 2001 From: David Porter Date: Sat, 8 May 2010 15:35:06 +1000 Subject: [PATCH] Fix the update tests Signed-off-by: Adam Vandenberg --- Library/Homebrew/test/test_updater.rb | 16 +++++++++------- Library/Homebrew/test/tests | 6 ------ Library/Homebrew/update.rb | 3 ++- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/test/test_updater.rb b/Library/Homebrew/test/test_updater.rb index b94ec952a4..1d733560bc 100644 --- a/Library/Homebrew/test/test_updater.rb +++ b/Library/Homebrew/test/test_updater.rb @@ -23,6 +23,8 @@ class RefreshBrewMock < RefreshBrew raise "#{inspect} Unexpectedly called backticks in pwd `#{HOMEBREW_PREFIX}' and command `#{cmd}'" end end + + alias safe_system ` def expectations_met? @expect.keys.sort == @called.sort @@ -54,8 +56,8 @@ class UpdaterTests < Test::Unit::TestCase def test_update_homebrew_without_any_changes outside_prefix do updater = RefreshBrewMock.new - updater.in_prefix_expect("git checkout master") - updater.in_prefix_expect("git pull origin master", "Already up-to-date.\n") + updater.in_prefix_expect(RefreshBrew::INIT_COMMAND) + updater.in_prefix_expect(RefreshBrew::UPDATE_COMMAND, "Already up-to-date.\n") assert_equal false, updater.update_from_masterbrew! assert updater.expectations_met? @@ -67,9 +69,9 @@ class UpdaterTests < Test::Unit::TestCase def test_update_homebrew_without_formulae_changes outside_prefix do updater = RefreshBrewMock.new - updater.in_prefix_expect("git checkout master") + updater.in_prefix_expect(RefreshBrew::INIT_COMMAND) output = fixture('update_git_pull_output_without_formulae_changes') - updater.in_prefix_expect("git pull origin master", output) + updater.in_prefix_expect(RefreshBrew::UPDATE_COMMAND, output) assert_equal true, updater.update_from_masterbrew! assert !updater.pending_formulae_changes? @@ -81,9 +83,9 @@ class UpdaterTests < Test::Unit::TestCase def test_update_homebrew_with_formulae_changes outside_prefix do updater = RefreshBrewMock.new - updater.in_prefix_expect("git checkout master") + updater.in_prefix_expect(RefreshBrew::INIT_COMMAND) output = fixture('update_git_pull_output_with_formulae_changes') - updater.in_prefix_expect("git pull origin master", output) + updater.in_prefix_expect(RefreshBrew::UPDATE_COMMAND, output) assert_equal true, updater.update_from_masterbrew! assert updater.pending_formulae_changes? @@ -95,7 +97,7 @@ class UpdaterTests < Test::Unit::TestCase def test_updater_returns_current_revision outside_prefix do updater = RefreshBrewMock.new - updater.in_prefix_expect('git log -l -1 --pretty=format:%H', 'the-revision-hash') + updater.in_prefix_expect(RefreshBrew::REVISION_COMMAND, 'the-revision-hash') assert_equal 'the-revision-hash', updater.current_revision end end diff --git a/Library/Homebrew/test/tests b/Library/Homebrew/test/tests index b292bb5706..21cc9f17ed 100755 --- a/Library/Homebrew/test/tests +++ b/Library/Homebrew/test/tests @@ -5,10 +5,6 @@ # Note: "formula_test" is omitted; these aren't unit tests but sanity checks # on the real formulae. # -# Run as: -# ./tests -- --skip-update -# to omit the update tests which only seem to work for mxcl -# # Feel free to split out test_bucket ruby test_bucket.rb $* @@ -24,6 +20,4 @@ ruby test_pathname_install.rb $* ruby test_utils.rb $* ruby test_ARGV.rb $* ruby test_ENV.rb $* - -# Update tests (only seem to work for mxcl) ruby test_updater.rb $* diff --git a/Library/Homebrew/update.rb b/Library/Homebrew/update.rb index a580b8cae0..bd45e6195f 100644 --- a/Library/Homebrew/update.rb +++ b/Library/Homebrew/update.rb @@ -1,5 +1,6 @@ class RefreshBrew RESPOSITORY_URL = 'git://github.com/mxcl/homebrew.git' + INIT_COMMAND = "git init" CHECKOUT_COMMAND = 'git checkout -q master' UPDATE_COMMAND = "git pull #{RESPOSITORY_URL} master" REVISION_COMMAND = 'git log -l -1 --pretty=format:%H 2> /dev/null' @@ -60,7 +61,7 @@ class RefreshBrew def execute(cmd) out = `#{cmd}` - unless $?.success? + if $? && !$?.success? puts out raise "Failed while executing #{cmd}" end