aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Vandenberg2010-02-10 22:21:24 -0800
committerAdam Vandenberg2010-04-06 08:27:10 -0700
commitfd453107c6bade4320ca7bafcc7707eef24ce01e (patch)
treef3ca37be4314ec1596547d9980ce78e6508bbbf6
parent298c74d147479186dbe1f99988ccda1de0747753 (diff)
downloadbrew-fd453107c6bade4320ca7bafcc7707eef24ce01e.tar.bz2
Add tests for patching.
-rw-r--r--Library/Homebrew/test/patches/noop-a.diff10
-rw-r--r--Library/Homebrew/test/patches/noop-b.diff10
-rw-r--r--Library/Homebrew/test/test_patching.rb91
-rwxr-xr-xLibrary/Homebrew/test/tests6
4 files changed, 117 insertions, 0 deletions
diff --git a/Library/Homebrew/test/patches/noop-a.diff b/Library/Homebrew/test/patches/noop-a.diff
new file mode 100644
index 000000000..7b57f8fc9
--- /dev/null
+++ b/Library/Homebrew/test/patches/noop-a.diff
@@ -0,0 +1,10 @@
+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
diff --git a/Library/Homebrew/test/patches/noop-b.diff b/Library/Homebrew/test/patches/noop-b.diff
new file mode 100644
index 000000000..bc081ca82
--- /dev/null
+++ b/Library/Homebrew/test/patches/noop-b.diff
@@ -0,0 +1,10 @@
+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
diff --git a/Library/Homebrew/test/test_patching.rb b/Library/Homebrew/test/test_patching.rb
new file mode 100644
index 000000000..df4825711
--- /dev/null
+++ b/Library/Homebrew/test/test_patching.rb
@@ -0,0 +1,91 @@
+require 'testing_env'
+
+require 'extend/ARGV' # needs to be after test/unit to avoid conflict with OptionsParser
+ARGV.extend(HomebrewArgvExtension)
+
+require 'formula'
+require 'utils'
+
+
+class TestBall <Formula
+ def initialize name
+ @url="file:///#{TEST_FOLDER}/testball-0.1.tbz"
+ @homepage = 'http://example.com/'
+ @md5='71aa838a9e4050d1876a295a9e62cbe6'
+ super name
+ end
+ def install ; end
+end
+
+
+class DefaultPatchBall <TestBall
+ def patches
+ # Default is p1
+ "file:///#{TEST_FOLDER}/patches/noop-a.diff"
+ end
+end
+
+class ListPatchBall <TestBall
+ def patches
+ ["file:///#{TEST_FOLDER}/patches/noop-a.diff"]
+ end
+end
+
+class P0PatchBall <TestBall
+ def patches
+ { :p0 => ["file:///#{TEST_FOLDER}/patches/noop-b.diff"] }
+ end
+end
+
+class P1PatchBall <TestBall
+ def patches
+ { :p1 => ["file:///#{TEST_FOLDER}/patches/noop-a.diff"] }
+ end
+end
+
+
+class PatchingTests < Test::Unit::TestCase
+ def read_file path
+ File.open(path, 'r') { |f| f.read }
+ end
+
+ def test_single_patch
+ nostdout do
+ DefaultPatchBall.new('test_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
+ end
+ end
+
+ def test_patch_list
+ nostdout do
+ ListPatchBall.new('test_patch_list').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
+ end
+
+ def test_p0_patch
+ nostdout do
+ P0PatchBall.new('test_p0_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
+ end
+ end
+
+ def test_p1_patch
+ nostdout do
+ P1PatchBall.new('test_p1_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
+ end
+ end
+end
diff --git a/Library/Homebrew/test/tests b/Library/Homebrew/test/tests
index 5d2f60ae8..a63d5be35 100755
--- a/Library/Homebrew/test/tests
+++ b/Library/Homebrew/test/tests
@@ -8,3 +8,9 @@
# Bulk of the tests
ruby unittest.rb $*
+
+# Patching tests
+ruby test_patching.rb $*
+
+# External dependency tests
+ruby test_external_deps.rb $*