| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "testing_env" | 
					
						
							|  |  |  | require "formula" | 
					
						
							| 
									
										
										
										
											2010-02-10 22:21:24 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class PatchingTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2016-08-05 22:04:59 -07:00
										 |  |  |   TESTBALL_URL = "file://#{TEST_DIRECTORY}/tarballs/testball-0.1.tbz".freeze | 
					
						
							|  |  |  |   TESTBALL_PATCHES_URL = "file://#{TEST_DIRECTORY}/tarballs/testball-0.1-patches.tgz".freeze | 
					
						
							|  |  |  |   PATCH_URL_A = "file://#{TEST_DIRECTORY}/patches/noop-a.diff".freeze | 
					
						
							|  |  |  |   PATCH_URL_B = "file://#{TEST_DIRECTORY}/patches/noop-b.diff".freeze | 
					
						
							| 
									
										
										
										
											2014-07-29 16:06:06 -05:00
										 |  |  |   PATCH_A_CONTENTS = File.read "#{TEST_DIRECTORY}/patches/noop-a.diff" | 
					
						
							|  |  |  |   PATCH_B_CONTENTS = File.read "#{TEST_DIRECTORY}/patches/noop-b.diff" | 
					
						
							| 
									
										
										
										
											2016-08-05 22:04:59 -07:00
										 |  |  |   APPLY_A = "noop-a.diff".freeze | 
					
						
							|  |  |  |   APPLY_B = "noop-b.diff".freeze | 
					
						
							|  |  |  |   APPLY_C = "noop-c.diff".freeze | 
					
						
							| 
									
										
										
										
											2014-06-10 20:24:07 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-29 16:06:06 -05:00
										 |  |  |   def formula(*args, &block) | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |     super do | 
					
						
							| 
									
										
										
										
											2016-01-25 08:21:57 -08:00
										 |  |  |       url TESTBALL_URL | 
					
						
							|  |  |  |       sha256 TESTBALL_SHA256 | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |       class_eval(&block) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-23 21:39:10 -05:00
										 |  |  |   def teardown | 
					
						
							|  |  |  |     @_f.clear_cache | 
					
						
							| 
									
										
										
										
											2015-08-17 17:08:23 +02:00
										 |  |  |     @_f.patchlist.each { |p| p.clear_cache if p.external? } | 
					
						
							| 
									
										
										
										
											2014-06-23 21:39:10 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-26 20:51:43 -05:00
										 |  |  |   def assert_patched(formula) | 
					
						
							|  |  |  |     shutup do | 
					
						
							|  |  |  |       formula.brew do | 
					
						
							|  |  |  |         formula.patch | 
					
						
							|  |  |  |         s = File.read("libexec/NOOP") | 
					
						
							|  |  |  |         refute_includes s, "NOOP", "libexec/NOOP was not patched as expected" | 
					
						
							|  |  |  |         assert_includes s, "ABCD", "libexec/NOOP was not patched as expected" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-02-10 22:21:24 -08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-06-20 00:51:01 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-25 08:21:57 -08:00
										 |  |  |   def assert_sequentially_patched(formula) | 
					
						
							|  |  |  |     shutup do | 
					
						
							|  |  |  |       formula.brew do | 
					
						
							|  |  |  |         formula.patch | 
					
						
							|  |  |  |         s = File.read("libexec/NOOP") | 
					
						
							|  |  |  |         refute_includes s, "NOOP", "libexec/NOOP was not patched as expected" | 
					
						
							|  |  |  |         refute_includes s, "ABCD", "libexec/NOOP was not patched as expected" | 
					
						
							|  |  |  |         assert_includes s, "1234", "libexec/NOOP was not patched as expected" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def assert_missing_apply_fail(formula) | 
					
						
							|  |  |  |     assert_raises(MissingApplyError) do | 
					
						
							|  |  |  |       shutup do | 
					
						
							|  |  |  |         formula.brew do | 
					
						
							|  |  |  |           formula.patch | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-10 22:21:24 -08:00
										 |  |  |   def test_single_patch | 
					
						
							| 
									
										
										
										
											2014-12-26 20:51:43 -05:00
										 |  |  |     assert_patched formula { | 
					
						
							|  |  |  |       def patches | 
					
						
							|  |  |  |         PATCH_URL_A | 
					
						
							| 
									
										
										
										
											2014-12-26 20:20:10 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2014-12-26 20:51:43 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_single_patch_dsl | 
					
						
							| 
									
										
										
										
											2014-12-26 20:51:43 -05:00
										 |  |  |     assert_patched formula { | 
					
						
							|  |  |  |       patch do | 
					
						
							|  |  |  |         url PATCH_URL_A | 
					
						
							| 
									
										
										
										
											2016-01-25 08:21:57 -08:00
										 |  |  |         sha256 PATCH_A_SHA256 | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_single_patch_dsl_with_apply | 
					
						
							|  |  |  |     assert_patched formula { | 
					
						
							|  |  |  |       patch do | 
					
						
							|  |  |  |         url TESTBALL_PATCHES_URL | 
					
						
							|  |  |  |         sha256 TESTBALL_PATCHES_SHA256 | 
					
						
							|  |  |  |         apply APPLY_A | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_single_patch_dsl_with_sequential_apply | 
					
						
							|  |  |  |     assert_sequentially_patched formula { | 
					
						
							|  |  |  |       patch do | 
					
						
							|  |  |  |         url TESTBALL_PATCHES_URL | 
					
						
							|  |  |  |         sha256 TESTBALL_PATCHES_SHA256 | 
					
						
							|  |  |  |         apply APPLY_A, APPLY_C | 
					
						
							| 
									
										
										
										
											2014-12-26 20:20:10 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2014-12-26 20:51:43 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_single_patch_dsl_with_strip | 
					
						
							| 
									
										
										
										
											2014-12-26 20:51:43 -05:00
										 |  |  |     assert_patched formula { | 
					
						
							|  |  |  |       patch :p1 do | 
					
						
							|  |  |  |         url PATCH_URL_A | 
					
						
							| 
									
										
										
										
											2016-01-25 08:21:57 -08:00
										 |  |  |         sha256 PATCH_A_SHA256 | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_single_patch_dsl_with_strip_with_apply | 
					
						
							|  |  |  |     assert_patched formula { | 
					
						
							|  |  |  |       patch :p1 do | 
					
						
							|  |  |  |         url TESTBALL_PATCHES_URL | 
					
						
							|  |  |  |         sha256 TESTBALL_PATCHES_SHA256 | 
					
						
							|  |  |  |         apply APPLY_A | 
					
						
							| 
									
										
										
										
											2014-12-26 20:20:10 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2014-12-26 20:51:43 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_single_patch_dsl_with_incorrect_strip | 
					
						
							|  |  |  |     assert_raises(ErrorDuringExecution) do | 
					
						
							|  |  |  |       shutup do | 
					
						
							|  |  |  |         formula do | 
					
						
							|  |  |  |           patch :p0 do | 
					
						
							| 
									
										
										
										
											2014-06-10 20:24:07 -05:00
										 |  |  |             url PATCH_URL_A | 
					
						
							| 
									
										
										
										
											2016-01-25 08:21:57 -08:00
										 |  |  |             sha256 PATCH_A_SHA256 | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2016-04-10 22:53:56 -04:00
										 |  |  |         end.brew { |f, _staging| f.patch } | 
					
						
							| 
									
										
										
										
											2016-01-25 08:21:57 -08:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_single_patch_dsl_with_incorrect_strip_with_apply | 
					
						
							|  |  |  |     assert_raises(ErrorDuringExecution) do | 
					
						
							|  |  |  |       shutup do | 
					
						
							|  |  |  |         formula do | 
					
						
							|  |  |  |           patch :p0 do | 
					
						
							|  |  |  |             url TESTBALL_PATCHES_URL | 
					
						
							|  |  |  |             sha256 TESTBALL_PATCHES_SHA256 | 
					
						
							|  |  |  |             apply APPLY_A | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2016-04-10 22:53:56 -04:00
										 |  |  |         end.brew { |f, _staging| f.patch } | 
					
						
							| 
									
										
										
										
											2010-02-10 22:21:24 -08:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   def test_patch_p0_dsl | 
					
						
							| 
									
										
										
										
											2014-12-26 20:51:43 -05:00
										 |  |  |     assert_patched formula { | 
					
						
							|  |  |  |       patch :p0 do | 
					
						
							|  |  |  |         url PATCH_URL_B | 
					
						
							| 
									
										
										
										
											2016-01-25 08:21:57 -08:00
										 |  |  |         sha256 PATCH_B_SHA256 | 
					
						
							| 
									
										
										
										
											2014-12-26 20:20:10 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2014-12-26 20:51:43 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-25 08:21:57 -08:00
										 |  |  |   def test_patch_p0_dsl_with_apply | 
					
						
							|  |  |  |     assert_patched formula { | 
					
						
							|  |  |  |       patch :p0 do | 
					
						
							|  |  |  |         url TESTBALL_PATCHES_URL | 
					
						
							|  |  |  |         sha256 TESTBALL_PATCHES_SHA256 | 
					
						
							|  |  |  |         apply APPLY_B | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-05 22:04:59 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-01-25 08:21:57 -08:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   def test_patch_p0 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     assert_patched formula { | 
					
						
							|  |  |  |       def patches | 
					
						
							| 
									
										
										
										
											2016-09-17 15:32:44 +01:00
										 |  |  |         { p0: PATCH_URL_B } | 
					
						
							| 
									
										
										
										
											2015-08-03 21:18:00 +08:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-07 19:41:14 -05:00
										 |  |  |   def test_patch_array | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     assert_patched formula { | 
					
						
							|  |  |  |       def patches | 
					
						
							|  |  |  |         [PATCH_URL_A] | 
					
						
							| 
									
										
										
										
											2015-08-03 21:18:00 +08:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-02-10 22:21:24 -08:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   def test_patch_hash | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     assert_patched formula { | 
					
						
							|  |  |  |       def patches | 
					
						
							| 
									
										
										
										
											2016-09-17 15:32:44 +01:00
										 |  |  |         { p1: PATCH_URL_A } | 
					
						
							| 
									
										
										
										
											2015-08-03 21:18:00 +08:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-02-10 22:21:24 -08:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   def test_patch_hash_array | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     assert_patched formula { | 
					
						
							|  |  |  |       def patches | 
					
						
							| 
									
										
										
										
											2016-09-17 15:32:44 +01:00
										 |  |  |         { p1: [PATCH_URL_A] } | 
					
						
							| 
									
										
										
										
											2015-08-03 21:18:00 +08:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_patch_string | 
					
						
							| 
									
										
										
										
											2014-12-26 20:51:43 -05:00
										 |  |  |     assert_patched formula { patch PATCH_A_CONTENTS } | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_patch_string_with_strip | 
					
						
							| 
									
										
										
										
											2014-12-26 20:51:43 -05:00
										 |  |  |     assert_patched formula { patch :p0, PATCH_B_CONTENTS } | 
					
						
							| 
									
										
										
										
											2010-02-10 22:21:24 -08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-07-29 16:06:06 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-05 22:04:59 -07:00
										 |  |  |   def test_patch_data_constant | 
					
						
							| 
									
										
										
										
											2014-12-26 20:51:43 -05:00
										 |  |  |     assert_patched formula("test", Pathname.new(__FILE__).expand_path) { | 
					
						
							|  |  |  |       def patches | 
					
						
							| 
									
										
										
										
											2015-07-21 22:14:04 +08:00
										 |  |  |         :DATA | 
					
						
							| 
									
										
										
										
											2014-12-26 20:20:10 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2014-12-26 20:51:43 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-07-29 16:06:06 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-01-25 08:21:57 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_single_patch_missing_apply_fail | 
					
						
							|  |  |  |     assert_missing_apply_fail formula { | 
					
						
							|  |  |  |       def patches | 
					
						
							|  |  |  |         TESTBALL_PATCHES_URL | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_single_patch_dsl_missing_apply_fail | 
					
						
							|  |  |  |     assert_missing_apply_fail formula { | 
					
						
							|  |  |  |       patch do | 
					
						
							|  |  |  |         url TESTBALL_PATCHES_URL | 
					
						
							|  |  |  |         sha256 TESTBALL_PATCHES_SHA256 | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_single_patch_dsl_with_apply_enoent_fail | 
					
						
							|  |  |  |     assert_raises(ErrorDuringExecution) do | 
					
						
							|  |  |  |       shutup do | 
					
						
							|  |  |  |         formula do | 
					
						
							|  |  |  |           patch do | 
					
						
							|  |  |  |             url TESTBALL_PATCHES_URL | 
					
						
							|  |  |  |             sha256 TESTBALL_PATCHES_SHA256 | 
					
						
							|  |  |  |             apply "patches/#{APPLY_A}" | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2016-04-10 22:53:56 -04:00
										 |  |  |         end.brew { |f, _staging| f.patch } | 
					
						
							| 
									
										
										
										
											2016-01-25 08:21:57 -08:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-02-10 22:21:24 -08:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2014-07-29 16:06:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | __END__
 | 
					
						
							|  |  |  | diff --git a/libexec/NOOP b/libexec/NOOP | 
					
						
							|  |  |  | index bfdda4c..e08d8f4 100755
 | 
					
						
							|  |  |  | --- a/libexec/NOOP | 
					
						
							|  |  |  | +++ b/libexec/NOOP | 
					
						
							|  |  |  | @@ -1,2 +1,2 @@ | 
					
						
							|  |  |  |  #!/bin/bash | 
					
						
							|  |  |  | -echo NOOP | 
					
						
							|  |  |  | \ No newline at end of file | 
					
						
							|  |  |  | +echo ABCD | 
					
						
							|  |  |  | \ No newline at end of file |