| 
									
										
										
										
											2010-02-12 14:56:01 -08:00
										 |  |  | require 'testing_env' | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | require 'cmd/update' | 
					
						
							| 
									
										
										
										
											2015-07-05 19:13:02 +08:00
										 |  |  | require "formula_versions" | 
					
						
							| 
									
										
										
										
											2013-03-28 17:37:29 -05:00
										 |  |  | require 'yaml' | 
					
						
							| 
									
										
										
										
											2010-02-12 14:56:01 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class UpdaterTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2014-06-10 20:03:37 -05:00
										 |  |  |   class UpdaterMock < ::Updater | 
					
						
							| 
									
										
										
										
											2015-07-09 12:33:31 +01:00
										 |  |  |     attr_accessor :diff, :expected, :called | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-23 18:41:50 -05:00
										 |  |  |     def initialize(*) | 
					
						
							| 
									
										
										
										
											2014-06-10 20:03:57 -05:00
										 |  |  |       super | 
					
						
							|  |  |  |       @outputs = Hash.new { |h, k| h[k] = [] } | 
					
						
							|  |  |  |       @expected = [] | 
					
						
							|  |  |  |       @called = [] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-10 20:03:37 -05:00
										 |  |  |     def in_repo_expect(cmd, output = '') | 
					
						
							|  |  |  |       @expected << cmd | 
					
						
							|  |  |  |       @outputs[cmd] << output | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-04-13 23:21:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-23 18:50:55 -05:00
										 |  |  |     def `(*args) | 
					
						
							|  |  |  |       cmd = args.join(" ") | 
					
						
							| 
									
										
										
										
											2014-06-10 20:03:37 -05:00
										 |  |  |       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 | 
					
						
							| 
									
										
										
										
											2014-06-23 18:50:55 -05:00
										 |  |  |     alias_method :safe_system, :` | 
					
						
							| 
									
										
										
										
											2015-07-09 12:33:31 +01:00
										 |  |  |     alias_method :system, :` | 
					
						
							| 
									
										
										
										
											2014-07-03 12:57:13 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def inspect | 
					
						
							|  |  |  |       "#<#{self.class.name}>" | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-02-12 14:56:01 -08:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   def fixture(name) | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |     self.class.fixture_data[name] || "" | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-04-13 23:21:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   def self.fixture_data | 
					
						
							| 
									
										
										
										
											2014-06-10 21:49:41 -05:00
										 |  |  |     @fixture_data ||= YAML.load_file("#{TEST_DIRECTORY}/fixtures/updater_fixture.yaml") | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-04-13 23:21:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-15 12:54:03 -05:00
										 |  |  |   def teardown | 
					
						
							|  |  |  |     FileUtils.rm_rf HOMEBREW_LIBRARY.join("Taps") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |   def perform_update(fixture_name="") | 
					
						
							| 
									
										
										
										
											2015-07-05 19:13:02 +08:00
										 |  |  |     Formulary.stubs(:factory).returns(stub(:pkg_version => "1.0")) | 
					
						
							|  |  |  |     FormulaVersions.stubs(:new).returns(stub(:formula_at_revision => "2.0")) | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |     @updater.diff = fixture(fixture_name) | 
					
						
							| 
									
										
										
										
											2015-07-09 12:33:31 +01:00
										 |  |  |     @updater.in_repo_expect("git diff --quiet", true) | 
					
						
							|  |  |  |     @updater.in_repo_expect("git symbolic-ref --short HEAD", "master") | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |     @updater.in_repo_expect("git rev-parse -q --verify HEAD", "1234abcd") | 
					
						
							|  |  |  |     @updater.in_repo_expect("git config core.autocrlf false") | 
					
						
							| 
									
										
										
										
											2015-07-10 00:20:19 +01:00
										 |  |  |     @updater.in_repo_expect("git pull --quiet origin refs/heads/master:refs/remotes/origin/master") | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |     @updater.in_repo_expect("git rev-parse -q --verify HEAD", "3456cdef") | 
					
						
							| 
									
										
										
										
											2015-07-09 12:33:31 +01:00
										 |  |  |     @updater.pull!(:silent => true) | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |     @report.update(@updater.report) | 
					
						
							| 
									
										
										
										
											2015-07-09 12:33:31 +01:00
										 |  |  |     assert_equal @updater.expected, @updater.called | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2014-06-11 12:22:29 -05:00
										 |  |  |     assert_empty @report | 
					
						
							| 
									
										
										
										
											2013-07-09 22:12:08 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-04-13 23:21:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-09 22:12:08 -05:00
										 |  |  |   def test_update_homebrew_without_formulae_changes | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |     perform_update("update_git_diff_output_without_formulae_changes") | 
					
						
							| 
									
										
										
										
											2014-06-11 12:22:29 -05:00
										 |  |  |     assert_empty @report.select_formula(:M) | 
					
						
							|  |  |  |     assert_empty @report.select_formula(:A) | 
					
						
							| 
									
										
										
										
											2014-07-25 10:42:47 -05:00
										 |  |  |     assert_empty @report.select_formula(:D) | 
					
						
							| 
									
										
										
										
											2013-07-09 22:12:08 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-04-13 23:21:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-09 22:12:08 -05:00
										 |  |  |   def test_update_homebrew_with_formulae_changes | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |     perform_update("update_git_diff_output_with_formulae_changes") | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-07-08 19:56:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-14 11:10:43 -06:00
										 |  |  |   def test_update_homebrew_with_removed_formulae | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |     perform_update("update_git_diff_output_with_removed_formulae") | 
					
						
							| 
									
										
										
										
											2013-11-14 11:10:43 -06:00
										 |  |  |     assert_equal %w{libgsasl}, @report.select_formula(:D) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_update_homebrew_with_changed_filetype | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |     perform_update("update_git_diff_output_with_changed_filetype") | 
					
						
							| 
									
										
										
										
											2013-11-14 11:10:43 -06:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_update_homebrew_with_restructured_tap | 
					
						
							|  |  |  |     repo = HOMEBREW_LIBRARY.join("Taps", "foo", "bar") | 
					
						
							|  |  |  |     @updater = UpdaterMock.new(repo) | 
					
						
							|  |  |  |     repo.join("Formula").mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |     perform_update("update_git_diff_output_with_restructured_tap") | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     assert_equal %w{foo/bar/git foo/bar/lua}, @report.select_formula(:A) | 
					
						
							| 
									
										
										
										
											2014-07-31 15:54:03 -05:00
										 |  |  |     assert_empty @report.select_formula(:D) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_update_homebrew_simulate_homebrew_php_restructuring | 
					
						
							|  |  |  |     repo = HOMEBREW_LIBRARY.join("Taps", "foo", "bar") | 
					
						
							|  |  |  |     @updater = UpdaterMock.new(repo) | 
					
						
							|  |  |  |     repo.join("Formula").mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     perform_update("update_git_diff_simulate_homebrew_php_restructuring") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_empty @report.select_formula(:A) | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  |     assert_equal %w{foo/bar/git foo/bar/lua}, @report.select_formula(:D) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-07-26 20:11:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_update_homebrew_with_tap_formulae_changes | 
					
						
							|  |  |  |     repo = HOMEBREW_LIBRARY.join("Taps", "foo", "bar") | 
					
						
							|  |  |  |     @updater = UpdaterMock.new(repo) | 
					
						
							|  |  |  |     repo.join("Formula").mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     perform_update("update_git_diff_output_with_tap_formulae_changes") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_equal %w{foo/bar/lua}, @report.select_formula(:A) | 
					
						
							|  |  |  |     assert_equal %w{foo/bar/git}, @report.select_formula(:M) | 
					
						
							|  |  |  |     assert_empty @report.select_formula(:D) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-01-29 10:41:03 -08:00
										 |  |  | end |