Commit 17d5bc89 authored by Marius Rackwitz's avatar Marius Rackwitz

[Spec] Test frameworks for AggregateXCConfig

parent e4724166
...@@ -118,15 +118,32 @@ def fixture_file_accessor(name, platform = :ios) ...@@ -118,15 +118,32 @@ def fixture_file_accessor(name, platform = :ios)
Pod::Sandbox::FileAccessor.new(path_list, spec.consumer(platform)) Pod::Sandbox::FileAccessor.new(path_list, spec.consumer(platform))
end end
def fixture_pod_target(name, platform = :ios, target_definition = nil) def fixture_target_definition(podfile = nil, &block)
spec = fixture_spec(name) podfile ||= Pod::Podfile.new(&block)
target_definition ||= Pod::Podfile::TargetDefinition.new('Pods', nil) Pod::Podfile::TargetDefinition.new('Pods', podfile)
end
def fixture_pod_target(spec_or_name, platform = :ios, target_definition = nil)
spec = spec_or_name.is_a?(Pod::Specification) ? spec_or_name : fixture_spec(spec_or_name)
target_definition ||= fixture_target_definition
target_definition.store_pod(spec.name)
Pod::PodTarget.new([spec], target_definition, config.sandbox).tap do |pod_target| Pod::PodTarget.new([spec], target_definition, config.sandbox).tap do |pod_target|
pod_target.stubs(:platform).returns(platform) pod_target.stubs(:platform).returns(platform)
pod_target.file_accessors << fixture_file_accessor(name, platform) pod_target.file_accessors << fixture_file_accessor(spec.defined_in_file, platform)
consumer = spec.consumer(platform)
pod_target.spec_consumers << consumer
end end
end end
def fixture_aggregate_target(pod_targets = [], platform = :ios, target_definition = nil)
target_definition ||= pod_targets.map(&:target_definition).first || fixture_target_definition
target = Pod::AggregateTarget.new(target_definition, config.sandbox)
target.client_root = config.sandbox.root.dirname
target.stubs(:platform).returns(platform)
target.pod_targets = pod_targets
target
end
#-----------------------------------------------------------------------------# #-----------------------------------------------------------------------------#
SpecHelper::Fixture.fixture('banana-lib') # ensure it exists SpecHelper::Fixture.fixture('banana-lib') # ensure it exists
......
...@@ -5,33 +5,30 @@ module Pod ...@@ -5,33 +5,30 @@ module Pod
module XCConfig module XCConfig
describe AggregateXCConfig do describe AggregateXCConfig do
def spec
fixture_spec('banana-lib/BananaLib.podspec')
end
before do before do
@spec = fixture_spec('banana-lib/BananaLib.podspec') @spec = spec
@consumer = @spec.consumer(:ios) @pod_target = fixture_pod_target(@spec)
target_definition = Podfile::TargetDefinition.new('Pods', nil) @consumer = @pod_target.spec_consumers.last
target_definition.store_pod('BananaLib') @target = fixture_aggregate_target([@pod_target])
target_definition.whitelist_pod_for_configuration('BananaLib', 'Release') @target.target_definition.should == @pod_target.target_definition
@target = AggregateTarget.new(target_definition, config.sandbox) @target.target_definition.whitelist_pod_for_configuration(@spec.name, 'Release')
@target.client_root = config.sandbox.root.dirname @podfile = @target.target_definition.podfile
@target.stubs(:platform).returns(:ios)
@pod_target = PodTarget.new([@spec], target_definition, config.sandbox)
@pod_target.stubs(:platform).returns(:ios)
@pod_target.stubs(:spec_consumers).returns([@consumer])
file_accessor = fixture_file_accessor('banana-lib/BananaLib.podspec')
@pod_target.stubs(:file_accessors).returns([file_accessor])
@target.pod_targets = [@pod_target]
@generator = AggregateXCConfig.new(@target, 'Release') @generator = AggregateXCConfig.new(@target, 'Release')
end end
shared 'AggregateXCConfig' do
it 'returns the path of the pods root relative to the user project' do it 'returns the path of the pods root relative to the user project' do
@generator.target.relative_pods_root.should == '${SRCROOT}/Pods' @generator.target.relative_pods_root.should == '${SRCROOT}/Pods'
end end
#-----------------------------------------------------------------------# #--------------------------------------------------------------------#
before do before do
@podfile = Podfile.new
@target.target_definition.stubs(:podfile).returns(@podfile)
@xcconfig = @generator.generate @xcconfig = @generator.generate
end end
...@@ -39,7 +36,7 @@ module Pod ...@@ -39,7 +36,7 @@ module Pod
@xcconfig.class.should == Xcodeproj::Config @xcconfig.class.should == Xcodeproj::Config
end end
it 'configures the project to load all members that implement Objective-c classes or categories from the static library' do it 'configures the project to load all members that implement Objective-c classes or categories' do
@xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-ObjC' @xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-ObjC'
end end
...@@ -59,16 +56,6 @@ module Pod ...@@ -59,16 +56,6 @@ module Pod
@xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}/Pods' @xcconfig.to_hash['PODS_ROOT'].should == '${SRCROOT}/Pods'
end end
it 'adds the sandbox public headers search paths to the xcconfig, with quotes, as header search paths' do
expected = "\"#{config.sandbox.public_headers.search_paths(:ios).join('" "')}\""
@xcconfig.to_hash['HEADER_SEARCH_PATHS'].should == expected
end
it 'adds the sandbox public headers search paths to the xcconfig, with quotes, as system headers' do
expected = "$(inherited) -isystem \"#{config.sandbox.public_headers.search_paths(:ios).join('" -isystem "')}\""
@xcconfig.to_hash['OTHER_CFLAGS'].should == expected
end
it 'adds the COCOAPODS macro definition' do it 'adds the COCOAPODS macro definition' do
@xcconfig.to_hash['GCC_PREPROCESSOR_DEFINITIONS'].should.include 'COCOAPODS=1' @xcconfig.to_hash['GCC_PREPROCESSOR_DEFINITIONS'].should.include 'COCOAPODS=1'
end end
...@@ -77,20 +64,12 @@ module Pod ...@@ -77,20 +64,12 @@ module Pod
@xcconfig.to_hash['GCC_PREPROCESSOR_DEFINITIONS'].should.include '$(inherited)' @xcconfig.to_hash['GCC_PREPROCESSOR_DEFINITIONS'].should.include '$(inherited)'
end end
it 'links the pod targets with the aggregate integration library target' do
@xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-l"Pods-BananaLib"'
end
it 'does not links the pod targets with the aggregate integration library target for non-whitelisted configuration' do
@generator = AggregateXCConfig.new(@target, 'Debug')
@xcconfig = @generator.generate
@xcconfig.to_hash['OTHER_LDFLAGS'].should.not.include '-l"Pods-BananaLib"'
end
it 'should configure OTHER_LIBTOOLFLAGS flags to include OTHER_LDFLAGS' do it 'should configure OTHER_LIBTOOLFLAGS flags to include OTHER_LDFLAGS' do
@xcconfig.to_hash['OTHER_LIBTOOLFLAGS'].should == '$(OTHER_LDFLAGS)' @xcconfig.to_hash['OTHER_LIBTOOLFLAGS'].should == '$(OTHER_LDFLAGS)'
end end
end
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
describe "if a pod target does not contain source files" do describe "if a pod target does not contain source files" do
...@@ -116,6 +95,67 @@ module Pod ...@@ -116,6 +95,67 @@ module Pod
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
describe 'with library' do
def spec
fixture_spec('banana-lib/BananaLib.podspec')
end
behaves_like 'AggregateXCConfig'
it 'adds the sandbox public headers search paths to the xcconfig, with quotes, as header search paths' do
expected = "\"#{config.sandbox.public_headers.search_paths(:ios).join('" "')}\""
@xcconfig.to_hash['HEADER_SEARCH_PATHS'].should == expected
end
it 'adds the sandbox public headers search paths to the xcconfig, with quotes, as system headers' do
expected = "$(inherited) -isystem \"#{config.sandbox.public_headers.search_paths(:ios).join('" -isystem "')}\""
@xcconfig.to_hash['OTHER_CFLAGS'].should == expected
end
it 'links the pod targets with the aggregate target' do
@xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-l"Pods-BananaLib"'
end
it 'does not links the pod targets with the aggregate target for non-whitelisted configuration' do
@generator = AggregateXCConfig.new(@target, 'Debug')
@xcconfig = @generator.generate
@xcconfig.to_hash['OTHER_LDFLAGS'].should.not.include '-l"Pods-BananaLib"'
end
end
describe 'with framework' do
def spec
fixture_spec('orange-framework/OrangeFramework.podspec')
end
behaves_like 'AggregateXCConfig'
it 'sets the PODS_FRAMEWORK_BUILD_PATH build variable' do
@xcconfig.to_hash['PODS_FRAMEWORK_BUILD_PATH'].should == '$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods'
end
it 'adds the framework build path to the xcconfig, with quotes, as framework search paths' do
@xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should == "\"$PODS_FRAMEWORK_BUILD_PATH\""
end
it 'adds the framework header paths to the xcconfig, with quotes, as local headers' do
expected = "$(inherited) -iquote \"$PODS_FRAMEWORK_BUILD_PATH/OrangeFramework.framework/Headers\""
@xcconfig.to_hash['OTHER_CFLAGS'].should == expected
end
it 'links the pod targets with the aggregate target' do
@xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-framework "OrangeFramework"'
end
it 'adds the COCOAPODS macro definition' do
@xcconfig.to_hash['OTHER_SWIFT_FLAGS'].should.include '-D COCOAPODS'
end
end
#-----------------------------------------------------------------------#
describe "serializing and deserializing" do
before do before do
@path = temporary_directory + 'sample.xcconfig' @path = temporary_directory + 'sample.xcconfig'
@generator.save_as(@path) @generator.save_as(@path)
...@@ -127,6 +167,8 @@ module Pod ...@@ -127,6 +167,8 @@ module Pod
end end
end end
end
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