Commit b6152cc8 authored by Samuel E. Giddins's avatar Samuel E. Giddins

Merge pull request #5030 from CocoaPods/seg-validate-no-duplicate-targets

Validate no duplicate targets in Podfile
parents 109d9702 5008e0d0
...@@ -41,6 +41,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -41,6 +41,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Marius Rackwitz](https://github.com/mrackwitz) [Marius Rackwitz](https://github.com/mrackwitz)
[#5022](https://github.com/CocoaPods/CocoaPods/issues/5022) [#5022](https://github.com/CocoaPods/CocoaPods/issues/5022)
* Validate that a Podfile does not declare the same target twice.
[Samuel Giddins](https://github.com/segiddins)
[#5029](https://github.com/CocoaPods/CocoaPods/issues/5029)
## 1.0.0.beta.5 (2016-03-08) ## 1.0.0.beta.5 (2016-03-08)
......
...@@ -34,6 +34,7 @@ module Pod ...@@ -34,6 +34,7 @@ module Pod
validate_pod_directives validate_pod_directives
validate_no_abstract_only_pods! validate_no_abstract_only_pods!
validate_dependencies_are_present! validate_dependencies_are_present!
validate_no_duplicate_targets!
@validated = true @validated = true
end end
...@@ -122,6 +123,16 @@ module Pod ...@@ -122,6 +123,16 @@ module Pod
add_error "The dependency `#{dep}` is not used in any concrete target." add_error "The dependency `#{dep}` is not used in any concrete target."
end end
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 end
end end
...@@ -182,5 +182,54 @@ module Pod ...@@ -182,5 +182,54 @@ module Pod
validator.errors.should.be.empty validator.errors.should.be.empty
end end
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
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