Commit fefbe452 authored by Samuel Giddins's avatar Samuel Giddins

[PodfileValidator] Fix abstract-only dependency check

parent fedede87
...@@ -7,7 +7,7 @@ GIT ...@@ -7,7 +7,7 @@ GIT
GIT GIT
remote: https://github.com/CocoaPods/Core.git remote: https://github.com/CocoaPods/Core.git
revision: 930de7aeb3f50eccf6d65b4d479daa3f5a956f87 revision: 9fd6c128f989655cf48b07f7145d73ad02ab0694
branch: seg-podfile-refactor branch: seg-podfile-refactor
specs: specs:
cocoapods-core (0.39.0) cocoapods-core (0.39.0)
......
...@@ -112,18 +112,11 @@ module Pod ...@@ -112,18 +112,11 @@ module Pod
end end
def validate_no_abstract_only_pods! def validate_no_abstract_only_pods!
abstract_pods = ->(target_definition) do all_dependencies = podfile.dependencies
if !target_definition.abstract? || !target_definition.children.empty? concrete_dependencies = podfile.target_definition_list.reject(&:abstract?).flat_map(&:dependencies).uniq
target_definition.children.flat_map do |td| abstract_only_dependencies = all_dependencies - concrete_dependencies
abstract_pods[td] abstract_only_dependencies.each do |dep|
end add_error "The dependency `#{dep}` is not used in any concrete target."
else
target_definition.dependencies
end
end
pods = podfile.root_target_definitions.flat_map(&abstract_pods).uniq
pods.each do |pod|
add_error "The dependency `#{pod}` is not used in any concrete target."
end end
end end
end end
......
...@@ -63,6 +63,7 @@ module Pod ...@@ -63,6 +63,7 @@ module Pod
end end
end end
describe 'empty podfiles' do
it 'warns if the podfile does not contain any dependency' do it 'warns if the podfile does not contain any dependency' do
podfile = Pod::Podfile.new podfile = Pod::Podfile.new
validator = Installer::PodfileValidator.new(podfile) validator = Installer::PodfileValidator.new(podfile)
...@@ -73,4 +74,113 @@ module Pod ...@@ -73,4 +74,113 @@ module Pod
validator.warnings.should == ['The Podfile does not contain any dependencies.'] validator.warnings.should == ['The Podfile does not contain any dependencies.']
end end
end end
describe 'abstract-only dependencies' do
it 'errors when there is only a root target' do
podfile = Pod::Podfile.new do
pod 'Alamofire'
end
validator = Installer::PodfileValidator.new(podfile)
validator.validate
validator.should.not.be.valid
validator.errors.should == ['The dependency `Alamofire` is not used in any concrete target.']
end
it 'errors when there are only abstract targets' do
podfile = Pod::Podfile.new do
abstract_target 'Abstract' do
pod 'Alamofire'
end
end
validator = Installer::PodfileValidator.new(podfile)
validator.validate
validator.should.not.be.valid
validator.errors.should == ['The dependency `Alamofire` is not used in any concrete target.']
end
it 'does not error when an abstract target has concrete children with complete inheritance' do
podfile = Pod::Podfile.new do
abstract_target 'Abstract' do
pod 'Alamofire'
target 'Concrete'
end
end
validator = Installer::PodfileValidator.new(podfile)
validator.validate
validator.should.be.valid
validator.errors.should.be.empty
end
it 'errors when an abstract target has concrete children with no inheritance' do
podfile = Pod::Podfile.new do
abstract_target 'Abstract' do
pod 'Alamofire'
target 'Concrete' do
inherit! :none
end
end
end
validator = Installer::PodfileValidator.new(podfile)
validator.validate
validator.should.not.be.valid
validator.errors.should == ['The dependency `Alamofire` is not used in any concrete target.']
end
it 'errors when an abstract target has concrete children with only search_paths inheritance' do
podfile = Pod::Podfile.new do
abstract_target 'Abstract' do
pod 'Alamofire'
target 'Concrete' do
inherit! :search_paths
end
end
end
validator = Installer::PodfileValidator.new(podfile)
validator.validate
validator.should.not.be.valid
validator.errors.should == ['The dependency `Alamofire` is not used in any concrete target.']
end
it 'does not error when an abstract target has multiple children with varied inheritance' do
podfile = Pod::Podfile.new do
abstract_target 'Abstract' do
pod 'Alamofire'
target 'Concrete' do
inherit! :none
end
target 'Other Concrete' do
end
end
end
validator = Installer::PodfileValidator.new(podfile)
validator.validate
validator.should.be.valid
validator.errors.should.be.empty
end
it 'does not error when an abstract target has multiple children with varied inheritance' do
podfile = Pod::Podfile.new do
abstract_target 'Abstract' do
pod 'Alamofire'
target 'Concrete' do
inherit! :search_paths
end
target 'Other Concrete' do
end
end
end
validator = Installer::PodfileValidator.new(podfile)
validator.validate
validator.should.be.valid
validator.errors.should.be.empty
end
end
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment