From cc3d041c263ef88d2d301d06eb17031cfabfc971 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Mon, 25 Jan 2016 08:21:57 -0800 Subject: DSL method "apply" to specify patch files The "apply" DSL method can be called from patch-do blocks to specify the paths within an archive of the desired patch files, which will be applied in the order in which they were supplied to the "apply" calls. If "apply" isn't used, raise an error whenever the extracted directory doesn't contain exactly one file. The "apply" method can be called zero or more times within a patch-do block with the following syntaxes supported: apply "single_apply" apply "multiple_apply_1", "multiple_apply_2" apply [array_of_apply] If apply must be used, a single call using the second syntax above is usually best practice. Each apply leaf should be the relative path to a specific patch file in the extracted directory. For example, if extracting this-v123-patches.tar.gz gives you this-123 this-123/.DS_Store this-123/LICENSE.txt this-123/patches this-123/patches/A.diff this-123/patches/B.diff this-123/patches/C.diff this-123/README.txt and you want to apply only B.diff and C.diff, then you need to use "patches/B.diff" and "patches/C.diff" for the lowest-level apply leaves. The code was provided by Xu Cheng. Any mistakes are mine. --- Library/Homebrew/test/test_patch.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'Library/Homebrew/test/test_patch.rb') diff --git a/Library/Homebrew/test/test_patch.rb b/Library/Homebrew/test/test_patch.rb index 0d0033ee1..3c6743ded 100644 --- a/Library/Homebrew/test/test_patch.rb +++ b/Library/Homebrew/test/test_patch.rb @@ -128,3 +128,28 @@ class ExternalPatchTests < Homebrew::TestCase assert_equal "/tmp/foo.tar.gz", @p.cached_download end end + +class ApplyPatchTests < Homebrew::TestCase + def test_empty_patch_files + patch = Patch.create(:p2, nil) + resource = patch.resource + patch_files = patch.patch_files + assert_kind_of Resource::Patch, resource + assert_equal patch_files, resource.patch_files + assert_equal patch_files, [] + end + + def test_resource_patch_apply_method + patch = Patch.create(:p2, nil) + resource = patch.resource + patch_files = patch.patch_files + resource.apply("patch1.diff") + assert_equal patch_files, ["patch1.diff"] + resource.apply("patch2.diff", "patch3.diff") + assert_equal patch_files, ["patch1.diff", "patch2.diff", "patch3.diff"] + resource.apply(["patch4.diff", "patch5.diff"]) + assert_equal patch_files.count, 5 + resource.apply("patch4.diff", ["patch5.diff", "patch6.diff"], "patch7.diff") + assert_equal patch_files.count, 7 + end +end -- cgit v1.2.3