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

[Init] Clean up target partitioning

parent 91eaa5f7
......@@ -63,17 +63,13 @@ module Pod
PLATFORM
# Split out the targets into app and test targets
all_app_targets = project.native_targets.reject { |t| t.name =~ /tests?/i }
all_tests_targets = project.native_targets.select { |t| t.name =~ /tests?/i }
test_targets, app_targets = project.native_targets.partition { |t| t.name =~ /test/i }
# Create an array of [app, (optional)test] target pairs
app_test_pairs = all_app_targets.map do |target|
test = all_tests_targets.select { |t| t.name.start_with? target.name }
[target, *test].compact
end
app_test_pairs.each do |target_pair|
podfile << target_module(target_pair)
app_targets.each do |app_target|
test_targets_for_app = test_targets.select do |target|
target.name.downcase.start_with?(app_target.name.downcase)
end
podfile << target_module(app_target, test_targets_for_app)
end
podfile
......@@ -85,12 +81,11 @@ module Pod
#
# @return [String] the text for the target module
#
def target_module(targets)
app = targets.first
def target_module(app, tests)
target_module = "\ntarget '#{app.name.gsub(/'/, "\\\\\'")}' do\n"
target_module << template_contents(config.default_podfile_path, " ", "Pods for #{app.name}\n")
targets[1..-1].each do |test|
tests.each do |test|
target_module << "\n target '#{test.name.gsub(/'/, "\\\\\'")}' do\n"
target_module << " inherit! :search_paths\n"
target_module << template_contents(config.default_test_podfile_path, " ", "Pods for testing")
......
......@@ -96,30 +96,29 @@ module Pod
run_command('init')
podfile_text = File.read(temporary_directory + "Podfile")
podfile_exact = <<-PODFILE.strip_heredoc
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# Uncomment this line if you're using Swift
# use_frameworks!
target 'App' do
# Pods for App
target 'AppTests' do
inherit! :search_paths
# Pods for testing
end
expected_podfile = <<-RUBY.strip_heredoc
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# Uncomment this line if you're using Swift
# use_frameworks!
target 'AppFeatureTests' do
inherit! :search_paths
# Pods for testing
end
target 'App' do
# Pods for App
target 'AppTests' do
inherit! :search_paths
# Pods for testing
end
end
PODFILE
target 'AppFeatureTests' do
inherit! :search_paths
# Pods for testing
end
end
RUBY
podfile_text.should == podfile_exact
File.read('Podfile').should == expected_podfile
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