Commit 5255b902 authored by Samuel Giddins's avatar Samuel Giddins

[PodfileValidator] Validate there are no duplicate targets in the Podfile

parent 109d9702
......@@ -34,6 +34,7 @@ module Pod
validate_pod_directives
validate_no_abstract_only_pods!
validate_dependencies_are_present!
validate_no_duplicate_targets!
@validated = true
end
......@@ -122,6 +123,16 @@ module Pod
add_error "The dependency `#{dep}` is not used in any concrete target."
end
end
def validate_no_duplicate_targets!
podfile.target_definition_list.group_by { |td| [td.name, td.user_project_path] }.
each do |(name, project), definitions|
next unless definitions.size > 1
error = "The target `#{name}` is declared twice"
error << " for the project `#{project}`" if project
add_error(error << '.')
end
end
end
end
end
......@@ -182,5 +182,54 @@ module Pod
validator.errors.should.be.empty
end
end
describe 'duplicated targets' do
it 'errors when the same target is declared twice' do
podfile = Pod::Podfile.new do
pod 'Alamofire'
target 'Target'
target 'Target'
end
validator = Installer::PodfileValidator.new(podfile)
validator.validate
validator.should.not.be.valid
validator.errors.should == ['The target `Target` is declared twice.']
end
it 'errors when the same target is declared twice when using a custom xcodeproj' do
podfile = Pod::Podfile.new do
pod 'Alamofire'
target 'Target' do
xcodeproj 'Project.xcodeproj'
end
target 'Target' do
xcodeproj 'Project.xcodeproj'
end
end
validator = Installer::PodfileValidator.new(podfile)
validator.validate
validator.should.not.be.valid
validator.errors.should == ['The target `Target` is declared twice for the project `Project.xcodeproj`.']
end
it 'does not error when the same target is declared twice for different projects' do
podfile = Pod::Podfile.new do
pod 'Alamofire'
target 'Target' do
xcodeproj 'Project.xcodeproj'
end
target 'Target' do
xcodeproj 'Project 1.xcodeproj'
end
target 'Target'
end
validator = Installer::PodfileValidator.new(podfile)
validator.validate
validator.should.be.valid
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