2 # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
4 # See LICENSE.txt for permissions.
8 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
9 require 'rubygems/version'
11 class TestGemDependency < RubyGemTestCase
16 @pkg1_0 = Gem::Dependency.new 'pkg', ['> 1.0']
17 @pkg1_1 = Gem::Dependency.new 'pkg', ['> 1.1']
19 @oth1_0 = Gem::Dependency.new 'other', ['> 1.0']
21 @r1_0 = Gem::Requirement.new ['> 1.0']
25 assert_equal "pkg", @pkg1_0.name
26 assert_equal @r1_0, @pkg1_0.version_requirements
29 def test_initialize_double
30 dep = Gem::Dependency.new("pkg", ["> 1.0", "< 2.0"])
32 assert_equal Gem::Requirement.new(["> 1.0", "< 2.0"]),
33 dep.version_requirements
36 def test_initialize_empty
37 dep = Gem::Dependency.new("pkg", [])
48 @version_requirement = req
49 @version_requirements = nil
52 assert_equal Gem::Requirement.new([">= 1.0"]), dep.version_requirements
55 def test_initialize_version
56 dep = Gem::Dependency.new 'pkg', Gem::Version.new('2')
58 assert_equal 'pkg', dep.name
60 assert_equal Gem::Requirement.new('= 2'), dep.version_requirements
63 def test_initialize_with_type
64 dep = Gem::Dependency.new("pkg", [], :development)
65 assert_equal(:development, dep.type)
68 def test_type_is_runtime_by_default
69 assert_equal(:runtime, Gem::Dependency.new("pkg", []).type)
72 def test_type_is_restricted
73 assert_raise(ArgumentError) do
74 Gem::Dependency.new("pkg", [:sometimes])
79 assert_equal @pkg1_0, @pkg1_0.dup
80 assert_equal @pkg1_0.dup, @pkg1_0
82 assert_not_equal @pkg1_0, @pkg1_1, "requirements different"
83 assert_not_equal @pkg1_1, @pkg1_0, "requirements different"
85 assert_not_equal @pkg1_0, @oth1_0, "names different"
86 assert_not_equal @oth1_0, @pkg1_0, "names different"
88 assert_not_equal @pkg1_0, Object.new
89 assert_not_equal Object.new, @pkg1_0
93 runtime = Gem::Dependency.new("pkg", [])
94 development = Gem::Dependency.new("pkg", [], :development)
96 assert_not_equal(runtime, development)
100 def dep(name, version)
101 Gem::Dependency.new name, version
108 pa0 = dep 'a', '>= 0'
109 pa0r = dep(/a/, '>= 0')
110 pab0r = dep(/a|b/, '>= 0')
112 assert((a0 =~ a0), 'match self')
113 assert((pa0 =~ a0), 'match version exact')
114 assert((pa0 =~ a1), 'match version')
115 assert((pa0r =~ a0), 'match regex simple')
116 assert((pab0r =~ a0), 'match regex complex')
118 assert(!(pa0r =~ b0), 'fail match regex')
119 assert(!(pa0r =~ Object.new), 'fail match Object')
123 assert_equal @pkg1_0.hash, @pkg1_0.dup.hash
124 assert_equal @pkg1_0.dup.hash, @pkg1_0.hash
126 assert_not_equal @pkg1_0.hash, @pkg1_1.hash, "requirements different"
127 assert_not_equal @pkg1_1.hash, @pkg1_0.hash, "requirements different"
129 assert_not_equal @pkg1_0.hash, @oth1_0.hash, "names different"
130 assert_not_equal @oth1_0.hash, @pkg1_0.hash, "names different"
134 runtime = Gem::Dependency.new("pkg", [])
135 development = Gem::Dependency.new("pkg", [], :development)
137 assert_not_equal(runtime.hash, development.hash)