From bc6e4a189491f0e3f911b879efec3e570029dd8e Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Thu, 13 Mar 2014 19:51:23 -0500 Subject: New patch implementation and DSL This commit introduces a new patch implementation that supports checksums and caching. Patches are declared in blocks: patch do url ... sha1 ... end A strip level of -p1 is assumed. It can be overridden using a symbol argument: patch :p0 do url ... sha1 ... end Patches can be declared in stable, devel, and head blocks. This form is preferred over using conditionals. stable do # ... patch do url ... sha1 ... end end Embedded (__END__) patches are declared like so: patch :DATA patch :p0, :DATA Patches can also be embedded by passing a string. This makes it possible to provide multiple embedded patches while making only some of them conditional. patch :p0, "..." --- Library/Homebrew/test/test_patch.rb | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Library/Homebrew/test/test_patch.rb (limited to 'Library/Homebrew/test/test_patch.rb') diff --git a/Library/Homebrew/test/test_patch.rb b/Library/Homebrew/test/test_patch.rb new file mode 100644 index 000000000..1cc1ac7af --- /dev/null +++ b/Library/Homebrew/test/test_patch.rb @@ -0,0 +1,52 @@ +require 'testing_env' +require 'patch' + +class PatchTests < Test::Unit::TestCase + def test_create_simple + patch = Patch.create(:p2) + assert_kind_of ExternalPatch, patch + assert patch.external? + assert_equal :p2, patch.strip + end + + def test_create_io + patch = Patch.create(:p0, StringIO.new("foo")) + assert_kind_of IOPatch, patch + assert !patch.external? + assert_equal :p0, patch.strip + end + + def test_create_io_without_strip + patch = Patch.create(StringIO.new("foo")) + assert_kind_of IOPatch, patch + assert_equal :p1, patch.strip + end + + def test_create_string + patch = Patch.create(:p0, "foo") + assert_kind_of IOPatch, patch + assert_equal :p0, patch.strip + end + + def test_create_string_without_strip + patch = Patch.create("foo") + assert_kind_of IOPatch, patch + assert_equal :p1, patch.strip + end + + def test_create_DATA + patch = Patch.create(:p0, :DATA) + assert_kind_of IOPatch, patch + assert_equal :p0, patch.strip + end + + def test_create_DATA_without_strip + patch = Patch.create(:DATA) + assert_kind_of IOPatch, patch + assert_equal :p1, patch.strip + end + + def test_raises_for_unknown_values + assert_raises(ArgumentError) { Patch.create(Object.new) } + end +end -- cgit v1.2.3