| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | require "testing_env" | 
					
						
							|  |  |  | require "cmd/update-report" | 
					
						
							|  |  |  | require "formula_versions" | 
					
						
							|  |  |  | require "yaml" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ReportTests < Homebrew::TestCase | 
					
						
							|  |  |  |   class ReporterMock < ::Reporter | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     attr_accessor :diff | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 19:17:47 +08:00
										 |  |  |     def initialize(tap) | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |       @tap = tap | 
					
						
							| 
									
										
										
										
											2016-03-08 19:17:47 +08:00
										 |  |  |       ENV["HOMEBREW_UPDATE_BEFORE#{repo_var}"] = "12345678" | 
					
						
							|  |  |  |       ENV["HOMEBREW_UPDATE_AFTER#{repo_var}"] = "abcdef12" | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |       super(tap) | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def fixture(name) | 
					
						
							|  |  |  |     self.class.fixture_data[name] || "" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def self.fixture_data | 
					
						
							|  |  |  |     @fixture_data ||= YAML.load_file("#{TEST_DIRECTORY}/fixtures/updater_fixture.yaml") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def setup | 
					
						
							| 
									
										
										
										
											2016-03-07 18:04:25 +08:00
										 |  |  |     @tap = CoreTap.new | 
					
						
							| 
									
										
										
										
											2016-03-08 19:17:47 +08:00
										 |  |  |     @reporter = ReporterMock.new(@tap) | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     @hub = ReporterHub.new | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def teardown | 
					
						
							|  |  |  |     FileUtils.rm_rf HOMEBREW_LIBRARY.join("Taps") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def perform_update(fixture_name = "") | 
					
						
							|  |  |  |     Formulary.stubs(:factory).returns(stub(:pkg_version => "1.0")) | 
					
						
							|  |  |  |     FormulaVersions.stubs(:new).returns(stub(:formula_at_revision => "2.0")) | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     @reporter.diff = fixture(fixture_name) | 
					
						
							|  |  |  |     @hub.add(@reporter) if @reporter.updated? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_update_report_without_revision_var | 
					
						
							| 
									
										
										
										
											2016-03-08 19:17:47 +08:00
										 |  |  |     ENV.delete_if { |k,v| k.start_with? "HOMEBREW_UPDATE" } | 
					
						
							|  |  |  |     assert_raises(Reporter::ReporterRevisionUnsetError) { Reporter.new(@tap) } | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_update_homebrew_without_any_changes | 
					
						
							|  |  |  |     perform_update | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     assert_empty @hub | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_update_homebrew_without_formulae_changes | 
					
						
							|  |  |  |     perform_update("update_git_diff_output_without_formulae_changes") | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     assert_empty @hub.select_formula(:M) | 
					
						
							|  |  |  |     assert_empty @hub.select_formula(:A) | 
					
						
							|  |  |  |     assert_empty @hub.select_formula(:D) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_update_homebrew_with_formulae_changes | 
					
						
							|  |  |  |     perform_update("update_git_diff_output_with_formulae_changes") | 
					
						
							|  |  |  |     assert_equal %w[xar yajl], @hub.select_formula(:M) | 
					
						
							|  |  |  |     assert_equal %w[antiword bash-completion ddrescue dict lua], @hub.select_formula(:A) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_update_homebrew_with_removed_formulae | 
					
						
							|  |  |  |     perform_update("update_git_diff_output_with_removed_formulae") | 
					
						
							|  |  |  |     assert_equal %w[libgsasl], @hub.select_formula(:D) | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_update_homebrew_with_changed_filetype | 
					
						
							|  |  |  |     perform_update("update_git_diff_output_with_changed_filetype") | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     assert_equal %w[elixir], @hub.select_formula(:M) | 
					
						
							|  |  |  |     assert_equal %w[libbson], @hub.select_formula(:A) | 
					
						
							|  |  |  |     assert_equal %w[libgsasl], @hub.select_formula(:D) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_update_homebrew_with_formula_rename | 
					
						
							|  |  |  |     @tap.stubs(:formula_renames).returns("cv" => "progress") | 
					
						
							|  |  |  |     perform_update("update_git_diff_output_with_formula_rename") | 
					
						
							|  |  |  |     assert_empty @hub.select_formula(:A) | 
					
						
							|  |  |  |     assert_empty @hub.select_formula(:D) | 
					
						
							|  |  |  |     assert_equal [["cv", "progress"]], @hub.select_formula(:R) | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_update_homebrew_with_restructured_tap | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     tap = Tap.new("foo", "bar") | 
					
						
							| 
									
										
										
										
											2016-03-08 19:17:47 +08:00
										 |  |  |     @reporter = ReporterMock.new(tap) | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     tap.path.join("Formula").mkpath | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     perform_update("update_git_diff_output_with_restructured_tap") | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     assert_equal %w[foo/bar/git foo/bar/lua], @hub.select_formula(:A) | 
					
						
							|  |  |  |     assert_empty @hub.select_formula(:D) | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_update_homebrew_simulate_homebrew_php_restructuring | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     tap = Tap.new("foo", "bar") | 
					
						
							| 
									
										
										
										
											2016-03-08 19:17:47 +08:00
										 |  |  |     @reporter = ReporterMock.new(tap) | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     tap.path.join("Formula").mkpath | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     perform_update("update_git_diff_simulate_homebrew_php_restructuring") | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     assert_empty @hub.select_formula(:A) | 
					
						
							|  |  |  |     assert_equal %w[foo/bar/git foo/bar/lua], @hub.select_formula(:D) | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_update_homebrew_with_tap_formulae_changes | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     tap = Tap.new("foo", "bar") | 
					
						
							| 
									
										
										
										
											2016-03-08 19:17:47 +08:00
										 |  |  |     @reporter = ReporterMock.new(tap) | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     tap.path.join("Formula").mkpath | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     perform_update("update_git_diff_output_with_tap_formulae_changes") | 
					
						
							| 
									
										
										
										
											2016-02-25 16:53:44 +08:00
										 |  |  |     assert_equal %w[foo/bar/lua], @hub.select_formula(:A) | 
					
						
							|  |  |  |     assert_equal %w[foo/bar/git], @hub.select_formula(:M) | 
					
						
							|  |  |  |     assert_empty @hub.select_formula(:D) | 
					
						
							| 
									
										
										
										
											2016-01-10 20:28:52 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | end |