Commit 64bdde9f authored by Samuel E. Giddins's avatar Samuel E. Giddins

Merge pull request #4372 from CocoaPods/seg-validate-external-source-specs

[AbstractExternalSource] Quickly validate specs
parents 76a401c0 f4c0016b
......@@ -44,10 +44,13 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[#2134](https://github.com/CocoaPods/CocoaPods/issues/2134)
* The `Info.plist` file's `CFBundleIdentifier` is now set via the
`PRODUCT_BUNDLE_IDENTIFIER` build setting, consisten with Xcode 7.
`PRODUCT_BUNDLE_IDENTIFIER` build setting, consistent with Xcode 7.
[Samuel Giddins](https://github.com/segiddins)
[#4426](https://github.com/CocoaPods/CocoaPods/issues/4426)
* Externally-sourced pods will now have their specifications quickly linted.
[Samuel Giddins](https://github.com/segiddins)
##### Bug Fixes
* Improve repo lint error message when no repo found with given name.
......
......@@ -141,17 +141,33 @@ module Pod
# @return [void]
#
def store_podspec(sandbox, spec, json = false)
if spec.is_a? Pathname
spec = Specification.from_file(spec).to_pretty_json
json = true
elsif spec.is_a?(String) && !json
spec = Specification.from_string(spec, 'spec.podspec').to_pretty_json
json = true
elsif spec.is_a?(Specification)
spec = spec.to_pretty_json
json = true
case spec
when Pathname
spec = Specification.from_file(spec)
when String
path = "#{name}.podspec"
path << '.json' if json
spec = Specification.from_string(spec, path)
end
sandbox.store_podspec(name, spec, true, json)
validate_podspec(spec)
sandbox.store_podspec(name, spec.to_pretty_json, true, true)
end
def validate_podspec(podspec)
validator = validator_for_podspec(podspec)
validator.quick = true
validator.allow_warnings = true
validator.ignore_public_only_results = true
Config.instance.with_changes(:silent => true) do
validator.validate
end
unless validator.validated?
raise Informative, "The `#{name}` pod failed to validate due to #{validator.failure_reason}:\n#{validator.results_message}"
end
end
def validator_for_podspec(podspec)
Validator.new(podspec, [])
end
end
end
......
......@@ -88,6 +88,11 @@ module Pod
# @return [void]
#
def print_results
UI.puts results_message
end
def results_message
message = ''
results.each do |result|
if result.platforms == [:ios]
platform_message = '[iOS] '
......@@ -114,9 +119,9 @@ module Pod
when :warning then type = 'WARN'
when :note then type = 'NOTE'
else raise "#{result.type}" end
UI.puts " - #{type.ljust(5)} | #{platform_message}#{subspecs_message}#{result.attribute_name}: #{result.message}"
message << " - #{type.ljust(5)} | #{platform_message}#{subspecs_message}#{result.attribute_name}: #{result.message}\n"
end
UI.puts
message << "\n"
end
def failure_reason
......
Subproject commit a4589c40aa717e3410441e88763cad64f8c73e05
Subproject commit 5eab6c43953c286f591380508e51fe9571901a98
......@@ -32,6 +32,7 @@ module Pod
describe 'Subclasses helpers' do
it 'pre-downloads the Pod and stores the relevant information in the sandbox' do
@subject.expects(:validate_podspec).with { |spec| spec.name.should == 'Reachability' }
@subject.send(:pre_download, config.sandbox)
path = config.sandbox.specifications_root + 'Reachability.podspec.json'
path.should.exist?
......@@ -43,6 +44,39 @@ module Pod
},
}
end
describe 'podspec validation' do
before do
@podspec = Pod::Specification.from_file(fixture('spec-repos') + 'master/Specs/JSONKit/1.4/JSONKit.podspec.json')
end
it 'returns a validator for the given podspec' do
validator = @subject.send(:validator_for_podspec, @podspec)
validator.spec.should == @podspec
end
before do
@validator = mock('Validator')
@validator.expects(:quick=).with(true)
@validator.expects(:allow_warnings=).with(true)
@validator.expects(:ignore_public_only_results=).with(true)
@validator.expects(:validate)
@subject.stubs(:validator_for_podspec).returns(@validator)
end
it 'validates with the correct settings' do
@validator.expects(:validated?).returns(true)
@subject.send(:validate_podspec, @podspec)
end
it 'raises when validation fails' do
@validator.expects(:validated?).returns(false)
@validator.stubs(:results_message).returns('results_message')
@validator.stubs(:failure_reason).returns('failure_reason')
should.raise(Informative) { @subject.send(:validate_podspec, @podspec) }.
message.should.include "The `Reachability` pod failed to validate due to failure_reason:\nresults_message"
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