2010-02-10 22:21:24 -08:00
|
|
|
require 'testing_env'
|
2014-03-13 19:51:23 -05:00
|
|
|
require 'formula'
|
|
|
|
require 'testball'
|
2010-02-10 22:21:24 -08:00
|
|
|
|
2014-06-18 20:32:51 -05:00
|
|
|
class PatchingTests < Homebrew::TestCase
|
2014-06-12 17:58:12 -05:00
|
|
|
PATCH_URL_A = "file://#{TEST_DIRECTORY}/patches/noop-a.diff"
|
|
|
|
PATCH_URL_B = "file://#{TEST_DIRECTORY}/patches/noop-b.diff"
|
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"
|
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
|
2014-06-12 17:58:12 -05:00
|
|
|
url "file://#{TEST_DIRECTORY}/tarballs/testball-0.1.tbz"
|
2014-03-13 19:51:23 -05:00
|
|
|
sha1 "482e737739d946b7c8cbaf127d9ee9c148b999f5"
|
|
|
|
class_eval(&block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-23 21:39:10 -05:00
|
|
|
def teardown
|
|
|
|
@_f.clear_cache
|
|
|
|
@_f.patchlist.select(&:external?).each(&:clear_cache)
|
|
|
|
end
|
|
|
|
|
2014-03-13 19:51:23 -05:00
|
|
|
def assert_patched(path)
|
|
|
|
s = File.read(path)
|
2014-06-11 13:03:06 -05:00
|
|
|
refute_includes s, "NOOP", "#{path} was not patched as expected"
|
|
|
|
assert_includes s, "ABCD", "#{path} was not patched as expected"
|
2010-02-10 22:21:24 -08:00
|
|
|
end
|
2012-06-20 00:51:01 -05:00
|
|
|
|
2010-02-10 22:21:24 -08:00
|
|
|
def test_single_patch
|
2012-04-17 19:11:36 -05:00
|
|
|
shutup do
|
2014-03-13 19:51:23 -05:00
|
|
|
formula do
|
2013-04-07 19:41:14 -05:00
|
|
|
def patches
|
2014-06-10 20:24:07 -05:00
|
|
|
PATCH_URL_A
|
2013-04-07 19:41:14 -05:00
|
|
|
end
|
2014-03-13 19:51:23 -05:00
|
|
|
end.brew { assert_patched 'libexec/NOOP' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_single_patch_dsl
|
|
|
|
shutup do
|
|
|
|
formula do
|
|
|
|
patch do
|
2014-06-10 20:24:07 -05:00
|
|
|
url PATCH_URL_A
|
2014-03-13 19:51:23 -05:00
|
|
|
sha1 "fa8af2e803892e523fdedc6b758117c45e5749a2"
|
|
|
|
end
|
|
|
|
end.brew { assert_patched 'libexec/NOOP' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_single_patch_dsl_with_strip
|
|
|
|
shutup do
|
|
|
|
formula do
|
|
|
|
patch :p1 do
|
2014-06-10 20:24:07 -05:00
|
|
|
url PATCH_URL_A
|
2014-03-13 19:51:23 -05:00
|
|
|
sha1 "fa8af2e803892e523fdedc6b758117c45e5749a2"
|
|
|
|
end
|
|
|
|
end.brew { assert_patched 'libexec/NOOP' }
|
|
|
|
end
|
|
|
|
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
|
2014-03-13 19:51:23 -05:00
|
|
|
sha1 "fa8af2e803892e523fdedc6b758117c45e5749a2"
|
|
|
|
end
|
|
|
|
end.brew { }
|
2010-02-10 22:21:24 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-13 19:51:23 -05:00
|
|
|
def test_patch_p0_dsl
|
|
|
|
shutup do
|
|
|
|
formula do
|
|
|
|
patch :p0 do
|
2014-06-10 20:24:07 -05:00
|
|
|
url PATCH_URL_B
|
2014-03-13 19:51:23 -05:00
|
|
|
sha1 "3b54bd576f998ef6d6623705ee023b55062b9504"
|
|
|
|
end
|
|
|
|
end.brew { assert_patched 'libexec/NOOP' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_patch_p0
|
|
|
|
shutup do
|
|
|
|
formula do
|
|
|
|
def patches
|
2014-06-10 20:24:07 -05:00
|
|
|
{ :p0 => PATCH_URL_B }
|
2014-03-13 19:51:23 -05:00
|
|
|
end
|
|
|
|
end.brew { assert_patched 'libexec/NOOP' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-07 19:41:14 -05:00
|
|
|
def test_patch_array
|
2012-04-17 19:11:36 -05:00
|
|
|
shutup do
|
2014-03-13 19:51:23 -05:00
|
|
|
formula do
|
2013-04-07 19:41:14 -05:00
|
|
|
def patches
|
2014-06-10 20:24:07 -05:00
|
|
|
[PATCH_URL_A]
|
2013-04-07 19:41:14 -05:00
|
|
|
end
|
2014-10-26 23:14:52 -05:00
|
|
|
end.brew { assert_patched 'libexec/NOOP' }
|
2010-02-10 22:21:24 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-13 19:51:23 -05:00
|
|
|
def test_patch_hash
|
2012-04-17 19:11:36 -05:00
|
|
|
shutup do
|
2014-03-13 19:51:23 -05:00
|
|
|
formula do
|
2013-04-07 19:41:14 -05:00
|
|
|
def patches
|
2014-06-10 20:24:07 -05:00
|
|
|
{ :p1 => PATCH_URL_A }
|
2013-04-07 19:41:14 -05:00
|
|
|
end
|
2014-10-26 23:14:52 -05:00
|
|
|
end.brew { assert_patched 'libexec/NOOP' }
|
2010-02-10 22:21:24 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-13 19:51:23 -05:00
|
|
|
def test_patch_hash_array
|
2012-04-17 19:11:36 -05:00
|
|
|
shutup do
|
2014-03-13 19:51:23 -05:00
|
|
|
formula do
|
2013-04-07 19:41:14 -05:00
|
|
|
def patches
|
2014-06-10 20:24:07 -05:00
|
|
|
{ :p1 => [PATCH_URL_A] }
|
2013-04-07 19:41:14 -05:00
|
|
|
end
|
2014-10-26 23:14:52 -05:00
|
|
|
end.brew { assert_patched 'libexec/NOOP' }
|
2014-03-13 19:51:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_patch_string
|
|
|
|
shutup do
|
|
|
|
formula do
|
2014-07-29 16:06:06 -05:00
|
|
|
patch PATCH_A_CONTENTS
|
2014-10-26 23:14:52 -05:00
|
|
|
end.brew { assert_patched 'libexec/NOOP' }
|
2014-03-13 19:51:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_patch_string_with_strip
|
|
|
|
shutup do
|
|
|
|
formula do
|
2014-07-29 16:06:06 -05:00
|
|
|
patch :p0, PATCH_B_CONTENTS
|
2014-10-26 23:14:52 -05:00
|
|
|
end.brew { assert_patched 'libexec/NOOP' }
|
2010-02-10 22:21:24 -08:00
|
|
|
end
|
|
|
|
end
|
2014-07-29 16:06:06 -05:00
|
|
|
|
|
|
|
def test_patch_DATA_constant
|
|
|
|
shutup do
|
|
|
|
formula("test", Pathname.new(__FILE__).expand_path) do
|
|
|
|
def patches
|
|
|
|
Formula::DATA
|
|
|
|
end
|
2014-10-26 23:14:52 -05:00
|
|
|
end.brew { assert_patched "libexec/NOOP" }
|
2014-07-29 16:06:06 -05:00
|
|
|
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
|