Commit 0c5c43c1 authored by Fabio Pelosin's avatar Fabio Pelosin

Speficiation#activate_for_platform and collateral improvements.

parent 8b505899
......@@ -62,26 +62,25 @@ module Pod
def lint
puts
invalid_count = lint_podspecs
count = specs_to_lint.count
if invalid_count == 0
puts lint_passed_message unless config.silent?
lint_passed_message = count == 1 ? "#{podspecs_to_lint.first.basename} passed validation" : "All the #{count} specs passed validation"
puts lint_passed_message.green << "\n\n" unless config.silent?
else
raise Informative, lint_failed_message(invalid_count)
raise Informative, count == 1 ? "The spec did not pass validation" : "#{invalid_count} out of #{count} specs failed validation"
end
end
private
def lint_podspecs
specs_count, invalid_count = 0, 0
podspecs_to_lint.each do |podspec_file|
root_spec = Specification.from_file(podspec_file)
specs = root_spec.recursive_subspecs.any? ? root_spec.recursive_subspecs : [root_spec]
specs.each do |spec|
invalid_count = 0
specs_to_lint.each do |spec|
# Show immediatly which pod is being processed.
print " -> #{spec}\r" unless config.silent? || is_repo?
$stdout.flush
linter = Linter.new(spec, podspec_file)
linter = Linter.new(spec)
linter.lenient = @only_errors
linter.quick = @quick || is_repo?
invalid_count += 1 unless linter.lint
......@@ -94,9 +93,7 @@ module Pod
puts unless config.silent? || should_skip?(linter)
end
specs_count += specs.count
end
puts "Analyzed #{specs_count} specs in #{podspecs_to_lint.count} podspecs files.\n\n" if is_repo? && !config.silent?
puts "Analyzed #{specs_to_lint.count} specs in #{podspecs_to_lint.count} podspecs files.\n\n" if is_repo? && !config.silent?
invalid_count
end
......@@ -116,55 +113,35 @@ module Pod
def print_messages(spec, type, messages)
return if config.silent?
if spec.platform.name
messages = clean_platfrom_messages(messages)
else
messages = clean_duplicate_platfrom_messages(messages)
end
messages.each {|msg| puts " - #{type.ljust(5)} | #{msg}"}
end
def clean_platfrom_messages(messages)
messages.map { |l| l.gsub(/ios: /,'').gsub(/osx: /,'') }
end
def clean_duplicate_platfrom_messages(messages)
duplicate_candiates = messages.select {|l| l.include?("ios: ")}
duplicated = duplicate_candiates.select {|l| messages.include?(l.gsub(/ios: /,'osx: ')) }
duplicated.uniq.each do |l|
clean = l.gsub(/ios: /,'')
messages.insert(messages.index(l), clean)
messages.delete(l)
messages.delete('osx: ' + clean)
end
messages
end
def podspecs_to_lint
@podspecs_to_lint ||= begin
if (is_repo?)
files = (config.repos_dir + @repo_or_podspec).glob('**/*.podspec')
elsif @repo_or_podspec
files = [Pathname.new(@repo_or_podspec)]
raise Informative, "[!] Unable to find a spec named #{@repo_or_podspec}".red << "\n\n" unless files[0].exist? && @repo_or_podspec.include?('.podspec')
raise Informative, "Unable to find a spec named #{@repo_or_podspec}" unless files[0].exist? && @repo_or_podspec.include?('.podspec')
else
files = Pathname.pwd.glob('*.podspec')
raise Informative, "[!] No specs found in the current directory".red << "\n\n" if files.empty?
raise Informative, "No specs found in the current directory" if files.empty?
end
files
end
end
def is_repo?
@is_repo ||= @repo_or_podspec && (config.repos_dir + @repo_or_podspec).exist? && !@repo_or_podspec.include?('/')
def specs_to_lint
@specs_to_lint ||= begin
podspecs_to_lint.map do |podspec|
root_spec = Specification.from_file(podspec)
root_spec.recursive_subspecs.any? ? root_spec.recursive_subspecs : root_spec
end.flatten
end
def lint_passed_message
( podspecs_to_lint.count == 1 ? "#{podspecs_to_lint.first.basename} passed validation" : "All the specs passed validation" ).green << "\n\n"
end
def lint_failed_message(count)
( podspecs_to_lint.count == 1 ? "[!] The spec did not pass validation" : "[!] #{count} specs failed validation" ).red << "\n\n"
def is_repo?
@is_repo ||= @repo_or_podspec && (config.repos_dir + @repo_or_podspec).exist? && !@repo_or_podspec.include?('/')
end
# Linter class
......@@ -174,10 +151,11 @@ module Pod
attr_accessor :quick, :lenient
attr_reader :spec, :file
attr_reader :errors, :warnings, :notes
def initialize(spec, podspec_file)
def initialize(spec)
@spec = spec
@file = podspec_file.realpath
@file = spec.defined_in_file.realpath
end
# Takes an array of podspec files and lints them all
......@@ -185,66 +163,71 @@ module Pod
# It returns true if the spec passed validation
#
def lint
# If the spec doesn't validate it raises and informative
# TODO: consider raising the informative in the clients of Pod::Specification#validate!
# and just report the errors here
peform_multiplatform_analysis unless quick
@platform_errors, @platform_warnings, @platform_notes = {}, {}, {}
platforms = @spec.available_platforms
platforms.each do |platform|
@platform_errors[platform], @platform_warnings[platform], @platform_notes[platform] = [], [], []
@spec.activate_platform(platform)
@platform = platform
puts "\n\n#{spec} - Analyzing on #{platform} platform.".green.reversed if config.verbose? && !@quick
# Skip validation if there are errors in the podspec as it would result in a crash
unless podspec_errors.empty?
@errors, @warnings, @notes = podspec_errors, [], ['[!] Fatal errors found skipping the rest of the validation']
return false
if !podspec_errors.empty?
@platform_errors[platform] += podspec_errors
@platform_notes[platform] << "#{platform.name} [!] Fatal errors found skipping the rest of the validation"
else
@platform_warnings[platform] += podspec_warnings + deprecation_warnings
peform_extensive_analysis unless quick
end
valid?
end
def valid?
lenient ? errors.empty? : errors.empty? && warnings.empty?
end
# Get common messages
@errors = @platform_errors.values.reduce(:&)
@warnings = @platform_warnings.values.reduce(:&)
@notes = @platform_notes.values.reduce(:&)
def errors
@errors ||= file_patterns_errors + build_errors
platforms.each do |platform|
# Mark platform specific messages
@errors += (@platform_errors[platform] - @errors).map {|m| "[#{platform}] #{m}"}
@warnings += (@platform_warnings[platform] - @warnings).map {|m| "[#{platform}] #{m}"}
@notes += (@platform_notes[platform] - @notes).map {|m| "[#{platform}] #{m}"}
end
def warnings
@warnings ||= podspec_warnings + deprecation_warnings
valid?
end
def notes
@notes ||= build_warnings
def valid?
lenient ? errors.empty? : ( errors.empty? && warnings.empty? )
end
# Performs platform specific analysis.
# It requires to download the source at each iteration
#
def peform_multiplatform_analysis
platform_names.each do |platform_name|
def peform_extensive_analysis
set_up_lint_environment
puts "\n\n#{spec} - Analyzing on #{Platform.new platform_name} platform.".green.reversed if config.verbose?
install_pod(platform_name)
install_pod
puts "Building with xcodebuild.\n".yellow if config.verbose?
xcodebuild_output.concat(xcodebuild_output_for_platfrom(platform_name))
file_patterns_errors.concat(file_patterns_errors_for_platfrom(platform_name))
# treat xcodebuild warnings as notes because the spec maintainer might not be the author of the library
xcodebuild_output.each { |msg| ( msg.include?('error') ? @platform_errors[@platform] : @platform_notes[@platform] ) << msg }
@platform_errors[@platform] += file_patterns_errors
tear_down_lint_environment
end
end
def platform_names
spec.platform.name ? [spec.platform.name] : [:ios, :osx]
end
def install_pod(platform_name)
podfile = podfile_from_spec(platform_name)
def install_pod
podfile = podfile_from_spec
config.verbose
Installer.new(podfile).install!
config.silent
end
def podfile_from_spec(platform_name)
def podfile_from_spec
name = spec.name
podspec = file.realpath.to_s
platform_sym = @platform.to_sym
podfile = Pod::Podfile.new do
platform platform_name
platform(platform_sym)
dependency name, :podspec => podspec
end
end
......@@ -276,16 +259,18 @@ module Pod
# @return [Array<String>] List of the fatal defects detected in a podspec
def podspec_errors
messages = []
messages << "The name of the spec should match the name of the file" unless names_match?
messages << "Unrecognized platfrom" unless platform_valid?
messages << "Missing name" unless spec.name
messages << "Missing version" unless spec.version
messages << "Missing summary" unless spec.summary
messages << "Missing homepage" unless spec.homepage
messages << "Missing author(s)" unless spec.authors
messages << "Missing source or part_of" unless spec.source || spec.part_of
messages << "Missing source_files" if spec.source_files.empty? && spec.subspecs.empty?
messages << "Missing source" unless spec.source
messages << "The name of the spec should match the name of the file" unless names_match?
messages << "Unrecognized platfrom (no value, :ios, :osx)" unless [nil, :ios, :osx].include?(spec.platform.name)
# attributes with multiplatform values
return messages unless platform_valid?
messages << "Missing source_files" if spec.source_files.empty? && spec.subspecs.empty? && spec.dependencies.empty?
messages += paths_starting_with_a_slash_errors
messages
end
......@@ -296,6 +281,10 @@ module Pod
file.basename.to_s == root_name + '.podspec'
end
def platform_valid?
[nil, :ios, :osx].include?(spec.platform.name)
end
def paths_starting_with_a_slash_errors
messages = []
%w[source_files resources clean_paths].each do |accessor|
......@@ -322,8 +311,8 @@ module Pod
source = @spec.source || {}
text = @file.read
messages = []
messages << "Missing license[:type]" unless license[:type]
messages << "Missing license[:file] or [:text]" unless license[:file] || license[:text]
messages << "Missing license type" unless license[:type]
messages << "Missing license file or text" unless license[:file] || license[:text]
messages << "The summary is not meaningful" if spec.summary =~ /A short description of/
messages << "The description is not meaningful" if spec.description && spec.description =~ /An optional longer description of/
messages << "The summary should end with a dot" if @spec.summary !~ /.*\./
......@@ -351,28 +340,16 @@ module Pod
deprecations
end
def build_errors
@build_errors ||= xcodebuild_output.select {|msg| msg.include?('error')}
end
def build_warnings
@build_warnings ||= xcodebuild_output - build_errors
end
def xcodebuild_output
@xcodebuild_output ||= []
end
# It creates a podfile in memory and builds a library containing
# the pod for all available platfroms with xcodebuild.
#
# It returns a array of strings
#
def xcodebuild_output_for_platfrom(platform_name)
def xcodebuild_output
return [] if `which xcodebuild`.strip.empty?
messages = []
output = Dir.chdir(config.project_pods_root) { `xcodebuild 2>&1` }
clean_output = process_xcode_build_output(output).map {|l| "#{platform_name}: #{l}"}
clean_output = process_xcode_build_output(output)
messages += clean_output
puts(output) if config.verbose?
messages
......@@ -392,35 +369,31 @@ module Pod
end
end
def file_patterns_errors
@file_patterns_errors ||= []
end
# It checks that every file pattern specified in a spec yields
# at least one file. It requires the pods to be alredy present
# in the current working directory under Pods/spec.name
#
# It returns a array of messages
#
def file_patterns_errors_for_platfrom(platform_name)
def file_patterns_errors
Dir.chdir(config.project_pods_root + spec.name ) do
messages = []
messages += check_spec_files_exists(:source_files, platform_name, '*.{h,m,mm,c,cpp}')
messages += check_spec_files_exists(:resources, platform_name)
messages += check_spec_files_exists(:source_files, '*.{h,m,mm,c,cpp}')
messages += check_spec_files_exists(:resources)
messages << "#{platform_name}: license[:file] = '#{spec.license[:file]}' -> did not match any file" if spec.license[:file] && pod_dir.glob(spec.license[:file]).empty?
messages.compact
end
end
def check_spec_files_exists(accessor, platform_name, options = {})
def check_spec_files_exists(accessor, options = {})
result = []
patterns = spec.send(accessor)[platform_name]
patterns = spec.send(accessor)
patterns.each do |original_pattern|
pattern = pod_dir + original_pattern
if pattern.directory? && options[:glob]
pattern += options[:glob]
end
result << "#{platform_name}: [#{accessor} = '#{original_pattern}'] -> did not match any file" if pattern.glob.empty?
result << "#{@platform}: [#{accessor} = '#{original_pattern}'] -> did not match any file" if pattern.glob.empty?
end
result
end
......
......@@ -63,8 +63,7 @@ module Pod
@target = @project.add_pod_target(@target_definition.label, @target_definition.platform)
pods.each do |pod|
# TODO add methods like xcconfig to LocalPod as well? (which returns the correct platform)
xcconfig.merge!(pod.specification.xcconfig[@target_definition.platform.name])
xcconfig.merge!(pod.specification.xcconfig)
pod.add_to_target(@target)
# TODO: this doesn't need to be done here, it has nothing to do with the target
......
......@@ -2,10 +2,10 @@ module Pod
class LocalPod
attr_reader :specification
attr_reader :sandbox
attr_reader :platform
def initialize(specification, sandbox, platform)
@specification, @sandbox, @platform = specification, sandbox, platform
@specification, @sandbox = specification, sandbox
@specification.activate_platform(platform)
end
def self.from_podspec(podspec, sandbox, platform)
......@@ -28,6 +28,10 @@ module Pod
specification.name
end
def platform
specification.active_platform
end
def create
root.mkpath unless exists?
end
......@@ -83,7 +87,7 @@ module Pod
def add_to_target(target)
implementation_files.each do |file|
target.add_source_file(file, nil, specification.compiler_flags[@platform.name].strip)
target.add_source_file(file, nil, specification.compiler_flags.strip)
end
end
......@@ -92,7 +96,7 @@ module Pod
end
def dependencies
specification.dependencies[@platform.name]
specification.dependencies
end
private
......@@ -116,8 +120,7 @@ module Pod
end
end
def expanded_paths(platforms_with_patterns, options = {})
patterns = platforms_with_patterns.is_a?(Hash) ? platforms_with_patterns[@platform.name] : platforms_with_patterns
def expanded_paths(patterns, options = {})
patterns.map do |pattern|
pattern = root + pattern
......
......@@ -34,7 +34,7 @@ module Pod
end
end
def support?(other)
def supports?(other)
return true if @symbolic_name.nil? || other.nil?
@symbolic_name == other.name && (deployment_target.nil? || other.deployment_target.nil? || deployment_target >= other.deployment_target)
end
......
......@@ -60,8 +60,9 @@ module Pod
spec = set.specification_by_name(dependency.name)
@loaded_specs << spec.name
@specs[spec.name] = spec
spec.activate_platform(target_definition.platform)
# And recursively load the dependencies of the spec.
find_dependency_sets(spec, (spec.dependencies[target_definition.platform.to_sym]), target_definition) if spec.dependencies[target_definition.platform.to_sym]
find_dependency_sets(spec, spec.dependencies, target_definition) if spec.dependencies
end
validate_platform!(spec || @specs[dependency.name], target_definition)
end
......@@ -69,7 +70,7 @@ module Pod
end
def validate_platform!(spec, target)
unless spec.available_platforms.any? { |platform| target.platform.support?(platform) }
unless spec.available_platforms.any? { |platform| target.platform.supports?(platform) }
raise Informative, "[!] The platform of the target `#{target.name}' (#{target.platform}) is not compatible with `#{spec}' which has a minimun requirement of #{spec.available_platforms.join(' - ')}.".red
end
end
......
......@@ -24,7 +24,7 @@ module Pod
spec.subspec_by_name(subspec_name)
end
attr_accessor :defined_in_file, :parent
attr_accessor :parent
def initialize(parent = nil, name = nil)
@parent, @name = parent, name if parent
......@@ -37,8 +37,6 @@ module Pod
@define_for_platforms = [:osx, :ios]
@clean_paths, @subspecs = [], []
@deployment_target = {}
@platform = Platform.new(nil)
initialized_multiplatform_attributes
# deprecated attributes
......@@ -48,11 +46,11 @@ module Pod
# Deprecated attributes
# TODO: remove once master repo and fixtures are updated
def part_of_dependency=(value)
puts "[!] `part_of_dependency' is deprecated in #{name}"
puts "[!] `part_of_dependency' is deprecated in #{name}".cyan
end
def part_of=(value)
puts "[!] `part_of' is deprecated in #{name}"
puts "[!] `part_of' is deprecated in #{name}".cyan
end
# Normal attributes
......@@ -107,13 +105,24 @@ module Pod
top_attr_writer attr, writer_labmda
end
# TODO: First defined
def platform
@platform || ( @parent ? @parent.platform : Platform.new(nil) )
end
def platform=(platform)
@platform = Platform.new(*platform)
end
top_attr_accessor :defined_in_file
top_attr_accessor :homepage
top_attr_accessor :source
top_attr_accessor :documentation
top_attr_accessor :requires_arc
top_attr_accessor :license, lambda { |l| ( l.kind_of? String ) ? { :type => l } : l }
top_attr_accessor :version, lambda { |v| Version.new(v) }
top_attr_accessor :platform, lambda { |p| Platform.new(*p) }
top_attr_accessor :readme_file, lambda { |file| Pathname.new(file) }
top_attr_accessor :authors, lambda { |a| parse_authors(a) }
alias_method :author=, :authors=
......@@ -167,14 +176,19 @@ module Pod
# It returns the value of the attribute for the current platform. In this way clients do not need to be aware of wich
# attributes are multiplatform
def self.platform_attr_reader(attr)
# TODO: implement
attr_reader attr
define_method(attr) do
raise Informative, "#{self.inspect}##{attr} not activated for a platform before consumption." unless active_platform
instance_variable_get("@#{attr}")[active_platform]
end
end
# It returns the value of a pod merged with upstream. The optional lambda can specify how to merge the values
def self.pltf_chained_attr_reader(attr, merge_lambda = nil)
# TODO: chain the value with the upstream
attr_reader attr
define_method(attr) do
raise Informative, "#{self.inspect}##{attr} not activated for a platform before consumption." unless active_platform
instance_variable_get("@#{attr}")[active_platform]
end
end
def self.platform_attr_writer(attr, block = nil)
......@@ -216,35 +230,27 @@ module Pod
alias_method :library=, :libraries=
def xcconfig
result = {}
@define_for_platforms.each do |platform|
if @parent
chained = @xcconfig[platform].dup.unshift @parent.xcconfig[platform]
chained = @parent.xcconfig.dup.merge! @xcconfig[active_platform]
else
chained = @xcconfig[platform].dup
chained = @xcconfig[active_platform].dup
end
chained.merge!({ 'OTHER_LDFLAGS' => '-l' << libraries[platform].join(' -l').strip }) unless libraries[platform].empty?
chained.merge!({ 'OTHER_LDFLAGS' => '-framework ' << frameworks[platform].join(' -framework ').strip }) unless frameworks[platform].empty?
result[platform] = chained
end
result
chained.merge!({ 'OTHER_LDFLAGS' => '-l' << libraries.join(' -l').strip }) unless libraries.empty?
chained.merge!({ 'OTHER_LDFLAGS' => '-framework ' << frameworks.join(' -framework ').strip }) unless frameworks.empty?
chained
end
platform_attr_writer :xcconfig, lambda {|value, current| current.tap { |c| c.merge!(value) } }
def compiler_flags
result = {}
@define_for_platforms.each do |platform|
if @parent
chained = @compiler_flags[platform].dup.unshift @parent.compiler_flags[platform]
chained = @compiler_flags[active_platform].dup.unshift @parent.compiler_flags[active_platform]
else
chained = @compiler_flags[platform].dup
chained = @compiler_flags[active_platform].dup
chained.unshift '-fobjc-arc' if @requires_arc
chained.unshift ''
end
result[platform] = chained.join(' ')
end
result
chained.join(' ')
end
platform_attr_writer :compiler_flags, lambda {|value, current| current << value }
......@@ -259,12 +265,8 @@ module Pod
end
def dependencies
result = {}
@define_for_platforms.each do |platform|
inherited_subspecs = subspecs.map {|s| Dependency.new(s.name, version) }
result[platform] = @dependencies[platform] + inherited_subspecs
end
result
raise Informative, "#{self.inspect}#dependencies not activated for a platform before consumption." unless active_platform
@dependencies[active_platform] + subspecs.map { |s| Dependency.new(s.name, version) }
end
# TODO: make top level?
......@@ -329,12 +331,17 @@ module Pod
available_platforms.any? { |p| platform.supports? p }
end
# Defines the active platform for comsumption of the specification.
def activate_for_platform(platform)
raise "[!] #{name} does not support platform".red unless supports_platform?(plaform)
@active_platform = platform
# Defines the active platform for comsumption of the specification and returns self
def activate_platform(platform)
platform = Platform.new(platform) if platform.is_a? Hash
raise "[!] #{name} does not support platform".red unless supports_platform?(platform)
top_level_parent.active_platform = platform.to_sym
self
end
# The active platform needs to be the same accross the chain
top_attr_accessor :active_platform
def local?
!source.nil? && !source[:local].nil?
end
......
......@@ -23,7 +23,8 @@ describe "Pod::Command::Spec#create" do
it "creates a new podspec stub file" do
run_command('spec', 'create', 'Bananas')
path = temporary_directory + 'Bananas.podspec'
spec = Pod::Specification.from_file(path)
spec = Pod::Specification.from_file(path).activate_platform(:ios)
spec.name.should == 'Bananas'
spec.license.should == { :type => "MIT", :file => "LICENSE" }
spec.version.should == Pod::Version.new('0.0.1')
......@@ -32,7 +33,7 @@ describe "Pod::Command::Spec#create" do
spec.authors.should == { `git config --get user.name`.strip => `git config --get user.email`.strip}
spec.source.should == { :git => 'http://EXAMPLE/Bananas.git', :tag => '0.0.1' }
spec.description.should == 'An optional longer description of Bananas.'
spec.source_files[:ios].should == ['Classes', 'Classes/**/*.{h,m}']
spec.source_files.should == ['Classes', 'Classes/**/*.{h,m}']
end
it "correctly creates a podspec from github" do
......@@ -128,13 +129,13 @@ describe "Pod::Command::Spec#lint" do
spec_file = fixture('spec-repos') + 'master/JSONKit/1.4/JSONKit.podspec'
cmd = command('spec', 'lint', '--quick', spec_file.to_s)
lambda { cmd.run }.should.raise Pod::Informative
cmd.output.should.include "Missing license[:file] or [:text]"
cmd.output.should.include "Missing license file or text"
end
it "respects the -only--errors option" do
spec_file = fixture('spec-repos') + 'master/JSONKit/1.4/JSONKit.podspec'
cmd = command('spec', 'lint', '--quick', '--only-errors', spec_file.to_s)
lambda { cmd.run }.should.not.raise
cmd.output.should.include "Missing license[:file] or [:text]"
cmd.output.should.include "Missing license file or text"
end
end
......@@ -19,7 +19,7 @@ describe "Pod::Command::Spec::Linter" do
it "fails a specifications that does not contain the minimum required attributes" do
spec, file = write_podspec('Pod::Spec.new do |s| end')
linter = Pod::Command::Spec::Linter.new(spec, file)
linter = Pod::Command::Spec::Linter.new(spec)
linter.lenient, linter.quick = true, true
linter.lint.should == false
linter.errors.join(' | ') =~ /name.*version.*summary.*homepage.*authors.*(source.*part_of).*source_files/
......@@ -27,7 +27,7 @@ describe "Pod::Command::Spec::Linter" do
it "fails specifications if the name does not match the name of the file" do
spec, file = write_podspec(stub_podspec(/s.name *= 'JSONKit'/, "s.name = 'JSONKitAAA'"))
linter = Pod::Command::Spec::Linter.new(spec, file)
linter = Pod::Command::Spec::Linter.new(spec)
linter.lenient, linter.quick = true, true
linter.lint.should == false
linter.errors.count.should == 1
......@@ -36,16 +36,16 @@ describe "Pod::Command::Spec::Linter" do
it "fails a specification if a path starts with a slash" do
spec, file = write_podspec(stub_podspec(/s.source_files = 'JSONKit\.\*'/, "s.source_files = '/JSONKit.*'"))
linter = Pod::Command::Spec::Linter.new(spec, file)
linter = Pod::Command::Spec::Linter.new(spec)
linter.lenient, linter.quick = true, true
linter.lint.should == false
linter.errors.count.should == 1
linter.errors[0].should =~ /Paths cannot start with a slash/
end
it "fails a specification if the plafrom is unrecognized" do
it "fails a specification if the platform is unrecognized" do
spec, file = write_podspec(stub_podspec(/s.name *= 'JSONKit'/, "s.name = 'JSONKit'\ns.platform = :iososx\n"))
linter = Pod::Command::Spec::Linter.new(spec, file)
linter = Pod::Command::Spec::Linter.new(spec)
linter.lenient, linter.quick = true, true
linter.lint.should == false
linter.errors.count.should == 1
......@@ -54,7 +54,7 @@ describe "Pod::Command::Spec::Linter" do
it "fails validation if the specification contains warnings" do
spec, file = write_podspec(stub_podspec)
linter = Pod::Command::Spec::Linter.new(spec, file)
linter = Pod::Command::Spec::Linter.new(spec)
linter.lenient, linter.quick = false, true
linter.lint.should == false
linter.errors.should.be.empty
......@@ -63,7 +63,7 @@ describe "Pod::Command::Spec::Linter" do
it "validates in lenient mode if there are no erros but there are warnings" do
spec, file = write_podspec(stub_podspec)
linter = Pod::Command::Spec::Linter.new(spec, file)
linter = Pod::Command::Spec::Linter.new(spec)
linter.lenient, linter.quick = true, true
linter.lint.should == true
linter.errors.should.be.empty
......@@ -72,7 +72,7 @@ describe "Pod::Command::Spec::Linter" do
it "respects quick mode" do
spec, file = write_podspec(stub_podspec)
linter = Pod::Command::Spec::Linter.new(spec, file)
linter = Pod::Command::Spec::Linter.new(spec)
linter.expects(:peform_multiplatform_analysis).never
linter.expects(:install_pod).never
linter.expects(:xcodebuild_output_for_platfrom).never
......@@ -83,7 +83,7 @@ describe "Pod::Command::Spec::Linter" do
it "produces deprecation notices" do
spec, file = write_podspec(stub_podspec(/s\.source_files = 'JSONKit\.\*'/, "s.source_files = 'JSONKit.*'\n if config.ios?\nend"))
linter = Pod::Command::Spec::Linter.new(spec, file)
linter = Pod::Command::Spec::Linter.new(spec)
linter.lenient, linter.quick = false, true
linter.lint.should == false
linter.errors.should.be.empty
......@@ -92,7 +92,7 @@ describe "Pod::Command::Spec::Linter" do
it "uses xcodebuild to generate notes and warnings" do
spec, file = write_podspec(stub_podspec)
linter = Pod::Command::Spec::Linter.new(spec, file)
linter = Pod::Command::Spec::Linter.new(spec)
linter.lenient, linter.quick = false, false
linter.lint.should == false
linter.notes.join(' | ').should.include "JSONKit/JSONKit.m:1640:27: warning: equality comparison with extraneous parentheses" unless `which xcodebuild`.strip.empty?
......@@ -100,8 +100,8 @@ describe "Pod::Command::Spec::Linter" do
it "checks for file patterns" do
spec, file = write_podspec(stub_podspec(/s\.source_files = 'JSONKit\.\*'/, "s.source_files = 'JSONKit.*'\ns.resources = 'WRONG_FOLDER'"))
linter = Pod::Command::Spec::Linter.new(spec, file)
linter.stubs(:xcodebuild_output_for_platfrom).returns([])
linter = Pod::Command::Spec::Linter.new(spec)
linter.stubs(:xcodebuild_output).returns([])
linter.lenient, linter.quick = false, false
linter.lint.should == false
linter.errors.join(' | ').should.include "[resources = 'WRONG_FOLDER'] -> did not match any file"
......
......@@ -68,34 +68,34 @@ describe "Pod::Platform with a nil value" do
end
end
describe "Pod::Platform#support?" do
describe "Pod::Platform#supports?" do
it "supports another platform is with the same operating system" do
p1 = Pod::Platform.new(:ios)
p2 = Pod::Platform.new(:ios)
p1.should.support?(p2)
p1.should.supports?(p2)
p1 = Pod::Platform.new(:osx)
p2 = Pod::Platform.new(:osx)
p1.should.support?(p2)
p1.should.supports?(p2)
end
it "supports a nil platform" do
p1 = Pod::Platform.new(:ios)
p1.should.support?(nil)
p1.should.supports?(nil)
end
it "supports a platform with a lower or equal deployment_target" do
p1 = Pod::Platform.new(:ios, '5.0')
p2 = Pod::Platform.new(:ios, '4.0')
p1.should.support?(p1)
p1.should.support?(p2)
p2.should.not.support?(p1)
p1.should.supports?(p1)
p1.should.supports?(p2)
p2.should.not.supports?(p1)
end
it "supports a platform regardless of the deployment_target if one of the two does not specify it" do
p1 = Pod::Platform.new(:ios)
p2 = Pod::Platform.new(:ios, '4.0')
p1.should.support?(p2)
p2.should.support?(p1)
p1.should.supports?(p2)
p2.should.supports?(p1)
end
end
......@@ -57,24 +57,23 @@ describe "A Pod::Specification loaded from a podspec" do
end
it "returns the pod's source files" do
@spec.source_files[:ios].should == ['Classes/*.{h,m}', 'Vendor']
@spec.source_files[:osx].should == ['Classes/*.{h,m}', 'Vendor']
@spec.activate_platform(:ios).source_files.should == ['Classes/*.{h,m}', 'Vendor']
@spec.activate_platform(:osx).source_files.should == ['Classes/*.{h,m}', 'Vendor']
end
it "returns the pod's dependencies" do
expected = Pod::Dependency.new('monkey', '~> 1.0.1', '< 1.0.9')
@spec.dependencies.should == { :ios => [expected], :osx => [expected] }
@spec.activate_platform(:ios).dependencies.should == [expected]
@spec.activate_platform(:osx).dependencies.should == [expected]
end
it "returns the pod's xcconfig settings" do
@spec.xcconfig[:ios].should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration'
}
@spec.activate_platform(:ios).xcconfig.should == { 'OTHER_LDFLAGS' => '-framework SystemConfiguration' }
end
it "has a shortcut to add frameworks to the xcconfig" do
@spec.frameworks = 'CFNetwork', 'CoreText'
@spec.xcconfig[:ios].should == {
@spec.activate_platform(:ios).xcconfig.should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration ' \
'-framework CFNetwork ' \
'-framework CoreText'
......@@ -83,7 +82,7 @@ describe "A Pod::Specification loaded from a podspec" do
it "has a shortcut to add libraries to the xcconfig" do
@spec.libraries = 'z', 'xml2'
@spec.xcconfig[:ios].should == {
@spec.activate_platform(:ios).xcconfig.should == {
'OTHER_LDFLAGS' => '-framework SystemConfiguration -lz -lxml2'
}
end
......@@ -102,9 +101,11 @@ describe "A Pod::Specification loaded from a podspec" do
it "adds compiler flags if ARC is required" do
@spec.parent.should == nil
@spec.requires_arc = true
@spec.compiler_flags.should == { :ios => " -fobjc-arc", :osx => " -fobjc-arc" }
@spec.activate_platform(:ios).compiler_flags.should == " -fobjc-arc"
@spec.activate_platform(:osx).compiler_flags.should == " -fobjc-arc"
@spec.compiler_flags = "-Wunused-value"
@spec.compiler_flags.should == { :ios => " -fobjc-arc -Wunused-value", :osx => " -fobjc-arc -Wunused-value" }
@spec.activate_platform(:ios).compiler_flags.should == " -fobjc-arc -Wunused-value"
@spec.activate_platform(:osx).compiler_flags.should == " -fobjc-arc -Wunused-value"
end
end
......@@ -231,7 +232,8 @@ describe "A Pod::Specification subspec" do
end
it "automatically forwards undefined attributes to the top level parent" do
[:version, :summary, :platform, :license, :authors, :requires_arc, :compiler_flags].each do |attr|
@spec.activate_platform(:ios)
[:version, :summary, :platform, :license, :authors, :requires_arc].each do |attr|
@spec.subspecs.first.send(attr).should == @spec.send(attr)
@spec.subspecs.first.subspecs.first.send(attr).should == @spec.send(attr)
end
......@@ -243,6 +245,16 @@ describe "A Pod::Specification subspec" do
@spec.subspec_by_name('MainSpec/FirstSubSpec').should == @spec.subspecs.first
@spec.subspec_by_name('MainSpec/FirstSubSpec/SecondSubSpec').should == @spec.subspecs.first.subspecs.first
end
xit "can be activated for a platorm"
xit "raises if not activated"
xit "returns self on activation for method chainablity"
xit "does not cache platform attributes and can activate another platform"
xit "resolves chained attributes"
xit "resolves not chained attributes"
xit "has the same active platform accross the chain attributes"
xit "raises a top level attribute is assigned to a spec with a parent"
end
describe "A Pod::Specification with :local source" do
......@@ -281,26 +293,31 @@ describe "A Pod::Specification, concerning its attributes that support different
end
it "returns the same list of source files for each platform" do
@spec.source_files.should == { :ios => %w{ file1 file2 }, :osx => %w{ file1 file2 } }
@spec.activate_platform(:ios).source_files.should == %w{ file1 file2 }
@spec.activate_platform(:osx).source_files.should == %w{ file1 file2 }
end
it "returns the same list of resources for each platform" do
@spec.resources.should == { :ios => %w{ file1 file2 }, :osx => %w{ file1 file2 } }
@spec.activate_platform(:ios).resources.should == %w{ file1 file2 }
@spec.activate_platform(:osx).resources.should == %w{ file1 file2 }
end
it "returns the same list of xcconfig build settings for each platform" do
build_settings = { 'OTHER_LDFLAGS' => '-lObjC -lz -framework QuartzCore' }
@spec.xcconfig.should == { :ios => build_settings, :osx => build_settings }
@spec.activate_platform(:ios).xcconfig.should == build_settings
@spec.activate_platform(:osx).xcconfig.should == build_settings
end
it "returns the same list of compiler flags for each platform" do
compiler_flags = ' -fobjc-arc -Wdeprecated-implementations'
@spec.compiler_flags.should == { :ios => compiler_flags, :osx => compiler_flags }
@spec.activate_platform(:ios).compiler_flags.should == compiler_flags
@spec.activate_platform(:osx).compiler_flags.should == compiler_flags
end
it "returns the same list of dependencies for each platform" do
dependencies = %w{ JSONKit SSZipArchive }.map { |name| Pod::Dependency.new(name) }
@spec.dependencies.should == { :ios => dependencies, :osx => dependencies }
@spec.activate_platform(:ios).dependencies.should == dependencies
@spec.activate_platform(:osx).dependencies.should == dependencies
end
end
......@@ -335,18 +352,18 @@ describe "A Pod::Specification, concerning its attributes that support different
end
it "returns a different list of source files for each platform" do
@spec.source_files.should == { :ios => %w{ file1 }, :osx => %w{ file1 file2 } }
@spec.activate_platform(:ios).source_files.should == %w{ file1 }
@spec.activate_platform(:osx).source_files.should == %w{ file1 file2 }
end
it "returns a different list of resources for each platform" do
@spec.resources.should == { :ios => %w{ file1 }, :osx => %w{ file1 file2 } }
@spec.activate_platform(:ios).resources.should == %w{ file1 }
@spec.activate_platform(:osx).resources.should == %w{ file1 file2 }
end
it "returns a different list of xcconfig build settings for each platform" do
@spec.xcconfig.should == {
:ios => { 'OTHER_LDFLAGS' => '-lObjC -lz -framework QuartzCore' },
:osx => { 'OTHER_LDFLAGS' => '-lObjC -all_load -lz -lxml -framework QuartzCore -framework CoreData' }
}
@spec.activate_platform(:ios).xcconfig.should == { 'OTHER_LDFLAGS' => '-lObjC -lz -framework QuartzCore' }
@spec.activate_platform(:osx).xcconfig.should == { 'OTHER_LDFLAGS' => '-lObjC -all_load -lz -lxml -framework QuartzCore -framework CoreData' }
end
it "returns the list of the supported platfroms and deployment targets" do
......@@ -356,17 +373,13 @@ describe "A Pod::Specification, concerning its attributes that support different
end
it "returns the same list of compiler flags for each platform" do
@spec.compiler_flags.should == {
:ios => ' -fobjc-arc -Wdeprecated-implementations',
:osx => ' -fobjc-arc -Wfloat-equal'
}
@spec.activate_platform(:ios).compiler_flags.should == ' -fobjc-arc -Wdeprecated-implementations'
@spec.activate_platform(:osx).compiler_flags.should == ' -fobjc-arc -Wfloat-equal'
end
it "returns the same list of dependencies for each platform" do
@spec.dependencies.should == {
:ios => [Pod::Dependency.new('JSONKit')],
:osx => [Pod::Dependency.new('SSZipArchive')]
}
@spec.activate_platform(:ios).dependencies.should == [Pod::Dependency.new('JSONKit')]
@spec.activate_platform(:osx).dependencies.should == [Pod::Dependency.new('SSZipArchive')]
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