mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
DependencyCollector: return created dep from #add
This commit is contained in:
parent
210401654b
commit
26c0524f1a
@ -26,16 +26,23 @@ class DependencyCollector
|
|||||||
@requirements = ComparableSet.new
|
@requirements = ComparableSet.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def add spec
|
def add(spec)
|
||||||
tag = nil
|
case dep = build(spec)
|
||||||
spec, tag = spec.shift if spec.is_a? Hash
|
when Dependency
|
||||||
|
@deps << dep
|
||||||
|
when Requirement
|
||||||
|
@requirements << dep
|
||||||
|
end
|
||||||
|
dep
|
||||||
|
end
|
||||||
|
|
||||||
dep = parse_spec(spec, tag)
|
def build(spec)
|
||||||
# Some symbol specs are conditional, and resolve to nil if there is no
|
spec, tag = case spec
|
||||||
# dependency needed for the current platform.
|
when Hash then spec.shift
|
||||||
return if dep.nil?
|
else spec
|
||||||
# Add dep to the correct bucket
|
end
|
||||||
(dep.is_a?(Requirement) ? @requirements : @deps) << dep
|
|
||||||
|
parse_spec(spec, tag)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -24,6 +24,11 @@ class DependencyCollectorTests < Test::Unit::TestCase
|
|||||||
assert_equal 2, @d.find_dependency('bar').tags.length
|
assert_equal 2, @d.find_dependency('bar').tags.length
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_add_returns_created_dep
|
||||||
|
ret = @d.add 'foo'
|
||||||
|
assert_equal Dependency.new('foo'), ret
|
||||||
|
end
|
||||||
|
|
||||||
def test_dependency_tags
|
def test_dependency_tags
|
||||||
assert Dependency.new('foo', :build).build?
|
assert Dependency.new('foo', :build).build?
|
||||||
assert Dependency.new('foo', [:build, :optional]).optional?
|
assert Dependency.new('foo', [:build, :optional]).optional?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user