| 
									
										
										
										
											2010-02-12 14:56:01 -08:00
										 |  |  | require 'testing_env' | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | require 'cmd/update' | 
					
						
							| 
									
										
										
										
											2013-03-28 17:37:29 -05:00
										 |  |  | require 'yaml' | 
					
						
							| 
									
										
										
										
											2010-02-12 14:56:01 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 23:21:00 -05:00
										 |  |  | class UpdaterMock < Updater | 
					
						
							|  |  |  |   def in_repo_expect(cmd, output = '') | 
					
						
							| 
									
										
										
										
											2011-06-12 17:07:59 +02:00
										 |  |  |     @outputs  ||= Hash.new { |h,k| h[k] = [] } | 
					
						
							|  |  |  |     @expected ||= [] | 
					
						
							|  |  |  |     @expected << cmd | 
					
						
							|  |  |  |     @outputs[cmd] << output | 
					
						
							| 
									
										
										
										
											2010-02-12 14:56:01 -08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-04-13 23:21:00 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def `(cmd, *args) | 
					
						
							|  |  |  |     cmd = "#{cmd} #{args*' '}".strip | 
					
						
							|  |  |  |     if @expected.include?(cmd) and !@outputs[cmd].empty? | 
					
						
							| 
									
										
										
										
											2011-06-12 17:07:59 +02:00
										 |  |  |       @called ||= [] | 
					
						
							|  |  |  |       @called << cmd | 
					
						
							|  |  |  |       @outputs[cmd].shift | 
					
						
							| 
									
										
										
										
											2010-02-12 14:56:01 -08:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2012-04-13 23:21:00 -05:00
										 |  |  |       raise "#<#{self.class.name} #{object_id}> unexpectedly called backticks: `#{cmd}'" | 
					
						
							| 
									
										
										
										
											2010-02-12 14:56:01 -08:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-05-08 15:35:06 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-13 23:21:00 -05:00
										 |  |  |   alias safe_system ` #` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-12 14:56:01 -08:00
										 |  |  |   def expectations_met? | 
					
						
							| 
									
										
										
										
											2011-06-12 17:07:59 +02:00
										 |  |  |     @expected == @called | 
					
						
							| 
									
										
										
										
											2010-02-12 14:56:01 -08:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  | class UpdaterTests < Test::Unit::TestCase | 
					
						
							|  |  |  |   def fixture(name) | 
					
						
							|  |  |  |     self.class.fixture_data[name] | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-04-13 23:21:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   def self.fixture_data | 
					
						
							| 
									
										
										
										
											2013-03-28 17:37:29 -05:00
										 |  |  |     @fixture_data ||= load_fixture_data | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def self.load_fixture_data | 
					
						
							|  |  |  |     YAML.load_file(Pathname.new(ABS__FILE__).parent.realpath + 'fixtures/updater_fixture.yaml') | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-09 22:12:08 -05:00
										 |  |  |   def setup | 
					
						
							|  |  |  |     @updater = UpdaterMock.new | 
					
						
							|  |  |  |     @report = Report.new | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-04-13 23:21:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-09 22:12:08 -05:00
										 |  |  |   def perform_update(diff_output="") | 
					
						
							| 
									
										
										
										
											2012-04-13 23:21:00 -05:00
										 |  |  |     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) | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-06-20 00:51:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-09 22:12:08 -05:00
										 |  |  |   def test_update_homebrew_without_any_changes | 
					
						
							|  |  |  |     perform_update | 
					
						
							|  |  |  |     assert @updater.expectations_met? | 
					
						
							|  |  |  |     assert @report.empty? | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-04-13 23:21:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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')) | 
					
						
							|  |  |  |     assert @updater.expectations_met? | 
					
						
							|  |  |  |     assert @report.select_formula(:M).empty? | 
					
						
							|  |  |  |     assert @report.select_formula(:A).empty? | 
					
						
							|  |  |  |     assert @report.select_formula(:R).empty? | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-04-13 23:21:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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')) | 
					
						
							|  |  |  |     assert @updater.expectations_met? | 
					
						
							|  |  |  |     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) | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-07-08 19:56:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   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')) | 
					
						
							|  |  |  |     assert @updater.expectations_met? | 
					
						
							|  |  |  |     assert_equal [ | 
					
						
							|  |  |  |       Pathname('someuser-sometap/Formula/antiword.rb'), | 
					
						
							|  |  |  |       Pathname('someuser-sometap/HomebrewFormula/lua.rb'), | 
					
						
							|  |  |  |       Pathname('someuser-sometap/custom-formula.rb'), | 
					
						
							|  |  |  |     ], @report.tapped_formula_for(:A) | 
					
						
							| 
									
										
										
										
											2013-07-08 19:56:43 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-11-14 11:10:43 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_update_homebrew_with_removed_formulae | 
					
						
							|  |  |  |     perform_update(fixture('update_git_diff_output_with_removed_formulae')) | 
					
						
							|  |  |  |     assert @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')) | 
					
						
							|  |  |  |     assert @updater.expectations_met? | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  | end |