aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBaptiste Fontaine2015-12-19 11:54:53 +0100
committerBaptiste Fontaine2015-12-20 12:11:40 +0100
commita6d2723ef532dc576968f6f9e155c165e47f26b2 (patch)
tree46cff38bb79e50f6533ceceb83e19e5f9b865385
parentf25894981663ba20596483d8391be232226a4954 (diff)
downloadbrew-a6d2723ef532dc576968f6f9e155c165e47f26b2.tar.bz2
more core unit tests
Closes Homebrew/homebrew#47182. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
-rw-r--r--Library/Homebrew/test/test_json.rb4
-rw-r--r--Library/Homebrew/test/test_patch.rb23
-rw-r--r--Library/Homebrew/test/test_pkg_version.rb10
-rw-r--r--Library/Homebrew/test/test_string.rb6
4 files changed, 43 insertions, 0 deletions
diff --git a/Library/Homebrew/test/test_json.rb b/Library/Homebrew/test/test_json.rb
index 5724cf41f..14d2f2b4c 100644
--- a/Library/Homebrew/test/test_json.rb
+++ b/Library/Homebrew/test/test_json.rb
@@ -13,4 +13,8 @@ class JsonSmokeTest < Homebrew::TestCase
json = '{"foo":["bar","baz"],"qux":1}'
assert_equal hash, Utils::JSON.load(json)
end
+
+ def test_decode_failure
+ assert_raises(Utils::JSON::Error) { Utils::JSON.load("nope") }
+ end
end
diff --git a/Library/Homebrew/test/test_patch.rb b/Library/Homebrew/test/test_patch.rb
index 214955ef1..4aa1a1623 100644
--- a/Library/Homebrew/test/test_patch.rb
+++ b/Library/Homebrew/test/test_patch.rb
@@ -35,6 +35,7 @@ class PatchTests < Homebrew::TestCase
def test_raises_for_unknown_values
assert_raises(ArgumentError) { Patch.create(Object.new) }
+ assert_raises(ArgumentError) { Patch.create(Object.new, Object.new) }
end
end
@@ -100,3 +101,25 @@ class LegacyPatchTests < Homebrew::TestCase
assert_empty Patch.normalize_legacy_patches(nil)
end
end
+
+class EmbeddedPatchTests < Homebrew::TestCase
+ def test_inspect
+ p = EmbeddedPatch.new :p1
+ assert_equal "#<EmbeddedPatch: :p1>", p.inspect
+ end
+end
+
+class ExternalPatchTests < Homebrew::TestCase
+ def setup
+ @p = ExternalPatch.new(:p1) { url "file:///my.patch" }
+
+ end
+
+ def test_url
+ assert_equal "file:///my.patch", @p.url
+ end
+
+ def test_inspect
+ assert_equal %(#<ExternalPatch: :p1 "file:///my.patch">), @p.inspect
+ end
+end
diff --git a/Library/Homebrew/test/test_pkg_version.rb b/Library/Homebrew/test/test_pkg_version.rb
index da2fe8ebc..06a57b734 100644
--- a/Library/Homebrew/test/test_pkg_version.rb
+++ b/Library/Homebrew/test/test_pkg_version.rb
@@ -37,4 +37,14 @@ class PkgVersionTests < Homebrew::TestCase
assert_equal "1.0", PkgVersion.new(Version.new("1.0"), 0).to_s
assert_equal "HEAD", PkgVersion.new(Version.new("HEAD"), 1).to_s
end
+
+ def test_hash
+ p1 = PkgVersion.new(Version.new("1.0"), 1)
+ p2 = PkgVersion.new(Version.new("1.0"), 1)
+ p3 = PkgVersion.new(Version.new("1.1"), 1)
+ p4 = PkgVersion.new(Version.new("1.0"), 0)
+ assert_equal p1.hash, p2.hash
+ refute_equal p1.hash, p3.hash
+ refute_equal p1.hash, p4.hash
+ end
end
diff --git a/Library/Homebrew/test/test_string.rb b/Library/Homebrew/test/test_string.rb
index 44582c510..d3f2bc268 100644
--- a/Library/Homebrew/test/test_string.rb
+++ b/Library/Homebrew/test/test_string.rb
@@ -31,4 +31,10 @@ I'm not indented
assert_equal "hello\ngoodbye\n\n", undented
end
+
+ def test_inreplace_sub_failure
+ s = "foobar".extend StringInreplaceExtension
+ s.sub! "not here", "test"
+ assert_equal [%(expected replacement of "not here" with "test")], s.errors
+ end
end