summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_dependency.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-22 02:52:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-22 02:52:35 +0000
commitb551e8c8b36766651be4e782e09e3b02e7d14a10 (patch)
treee164a1ef908bd4451568abf05b688f1593915b81 /test/rubygems/test_gem_dependency.rb
parent65544f575b25b18dc27f9364f973556ddb48538f (diff)
* lib/rubygems: update to 1.3.6.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems/test_gem_dependency.rb')
-rw-r--r--test/rubygems/test_gem_dependency.rb214
1 files changed, 81 insertions, 133 deletions
diff --git a/test/rubygems/test_gem_dependency.rb b/test/rubygems/test_gem_dependency.rb
index acaa3a8c4e..1f361229a4 100644
--- a/test/rubygems/test_gem_dependency.rb
+++ b/test/rubygems/test_gem_dependency.rb
@@ -1,189 +1,137 @@
-#--
-# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
-# All rights reserved.
-# See LICENSE.txt for permissions.
-#++
-
require_relative 'gemutilities'
-require 'rubygems/version'
+require 'rubygems/dependency'
class TestGemDependency < RubyGemTestCase
- def setup
- super
-
- @pkg1_0 = Gem::Dependency.new 'pkg', ['> 1.0']
- @pkg1_1 = Gem::Dependency.new 'pkg', ['> 1.1']
-
- @oth1_0 = Gem::Dependency.new 'other', ['> 1.0']
+ def test_subclass
+ sc = Class.new Gem::Dependency
+ def sc.requirement() bogus; end
- @r1_0 = Gem::Requirement.new ['> 1.0']
- end
+ out, err = capture_io do
+ assert_equal Gem::Requirement.default, sc.new('a').version_requirement
+ end
- def dep(name, version)
- Gem::Dependency.new name, version
+ assert_match %r%deprecated%, err
end
def test_initialize
- assert_equal "pkg", @pkg1_0.name
- assert_equal @r1_0, @pkg1_0.version_requirements
+ d = dep "pkg", "> 1.0"
+
+ assert_equal "pkg", d.name
+ assert_equal req("> 1.0"), d.requirement
end
def test_initialize_double
- dep = Gem::Dependency.new("pkg", ["> 1.0", "< 2.0"])
-
- assert_equal Gem::Requirement.new(["> 1.0", "< 2.0"]),
- dep.version_requirements
+ d = dep "pkg", "> 1.0", "< 2.0"
+ assert_equal req("> 1.0", "< 2.0"), d.requirement
end
def test_initialize_empty
- dep = Gem::Dependency.new("pkg", [])
- req = @r1_0
-
- req.instance_eval do
- @version = ">= 1.0"
- @op = ">="
- @nums = [1,0]
- @requirements = nil
- end
-
- dep.instance_eval do
- @version_requirement = req
- @version_requirements = nil
- end
-
- assert_equal Gem::Requirement.new([">= 1.0"]), dep.version_requirements
- end
-
- def test_initialize_version
- dep = Gem::Dependency.new 'pkg', Gem::Version.new('2')
-
- assert_equal 'pkg', dep.name
-
- assert_equal Gem::Requirement.new('= 2'), dep.version_requirements
+ d = dep "pkg"
+ assert_equal req(">= 0"), d.requirement
end
- def test_initialize_with_type
- dep = Gem::Dependency.new("pkg", [], :development)
- assert_equal(:development, dep.type)
- end
+ def test_initialize_type
+ assert_equal :runtime, dep("pkg").type
+ assert_equal :development, dep("pkg", [], :development).type
- def test_type_is_runtime_by_default
- assert_equal(:runtime, Gem::Dependency.new("pkg", []).type)
- end
-
- def test_type_is_restricted
assert_raises ArgumentError do
- Gem::Dependency.new("pkg", [:sometimes])
+ dep "pkg", :sometimes
end
end
+ def test_initialize_version
+ d = dep "pkg", v("2")
+ assert_equal req("= 2"), d.requirement
+ end
+
def test_equals2
- assert_equal @pkg1_0, @pkg1_0.dup
- assert_equal @pkg1_0.dup, @pkg1_0
+ o = dep "other"
+ d = dep "pkg", "> 1.0"
+ d1 = dep "pkg", "> 1.1"
+
+ assert_equal d, d.dup
+ assert_equal d.dup, d
- refute_equal @pkg1_0, @pkg1_1, "requirements different"
- refute_equal @pkg1_1, @pkg1_0, "requirements different"
+ refute_equal d, d1
+ refute_equal d1, d
- refute_equal @pkg1_0, @oth1_0, "names different"
- refute_equal @oth1_0, @pkg1_0, "names different"
+ refute_equal d, o
+ refute_equal o, d
- refute_equal @pkg1_0, Object.new
- refute_equal Object.new, @pkg1_0
+ refute_equal d, Object.new
+ refute_equal Object.new, d
end
def test_equals2_type
- runtime = Gem::Dependency.new("pkg", [])
- development = Gem::Dependency.new("pkg", [], :development)
-
- refute_equal(runtime, development)
+ refute_equal dep("pkg", :runtime), dep("pkg", :development)
end
def test_equals_tilde
- a0 = dep 'a', '0'
- a1 = dep 'a', '1'
- b0 = dep 'b', '0'
-
- pa0 = dep 'a', '>= 0'
- pa0r = dep(/a/, '>= 0')
- pab0r = dep(/a|b/, '>= 0')
-
- assert_match a0, a0, 'match self'
- assert_match pa0, a0, 'match version exact'
- assert_match pa0, a1, 'match version'
- assert_match pa0r, a0, 'match regex simple'
- assert_match pab0r, a0, 'match regex complex'
-
- refute_match pa0r, b0, 'fail match regex'
- refute_match pa0r, Object.new, 'fail match Object'
- end
+ d = dep "a", "0"
- def test_equals_tilde_escape
- a1 = Gem::Dependency.new 'a', '1'
+ 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"
- pab1 = Gem::Dependency.new 'a|b', '>= 1'
- pab1r = Gem::Dependency.new(/a|b/, '>= 1')
+ refute_match dep(/a/), dep("b")
+ refute_match dep("a"), Object.new
+ end
- refute_match pab1, a1, 'escaped'
- assert_match pab1r, a1, 'exact regexp'
+ def test_equals_tilde_escape
+ refute_match dep("a|b"), dep("a", "1")
+ assert_match dep(/a|b/), dep("a", "1")
end
def test_equals_tilde_object
- a0 = Object.new
-
- def a0.name() 'a' end
- def a0.version() '0' end
-
- pa0 = Gem::Dependency.new 'a', '>= 0'
+ o = Object.new
+ def o.name ; 'a' end
+ def o.version ; '0' end
- assert_match pa0, a0, 'match version exact'
+ assert_match dep("a"), o
end
def test_equals_tilde_spec
- def spec(name, version)
- Gem::Specification.new do |spec|
- spec.name = name
- spec.version = version
- end
- end
+ 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
- a0 = spec 'a', '0'
- a1 = spec 'a', '1'
- b0 = spec 'b', '0'
+ def test_hash
+ d = dep "pkg", "1.0"
- pa0 = dep 'a', '>= 0'
- pa0r = dep(/a/, '>= 0')
- pab0r = dep(/a|b/, '>= 0')
+ assert_equal d.hash, d.dup.hash
+ assert_equal d.dup.hash, d.hash
- assert_match pa0, a0, 'match version exact'
- assert_match pa0, a1, 'match version'
+ 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
- assert_match pa0r, a0, 'match regex simple'
- assert_match pa0r, a1, 'match regex simple'
+ def test_prerelease_eh
+ d = dep "pkg", "= 1"
- assert_match pab0r, a0, 'match regex complex'
- assert_match pab0r, b0, 'match regex complex'
+ refute d.prerelease?
- refute_match pa0r, b0, 'fail match regex'
- refute_match pa0r, Object.new, 'fail match Object'
- end
+ d.prerelease = true
- def test_hash
- assert_equal @pkg1_0.hash, @pkg1_0.dup.hash
- assert_equal @pkg1_0.dup.hash, @pkg1_0.hash
+ assert d.prerelease?
- refute_equal @pkg1_0.hash, @pkg1_1.hash, "requirements different"
- refute_equal @pkg1_1.hash, @pkg1_0.hash, "requirements different"
+ d = dep "pkg", "= 1.a"
- refute_equal @pkg1_0.hash, @oth1_0.hash, "names different"
- refute_equal @oth1_0.hash, @pkg1_0.hash, "names different"
- end
+ assert d.prerelease?
+
+ d.prerelease = false
+
+ assert d.prerelease?
- def test_hash_type
- runtime = Gem::Dependency.new("pkg", [])
- development = Gem::Dependency.new("pkg", [], :development)
+ d = dep "pkg", "> 1.a", "> 2"
- refute_equal(runtime.hash, development.hash)
+ assert d.prerelease?
end
end