Commit 512372a3 authored by Austin Emmons's avatar Austin Emmons

[Validator] Updates validation for dot_swift_version file to prevent failure…

[Validator] Updates validation for dot_swift_version file to prevent failure message for non-swift pods.

Responding to PR comments

Fixes incorrect test_swiftpod method call in validator_spec
parent 4117aea1
...@@ -16,6 +16,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -16,6 +16,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Dimitris Koutsogiorgas](https://github.com/dnkoutso) [Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#1698](https://github.com/CocoaPods/CocoaPods/issues/1698) [#1698](https://github.com/CocoaPods/CocoaPods/issues/1698)
* Prevents need for .swift-version file in Objective-C pods
[Austin Emmons](https://github.com/atreat)
[#6742](https://github.com/CocoaPods/CocoaPods/issues/6742)
##### Bug Fixes ##### Bug Fixes
* Fix pod install error from 1.2.1 when working with static lib-only projects. * Fix pod install error from 1.2.1 when working with static lib-only projects.
......
...@@ -146,16 +146,9 @@ module Pod ...@@ -146,16 +146,9 @@ module Pod
reasons << 'all results apply only to public specs, but you can use ' \ reasons << 'all results apply only to public specs, but you can use ' \
'`--private` to ignore them if linting the specification for a private pod' '`--private` to ignore them if linting the specification for a private pod'
end end
if dot_swift_version.nil?
reasons.to_sentence + ".\n[!] 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`'
else
reasons.to_sentence reasons.to_sentence
end end
end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
...@@ -308,6 +301,7 @@ module Pod ...@@ -308,6 +301,7 @@ module Pod
download_pod download_pod
check_file_patterns check_file_patterns
install_pod install_pod
validate_dot_swift_version
add_app_project_import add_app_project_import
validate_vendored_dynamic_frameworks validate_vendored_dynamic_frameworks
build_pod build_pod
...@@ -382,6 +376,17 @@ module Pod ...@@ -382,6 +376,17 @@ module Pod
validate_url(spec.documentation_url) if spec.documentation_url validate_url(spec.documentation_url) if spec.documentation_url
end end
def validate_dot_swift_version
if !used_swift_version.nil? && dot_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 ' \
'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
def setup_validation_environment def setup_validation_environment
validation_dir.rmtree if validation_dir.exist? validation_dir.rmtree if validation_dir.exist?
validation_dir.mkpath validation_dir.mkpath
......
...@@ -870,8 +870,14 @@ module Pod ...@@ -870,8 +870,14 @@ module Pod
validator validator
end end
it 'fails on deployment target < iOS 8 for Swift Pods' do def test_swiftpod_with_dot_swift_version(version = '3.1.0')
validator = test_swiftpod validator = test_swiftpod
validator.stubs(:dot_swift_version).returns(version)
validator
end
it 'fails on deployment target < iOS 8 for Swift Pods' do
validator = test_swiftpod_with_dot_swift_version
validator.validate validator.validate
validator.results.map(&:to_s).first.should.match /dynamic frameworks.*iOS > 8/ validator.results.map(&:to_s).first.should.match /dynamic frameworks.*iOS > 8/
...@@ -881,7 +887,7 @@ module Pod ...@@ -881,7 +887,7 @@ module Pod
it 'succeeds on deployment target < iOS 8 for Swift Pods using XCTest' do it 'succeeds on deployment target < iOS 8 for Swift Pods using XCTest' do
Specification::Consumer.any_instance.stubs(:frameworks).returns(%w(XCTest)) Specification::Consumer.any_instance.stubs(:frameworks).returns(%w(XCTest))
validator = test_swiftpod validator = test_swiftpod_with_dot_swift_version
validator.validate validator.validate
validator.results.count.should == 0 validator.results.count.should == 0
end end
...@@ -889,27 +895,36 @@ module Pod ...@@ -889,27 +895,36 @@ module Pod
it 'succeeds on deployment targets >= iOS 8 for Swift Pods' do it 'succeeds on deployment targets >= iOS 8 for Swift Pods' do
Specification.any_instance.stubs(:deployment_target).returns('9.0') Specification.any_instance.stubs(:deployment_target).returns('9.0')
validator = test_swiftpod validator = test_swiftpod_with_dot_swift_version
validator.validate validator.validate
validator.results.count.should == 0 validator.results.count.should == 0
end end
it 'tells users about the .swift-version file if the validation fails' do it 'fails without the presence of a .swift-version file for Swift Pods' do
Specification.any_instance.stubs(:deployment_target).returns('9.0') Specification.any_instance.stubs(:deployment_target).returns('9.0')
validator = test_swiftpod validator = test_swiftpod
validator.stubs(:validated?).returns(false) validator.validate
result = Validator::Result.new(:error, 'attribute', 'message') validator.results.count.should == 1
validator.stubs(:results).returns([result])
validator.failure_reason.should == "1 error.\n[!] The validator for " \ 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 ' \ 'Swift projects uses Swift 3.0 by default, if you are using a ' \
'different version of swift you can use a `.swift-version` file ' \ '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, ' \ 'to set the version for your Pod. For example to use Swift 2.3, ' \
"run: \n `echo \"2.3\" > .swift-version`" "run: \n `echo \"2.3\" > .swift-version`"
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')
validator = test_swiftpod_with_dot_swift_version
validator.validate
validator.results.count.should == 0
end
describe '#swift_version' do describe '#swift_version' do
it 'defaults to Swift 3.0' do it 'defaults to Swift 3.0' do
validator = test_swiftpod validator = test_swiftpod
......
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