Commit 1222f114 authored by Samuel Giddins's avatar Samuel Giddins

[Validator] Only import if the pod target is being built

parent ea2c2170
...@@ -399,12 +399,12 @@ module Pod ...@@ -399,12 +399,12 @@ module Pod
if language == :swift if language == :swift
source_file = validation_dir.+('App/main.swift') source_file = validation_dir.+('App/main.swift')
source_file.parent.mkpath source_file.parent.mkpath
import_statement = use_frameworks ? "import #{pod_target.product_module_name}\n" : '' import_statement = use_frameworks && pod_target.should_build? ? "import #{pod_target.product_module_name}\n" : ''
source_file.open('w') { |f| f << import_statement } source_file.open('w') { |f| f << import_statement }
else else
source_file = validation_dir.+('App/main.m') source_file = validation_dir.+('App/main.m')
source_file.parent.mkpath source_file.parent.mkpath
import_statement = if use_frameworks import_statement = if use_frameworks && pod_target.should_build?
"@import #{pod_target.product_module_name};\n" "@import #{pod_target.product_module_name};\n"
else else
header_name = "#{pod_target.product_module_name}/#{pod_target.product_module_name}.h" header_name = "#{pod_target.product_module_name}/#{pod_target.product_module_name}.h"
......
...@@ -496,7 +496,7 @@ module Pod ...@@ -496,7 +496,7 @@ module Pod
end end
it 'creates a swift import' do it 'creates a swift import' do
pod_target = stub(:uses_swift? => true, :product_module_name => 'ModuleName') pod_target = stub(:uses_swift? => true, :should_build? => true, :product_module_name => 'ModuleName')
file = @validator.send(:write_app_import_source_file, pod_target) file = @validator.send(:write_app_import_source_file, pod_target)
file.basename.to_s.should == 'main.swift' file.basename.to_s.should == 'main.swift'
...@@ -506,7 +506,7 @@ module Pod ...@@ -506,7 +506,7 @@ module Pod
end end
it 'creates an objective-c import' do it 'creates an objective-c import' do
pod_target = stub(:uses_swift? => false, :product_module_name => 'ModuleName') pod_target = stub(:uses_swift? => false, :should_build? => true, :product_module_name => 'ModuleName')
file = @validator.send(:write_app_import_source_file, pod_target) file = @validator.send(:write_app_import_source_file, pod_target)
file.basename.to_s.should == 'main.m' file.basename.to_s.should == 'main.m'
...@@ -517,6 +517,14 @@ module Pod ...@@ -517,6 +517,14 @@ module Pod
int main() {} int main() {}
OBJC OBJC
end end
it 'creates no import when the pod target has no source files' do
pod_target = stub(:uses_swift? => true, :should_build? => false)
file = @validator.send(:write_app_import_source_file, pod_target)
file.basename.to_s.should == 'main.swift'
file.read.should == ''
end
end end
describe 'when linting as a static lib' do describe 'when linting as a static lib' do
...@@ -526,7 +534,7 @@ module Pod ...@@ -526,7 +534,7 @@ module Pod
end end
it 'creates an objective-c import when a plausible umbrella header is found' do it 'creates an objective-c import when a plausible umbrella header is found' do
pod_target = stub(:uses_swift? => false, :product_module_name => 'ModuleName', :sandbox => @sandbox) pod_target = stub(:uses_swift? => false, :should_build? => true, :product_module_name => 'ModuleName', :sandbox => @sandbox)
header_name = "#{pod_target.product_module_name}/#{pod_target.product_module_name}.h" header_name = "#{pod_target.product_module_name}/#{pod_target.product_module_name}.h"
umbrella = pod_target.sandbox.public_headers.root.+(header_name) umbrella = pod_target.sandbox.public_headers.root.+(header_name)
umbrella.dirname.mkpath umbrella.dirname.mkpath
...@@ -543,7 +551,7 @@ module Pod ...@@ -543,7 +551,7 @@ module Pod
end end
it 'does not create an objective-c import when no umbrella header is found' do it 'does not create an objective-c import when no umbrella header is found' do
pod_target = stub(:uses_swift? => false, :product_module_name => 'ModuleName', :sandbox => @sandbox) pod_target = stub(:uses_swift? => false, :should_build? => true, :product_module_name => 'ModuleName', :sandbox => @sandbox)
file = @validator.send(:write_app_import_source_file, pod_target) file = @validator.send(:write_app_import_source_file, pod_target)
file.basename.to_s.should == 'main.m' file.basename.to_s.should == 'main.m'
...@@ -559,7 +567,7 @@ module Pod ...@@ -559,7 +567,7 @@ module Pod
it 'adds the importing file to the app target' do it 'adds the importing file to the app target' do
@validator.stubs(:use_frameworks).returns(true) @validator.stubs(:use_frameworks).returns(true)
@validator.send(:create_app_project) @validator.send(:create_app_project)
pod_target = stub(:uses_swift? => true, :pod_name => 'JSONKit', :product_module_name => 'ModuleName') pod_target = stub(:uses_swift? => true, :should_build? => true, :pod_name => 'JSONKit', :product_module_name => 'ModuleName')
installer = stub(:pod_targets => [pod_target]) installer = stub(:pod_targets => [pod_target])
@validator.instance_variable_set(:@installer, installer) @validator.instance_variable_set(:@installer, installer)
@validator.send(:add_app_project_import) @validator.send(:add_app_project_import)
......
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