aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/test_patch.rb63
-rw-r--r--Library/Homebrew/test/test_patches.rb88
-rw-r--r--Library/Homebrew/test/test_patching.rb147
3 files changed, 181 insertions, 117 deletions
diff --git a/Library/Homebrew/test/test_patch.rb b/Library/Homebrew/test/test_patch.rb
index 1cc1ac7af..9056e8371 100644
--- a/Library/Homebrew/test/test_patch.rb
+++ b/Library/Homebrew/test/test_patch.rb
@@ -50,3 +50,66 @@ class PatchTests < Test::Unit::TestCase
assert_raises(ArgumentError) { Patch.create(Object.new) }
end
end
+
+class LegacyPatchTests < Test::Unit::TestCase
+ def test_patch_single_string
+ patches = Patch.normalize_legacy_patches("http://example.com/patch.diff")
+ assert_equal 1, patches.length
+ assert_equal :p1, patches.first.strip
+ end
+
+ def test_patch_array
+ patches = Patch.normalize_legacy_patches(
+ %w{http://example.com/patch1.diff http://example.com/patch2.diff}
+ )
+
+ assert_equal 2, patches.length
+ assert_equal :p1, patches[0].strip
+ assert_equal :p1, patches[1].strip
+ end
+
+ def test_p0_hash_to_string
+ patches = Patch.normalize_legacy_patches(
+ :p0 => "http://example.com/patch.diff"
+ )
+
+ assert_equal 1, patches.length
+ assert_equal :p0, patches.first.strip
+ end
+
+ def test_p1_hash_to_string
+ patches = Patch.normalize_legacy_patches(
+ :p1 => "http://example.com/patch.diff"
+ )
+
+ assert_equal 1, patches.length
+ assert_equal :p1, patches.first.strip
+ end
+
+ def test_mixed_hash_to_strings
+ patches = Patch.normalize_legacy_patches(
+ :p1 => "http://example.com/patch1.diff",
+ :p0 => "http://example.com/patch0.diff"
+ )
+ assert_equal 2, patches.length
+ assert_equal 1, patches.select { |p| p.strip == :p0 }.length
+ assert_equal 1, patches.select { |p| p.strip == :p1 }.length
+ end
+
+ def test_mixed_hash_to_arrays
+ patches = Patch.normalize_legacy_patches(
+ :p1 => ["http://example.com/patch10.diff",
+ "http://example.com/patch11.diff"],
+ :p0 => ["http://example.com/patch00.diff",
+ "http://example.com/patch01.diff"]
+ )
+
+ assert_equal 4, patches.length
+ assert_equal 2, patches.select { |p| p.strip == :p0 }.length
+ assert_equal 2, patches.select { |p| p.strip == :p1 }.length
+ end
+
+ def test_nil
+ assert_empty Patch.normalize_legacy_patches(nil)
+ end
+end
diff --git a/Library/Homebrew/test/test_patches.rb b/Library/Homebrew/test/test_patches.rb
deleted file mode 100644
index 668d4b395..000000000
--- a/Library/Homebrew/test/test_patches.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-require 'testing_env'
-require 'test/testball'
-require 'set'
-
-# Expose some internals
-class Patches
- attr_reader :patches
-end
-
-class Patch
- attr_reader :patch_p
- attr_reader :patch_filename
-end
-
-
-class PatchingTests < Test::Unit::TestCase
- def test_patchSingleString
- patches = Patches.new("http://example.com/patch.diff")
- assert_equal 1, patches.patches.length
- p = patches.patches[0]
- assert_equal :p1, p.patch_p
- end
-
- def test_patchArray
- patches = Patches.new(["http://example.com/patch1.diff", "http://example.com/patch2.diff"])
- assert_equal 2, patches.patches.length
-
- p1 = patches.patches[0]
- assert_equal :p1, p1.patch_p
-
- p2 = patches.patches[0]
- assert_equal :p1, p2.patch_p
- end
-
- def test_p0_hash_to_string
- patches = Patches.new({
- :p0 => "http://example.com/patch.diff"
- })
- assert_equal 1, patches.patches.length
-
- p = patches.patches[0]
- assert_equal :p0, p.patch_p
- end
-
- def test_p1_hash_to_string
- patches = Patches.new({
- :p1 => "http://example.com/patch.diff"
- })
- assert_equal 1, patches.patches.length
-
- p = patches.patches[0]
- assert_equal :p1, p.patch_p
- end
-
- def test_mixed_hash_to_strings
- expected = {
- :p1 => "http://example.com/patch1.diff",
- :p0 => "http://example.com/patch0.diff"
- }
- patches = Patches.new(expected)
- assert_equal 2, patches.patches.length
-
- # Make sure unique filenames were assigned
- filenames = Set.new
- patches.each do |p|
- filenames << p.patch_filename
- end
-
- assert_equal 2, filenames.size
- end
-
- def test_mixed_hash_to_arrays
- expected = {
- :p1 => ["http://example.com/patch10.diff","http://example.com/patch11.diff"],
- :p0 => ["http://example.com/patch00.diff","http://example.com/patch01.diff"]
- }
- patches = Patches.new(expected)
- assert_equal 4, patches.patches.length
-
- # Make sure unique filenames were assigned
- filenames = Set.new
- patches.each do |p|
- filenames << p.patch_filename
- end
-
- assert_equal 4, filenames.size
- end
-end
diff --git a/Library/Homebrew/test/test_patching.rb b/Library/Homebrew/test/test_patching.rb
index 6642704c0..a82a8092a 100644
--- a/Library/Homebrew/test/test_patching.rb
+++ b/Library/Homebrew/test/test_patching.rb
@@ -1,64 +1,153 @@
require 'testing_env'
-require 'test/testball'
+require 'formula'
+require 'testball'
class PatchingTests < Test::Unit::TestCase
- def read_file path
- File.open(path, 'r') { |f| f.read }
+ def formula(&block)
+ super do
+ url "file:///#{TEST_FOLDER}/tarballs/testball-0.1.tbz"
+ sha1 "482e737739d946b7c8cbaf127d9ee9c148b999f5"
+ class_eval(&block)
+ end
+ end
+
+ def assert_patched(path)
+ s = File.read(path)
+ assert !s.include?("NOOP"), "File was unpatched."
+ assert s.include?("ABCD"), "File was not patched as expected."
end
def test_single_patch
shutup do
- Class.new(TestBall) do
+ formula do
def patches
"file:///#{TEST_FOLDER}/patches/noop-a.diff"
end
- end.new("test_single_patch").brew do
- s = read_file 'libexec/NOOP'
- assert !s.include?("NOOP"), "File was unpatched."
- assert s.include?("ABCD"), "File was not patched as expected."
+ end.brew { assert_patched 'libexec/NOOP' }
+ end
+ end
+
+ def test_single_patch_dsl
+ shutup do
+ formula do
+ patch do
+ url "file:///#{TEST_FOLDER}/patches/noop-a.diff"
+ 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
+ url "file:///#{TEST_FOLDER}/patches/noop-a.diff"
+ 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
+ url "file:///#{TEST_FOLDER}/patches/noop-a.diff"
+ sha1 "fa8af2e803892e523fdedc6b758117c45e5749a2"
+ end
+ end.brew { }
end
end
end
+ def test_patch_p0_dsl
+ shutup do
+ formula do
+ patch :p0 do
+ url "file:///#{TEST_FOLDER}/patches/noop-b.diff"
+ sha1 "3b54bd576f998ef6d6623705ee023b55062b9504"
+ end
+ end.brew { assert_patched 'libexec/NOOP' }
+ end
+ end
+
+ def test_patch_p0
+ shutup do
+ formula do
+ def patches
+ { :p0 => "file:///#{TEST_FOLDER}/patches/noop-b.diff" }
+ end
+ end.brew { assert_patched 'libexec/NOOP' }
+ end
+ end
+
def test_patch_array
shutup do
- Class.new(TestBall) do
+ formula do
def patches
["file:///#{TEST_FOLDER}/patches/noop-a.diff"]
end
- end.new("test_patch_array").brew do
- s = read_file 'libexec/NOOP'
- assert !s.include?("NOOP"), "File was unpatched."
- assert s.include?("ABCD"), "File was not patched as expected."
- end
+ end.brew { assert_patched 'libexec/noop' }
end
end
- def test_patch_p0
+ def test_patch_hash
shutup do
- Class.new(TestBall) do
+ formula do
def patches
- "file:///#{TEST_FOLDER}/patches/noop-a.diff"
+ { :p1 => "file:///#{TEST_FOLDER}/patches/noop-a.diff" }
end
- end.new("test_patch_p0").brew do
- s = read_file 'libexec/NOOP'
- assert !s.include?("NOOP"), "File was unpatched."
- assert s.include?("ABCD"), "File was not patched as expected."
- end
+ end.brew { assert_patched 'libexec/noop' }
end
end
- def test_patch_p1
+ def test_patch_hash_array
shutup do
- Class.new(TestBall) do
+ formula do
def patches
{ :p1 => ["file:///#{TEST_FOLDER}/patches/noop-a.diff"] }
end
- end.new("test_patch_p1").brew do
- s = read_file 'libexec/NOOP'
- assert !s.include?("NOOP"), "File was unpatched."
- assert s.include?("ABCD"), "File was not patched as expected."
- end
+ end.brew { assert_patched 'libexec/noop' }
+ end
+ end
+
+ def test_patch_string
+ shutup do
+ formula do
+ patch %q{
+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
+}
+ end.brew { assert_patched 'libexec/noop' }
+ end
+ end
+
+ def test_patch_string_with_strip
+ shutup do
+ formula do
+ patch :p0, %q{
+diff --git libexec/NOOP libexec/NOOP
+index bfdda4c..e08d8f4 100755
+--- libexec/NOOP
++++ libexec/NOOP
+@@ -1,2 +1,2 @@
+ #!/bin/bash
+-echo NOOP
+\ No newline at end of file
++echo ABCD
+\ No newline at end of file
+}
+ end.brew { assert_patched 'libexec/noop' }
end
end
end