Commit 2cd8016b authored by Samuel Giddins's avatar Samuel Giddins

[TargetInspector] List all native targets when user target isn't found

parent 0bb4eeac
require 'active_support/core_ext/array/conversions'
module Pod module Pod
class Installer class Installer
class Analyzer class Analyzer
...@@ -103,9 +105,11 @@ module Pod ...@@ -103,9 +105,11 @@ module Pod
def compute_targets(user_project) def compute_targets(user_project)
native_targets = user_project.native_targets native_targets = user_project.native_targets
target = native_targets.find { |t| t.name == target_definition.name.to_s } target = native_targets.find { |t| t.name == target_definition.name.to_s }
targets = [target].compact unless target
raise Informative, "Unable to find a target named `#{target_definition.name}`" if targets.empty? found = native_targets.map { |t| "`#{t.name}`" }.to_sentence
targets raise Informative, "Unable to find a target named `#{target_definition.name}`, did find #{found}."
end
[target]
end end
# @param [Array<PBXNativeTarget] the user's targets of the project of # @param [Array<PBXNativeTarget] the user's targets of the project of
......
...@@ -77,6 +77,18 @@ module Pod ...@@ -77,6 +77,18 @@ module Pod
e.message.should.match /Unable to find a target named `UserTarget`/ e.message.should.match /Unable to find a target named `UserTarget`/
end end
it 'suggests project native target names if the target cannot be found' do
target_definition = Podfile::TargetDefinition.new('UserTarget', nil)
user_project = Xcodeproj::Project.new('path')
user_project.new_target(:application, 'FirstTarget', :ios)
user_project.new_target(:application, 'SecondTarget', :ios)
user_project.new_target(:application, 'ThirdTarget', :ios)
target_inspector = TargetInspector.new(target_definition, config.installation_root)
e = lambda { target_inspector.send(:compute_targets, user_project) }.should.raise Informative
e.message.should.include 'did find `FirstTarget`, `SecondTarget`, and `ThirdTarget`.'
end
it 'returns the target with the same name of the target definition' do it 'returns the target with the same name of the target definition' do
target_definition = Podfile::TargetDefinition.new('UserTarget', nil) target_definition = Podfile::TargetDefinition.new('UserTarget', nil)
user_project = Xcodeproj::Project.new('path') user_project = Xcodeproj::Project.new('path')
......
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