Commit 61afb0d9 authored by Danielle Tomlinson's avatar Danielle Tomlinson Committed by GitHub

Merge pull request #6971 from CocoaPods/dani_validation

Fix validation when using --swift-version
parents 191eff09 2dd3f607
......@@ -26,6 +26,11 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#6948](https://github.com/CocoaPods/CocoaPods/pull/6948)
* Fix validation warnings when using --swift-version
[Danielle Tomlinson](https://github.com/dantoml)
[#6971](https://github.com/CocoaPods/CocoaPods/issue/6971)
## 1.3.1 (2017-08-02)
##### Enhancements
......
......@@ -14,6 +14,10 @@ module Pod
class Validator
include Config::Mixin
# The default version of Swift to use when linting pods
#
DEFAULT_SWIFT_VERSION = '3.0'.freeze
# @return [Specification::Linter] the linter instance from CocoaPods
# Core.
#
......@@ -252,7 +256,12 @@ module Pod
# @return [String] the SWIFT_VERSION to use for validation.
#
def swift_version
@swift_version ||= dot_swift_version || '3.0'
return @swift_version if defined?(@swift_version)
if version = dot_swift_version
@swift_version = version
else
DEFAULT_SWIFT_VERSION
end
end
# Set the SWIFT_VERSION that should be used to validate the pod.
......@@ -386,7 +395,7 @@ module Pod
end
def validate_dot_swift_version
if !used_swift_version.nil? && dot_swift_version.nil?
if !used_swift_version.nil? && @swift_version.nil?
warning(:swift_version,
'The validator for Swift projects uses ' \
'Swift 3.0 by default, if you are using a different version of ' \
......
......@@ -931,28 +931,41 @@ module Pod
validator.results.count.should == 0
end
it 'fails without the presence of a .swift-version file for Swift Pods' do
Specification.any_instance.stubs(:deployment_target).returns('9.0')
describe 'with a user provided swift-version' do
it 'succeeds with a --swift-version provided value' do
Specification.any_instance.stubs(:deployment_target).returns('9.0')
validator = test_swiftpod
validator.validate
validator.results.count.should == 1
result = validator.results.first
result.type.should == :warning
result.message.should == 'The validator for ' \
'Swift projects uses Swift 3.0 by default, if you are using a ' \
'different version of swift you can use a `.swift-version` file ' \
'to set the version for your Pod. For example to use Swift 2.3, ' \
"run: \n `echo \"2.3\" > .swift-version`"
validator = test_swiftpod
validator.swift_version = '3.1.0'
validator.validate
validator.results.count.should == 0
end
it 'succeeds with a .swift-version file' do
Specification.any_instance.stubs(:deployment_target).returns('9.0')
validator = test_swiftpod_with_dot_swift_version
validator.validate
validator.results.count.should == 0
end
end
it 'succeeds with the presence of a .swift-version file for Swift Pods' do
Specification.any_instance.stubs(:deployment_target).returns('9.0')
describe 'wihout a user provided swift version' do
it 'warns for Swift Pods' do
Specification.any_instance.stubs(:deployment_target).returns('9.0')
validator = test_swiftpod_with_dot_swift_version
validator.validate
validator.results.count.should == 0
validator = test_swiftpod
validator.validate
validator.results.count.should == 1
result = validator.results.first
result.type.should == :warning
result.message.should == 'The validator for ' \
'Swift projects uses Swift 3.0 by default, if you are using a ' \
'different version of swift you can use a `.swift-version` file ' \
'to set the version for your Pod. For example to use Swift 2.3, ' \
"run: \n `echo \"2.3\" > .swift-version`"
end
end
describe '#swift_version' do
......
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