2009-10-03 11:59:29 -04:00
|
|
|
require_relative 'gemutilities'
|
2010-02-21 21:52:35 -05:00
|
|
|
require 'rubygems/dependency'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
class TestGemDependency < RubyGemTestCase
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def test_subclass
|
|
|
|
sc = Class.new Gem::Dependency
|
|
|
|
def sc.requirement() bogus; end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
out, err = capture_io do
|
|
|
|
assert_equal Gem::Requirement.default, sc.new('a').version_requirement
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
assert_match %r%deprecated%, err
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_initialize
|
2010-02-21 21:52:35 -05:00
|
|
|
d = dep "pkg", "> 1.0"
|
|
|
|
|
|
|
|
assert_equal "pkg", d.name
|
|
|
|
assert_equal req("> 1.0"), d.requirement
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize_double
|
2010-02-21 21:52:35 -05:00
|
|
|
d = dep "pkg", "> 1.0", "< 2.0"
|
|
|
|
assert_equal req("> 1.0", "< 2.0"), d.requirement
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialize_empty
|
2010-02-21 21:52:35 -05:00
|
|
|
d = dep "pkg"
|
|
|
|
assert_equal req(">= 0"), d.requirement
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def test_initialize_type
|
|
|
|
assert_equal :runtime, dep("pkg").type
|
|
|
|
assert_equal :development, dep("pkg", [], :development).type
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
assert_raises ArgumentError do
|
2010-02-21 21:52:35 -05:00
|
|
|
dep "pkg", :sometimes
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def test_initialize_version
|
|
|
|
d = dep "pkg", v("2")
|
|
|
|
assert_equal req("= 2"), d.requirement
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_equals2
|
2010-02-21 21:52:35 -05:00
|
|
|
o = dep "other"
|
|
|
|
d = dep "pkg", "> 1.0"
|
|
|
|
d1 = dep "pkg", "> 1.1"
|
|
|
|
|
|
|
|
assert_equal d, d.dup
|
|
|
|
assert_equal d.dup, d
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
refute_equal d, d1
|
|
|
|
refute_equal d1, d
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
refute_equal d, o
|
|
|
|
refute_equal o, d
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
refute_equal d, Object.new
|
|
|
|
refute_equal Object.new, d
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
def test_equals2_type
|
2010-02-21 21:52:35 -05:00
|
|
|
refute_equal dep("pkg", :runtime), dep("pkg", :development)
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_equals_tilde
|
2010-02-21 21:52:35 -05:00
|
|
|
d = dep "a", "0"
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
assert_match d, d, "matche self"
|
|
|
|
assert_match dep("a", ">= 0"), d, "match version exact"
|
|
|
|
assert_match dep("a", ">= 0"), dep("a", "1"), "match version"
|
|
|
|
assert_match dep(/a/, ">= 0"), d, "match simple regexp"
|
|
|
|
assert_match dep(/a|b/, ">= 0"), d, "match scary regexp"
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
refute_match dep(/a/), dep("b")
|
|
|
|
refute_match dep("a"), Object.new
|
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def test_equals_tilde_escape
|
|
|
|
refute_match dep("a|b"), dep("a", "1")
|
|
|
|
assert_match dep(/a|b/), dep("a", "1")
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_equals_tilde_object
|
2010-02-21 21:52:35 -05:00
|
|
|
o = Object.new
|
|
|
|
def o.name ; 'a' end
|
|
|
|
def o.version ; '0' end
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
assert_match dep("a"), o
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_equals_tilde_spec
|
2010-02-21 21:52:35 -05:00
|
|
|
assert_match dep("a", ">= 0"), spec("a", "0")
|
|
|
|
assert_match dep("a", "1"), spec("a", "1")
|
|
|
|
assert_match dep(/a/, ">= 0"), spec("a", "0")
|
|
|
|
assert_match dep(/a|b/, ">= 0"), spec("b", "0")
|
|
|
|
refute_match dep(/a/, ">= 0"), spec("b", "0")
|
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def test_hash
|
|
|
|
d = dep "pkg", "1.0"
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
assert_equal d.hash, d.dup.hash
|
|
|
|
assert_equal d.dup.hash, d.hash
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
refute_equal dep("pkg", "1.0").hash, dep("pkg", "2.0").hash, "requirement"
|
|
|
|
refute_equal dep("pkg", "1.0").hash, dep("abc", "1.0").hash, "name"
|
|
|
|
refute_equal dep("pkg", :development), dep("pkg", :runtime), "type"
|
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def test_prerelease_eh
|
|
|
|
d = dep "pkg", "= 1"
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
refute d.prerelease?
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
d.prerelease = true
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
assert d.prerelease?
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
d = dep "pkg", "= 1.a"
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
assert d.prerelease?
|
|
|
|
|
|
|
|
d.prerelease = false
|
|
|
|
|
|
|
|
assert d.prerelease?
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
d = dep "pkg", "> 1.a", "> 2"
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
assert d.prerelease?
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
def test_version_requirements_equals_deprecated
|
|
|
|
d = dep "pkg", "1.0"
|
|
|
|
|
|
|
|
out, err = capture_io do
|
|
|
|
d.version_requirements = '2.0'
|
|
|
|
assert_equal Gem::Requirement.new(%w[2.0]), d.requirement
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match %r%deprecated%, err
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|