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
|
||||
end
|
||||
|
||||
def add spec
|
||||
tag = nil
|
||||
spec, tag = spec.shift if spec.is_a? Hash
|
||||
def add(spec)
|
||||
case dep = build(spec)
|
||||
when Dependency
|
||||
@deps << dep
|
||||
when Requirement
|
||||
@requirements << dep
|
||||
end
|
||||
dep
|
||||
end
|
||||
|
||||
dep = parse_spec(spec, tag)
|
||||
# Some symbol specs are conditional, and resolve to nil if there is no
|
||||
# dependency needed for the current platform.
|
||||
return if dep.nil?
|
||||
# Add dep to the correct bucket
|
||||
(dep.is_a?(Requirement) ? @requirements : @deps) << dep
|
||||
def build(spec)
|
||||
spec, tag = case spec
|
||||
when Hash then spec.shift
|
||||
else spec
|
||||
end
|
||||
|
||||
parse_spec(spec, tag)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -24,6 +24,11 @@ class DependencyCollectorTests < Test::Unit::TestCase
|
||||
assert_equal 2, @d.find_dependency('bar').tags.length
|
||||
end
|
||||
|
||||
def test_add_returns_created_dep
|
||||
ret = @d.add 'foo'
|
||||
assert_equal Dependency.new('foo'), ret
|
||||
end
|
||||
|
||||
def test_dependency_tags
|
||||
assert Dependency.new('foo', :build).build?
|
||||
assert Dependency.new('foo', [:build, :optional]).optional?
|
||||
|
Loading…
x
Reference in New Issue
Block a user