mirror of
https://github.com/zhigang1992/CocoaPods.git
synced 2026-04-29 18:05:42 +08:00
[Linter] Improvements.
- `spec lint` can now accept multiple files passed as arguments. - the linter can work in environments with xcodebuild. - Other misc improvements.
This commit is contained in:
@@ -19,16 +19,18 @@ describe "Pod::Command::Linter" do
|
||||
it "fails a specifications that does not contain the minimum required attributes" do
|
||||
file = write_podspec('Pod::Spec.new do |s| end')
|
||||
linter = Pod::Command::Spec::Linter.new(file)
|
||||
linter.lenient, linter.quick = true, true
|
||||
linter.lint.should == false
|
||||
linter.quick = true
|
||||
linter.lint
|
||||
linter.result_type.should == :error
|
||||
linter.errors.join(' | ') =~ /name.*version.*summary.*homepage.*authors.*(source.*part_of).*source_files/
|
||||
end
|
||||
|
||||
it "fails specifications if the name does not match the name of the file" do
|
||||
file = write_podspec(stub_podspec(/s.name *= 'JSONKit'/, "s.name = 'JSONKitAAA'"))
|
||||
linter = Pod::Command::Spec::Linter.new(file)
|
||||
linter.lenient, linter.quick = true, true
|
||||
linter.lint.should == false
|
||||
linter.quick = true
|
||||
linter.lint
|
||||
linter.result_type.should == :error
|
||||
linter.errors.count.should == 1
|
||||
linter.errors[0].should =~ /The name of the spec should match the name of the file/
|
||||
end
|
||||
@@ -36,8 +38,9 @@ describe "Pod::Command::Linter" do
|
||||
it "fails a specification if a path starts with a slash" do
|
||||
file = write_podspec(stub_podspec(/s.source_files = 'JSONKit\.\*'/, "s.source_files = '/JSONKit.*'"))
|
||||
linter = Pod::Command::Spec::Linter.new(file)
|
||||
linter.lenient, linter.quick = true, true
|
||||
linter.lint.should == false
|
||||
linter.quick = true
|
||||
linter.lint
|
||||
linter.result_type.should == :error
|
||||
linter.errors.count.should == 1
|
||||
linter.errors[0].should =~ /Paths cannot start with a slash/
|
||||
end
|
||||
@@ -45,8 +48,9 @@ describe "Pod::Command::Linter" do
|
||||
it "fails a specification if the platform is unrecognized" do
|
||||
file = write_podspec(stub_podspec(/s.name *= 'JSONKit'/, "s.name = 'JSONKit'\ns.platform = :iososx\n"))
|
||||
linter = Pod::Command::Spec::Linter.new(file)
|
||||
linter.lenient, linter.quick = true, true
|
||||
linter.lint.should == false
|
||||
linter.quick = true
|
||||
linter.lint
|
||||
linter.result_type.should == :error
|
||||
linter.errors.count.should == 1
|
||||
linter.errors[0].should =~ /Unrecognized platfrom/
|
||||
end
|
||||
@@ -54,19 +58,19 @@ describe "Pod::Command::Linter" do
|
||||
it "fails validation if the specification contains warnings" do
|
||||
file = write_podspec(stub_podspec(/.*license.*/, ""))
|
||||
linter = Pod::Command::Spec::Linter.new(file)
|
||||
linter.lenient, linter.quick = false, true
|
||||
linter.lint.should == false
|
||||
linter.quick = true
|
||||
linter.lint
|
||||
linter.result_type.should == :warning
|
||||
linter.errors.should.be.empty
|
||||
linter.warnings.should.not.be.empty
|
||||
end
|
||||
|
||||
it "validates in lenient mode if there are no errors but there are warnings" do
|
||||
it "correctly report specification that only contain warnings" do
|
||||
file = write_podspec(stub_podspec(/.*license.*/, ""))
|
||||
linter = Pod::Command::Spec::Linter.new(file)
|
||||
linter.lenient, linter.quick = true, true
|
||||
linter.lint.should == true
|
||||
linter.errors.should.be.empty
|
||||
linter.warnings.should.not.be.empty
|
||||
linter.quick = true
|
||||
linter.lint
|
||||
linter.result_type.should == :warning
|
||||
end
|
||||
|
||||
it "respects quick mode" do
|
||||
@@ -76,37 +80,39 @@ describe "Pod::Command::Linter" do
|
||||
linter.expects(:install_pod).never
|
||||
linter.expects(:xcodebuild_output_for_platfrom).never
|
||||
linter.expects(:file_patterns_errors_for_platfrom).never
|
||||
linter.lenient, linter.quick = false, true
|
||||
linter.quick = true
|
||||
linter.lint
|
||||
end
|
||||
|
||||
it "produces deprecation notices" do
|
||||
file = write_podspec(stub_podspec(/s\.source_files = 'JSONKit\.\*'/, "s.source_files = 'JSONKit.*'\n if config.ios?\nend"))
|
||||
linter = Pod::Command::Spec::Linter.new(file)
|
||||
linter.lenient, linter.quick = false, true
|
||||
linter.lint.should == false
|
||||
linter.quick = true
|
||||
linter.lint
|
||||
linter.result_type.should == :error
|
||||
linter.warnings.should.be.empty
|
||||
linter.errors.join(' | ').should =~ /`config.ios\?' and `config.osx\?' are deprecated/
|
||||
end
|
||||
|
||||
it "uses xcodebuild to generate notes and warnings" do
|
||||
it "uses xcodebuild to generate notes and warnings" do
|
||||
file = write_podspec(stub_podspec)
|
||||
linter = Pod::Command::Spec::Linter.new(file)
|
||||
linter.lenient, linter.quick = false, false
|
||||
linter.lint.should == false
|
||||
linter.lint
|
||||
linter.result_type.should == :warning
|
||||
linter.notes.join(' | ').should.include "JSONKit/JSONKit.m:1640:27: warning: equality comparison with extraneous parentheses" unless `which xcodebuild`.strip.empty?
|
||||
end
|
||||
|
||||
it "checks for file patterns" do
|
||||
it "checks for file patterns" do
|
||||
file = write_podspec(stub_podspec(/s\.source_files = 'JSONKit\.\*'/, "s.source_files = 'JSONKit.*'\ns.resources = 'WRONG_FOLDER'"))
|
||||
linter = Pod::Command::Spec::Linter.new(file)
|
||||
linter.stubs(:xcodebuild_output).returns([])
|
||||
linter.lenient, linter.quick = false, false
|
||||
linter.lint.should == false
|
||||
linter.quick = false
|
||||
linter.lint
|
||||
linter.result_type.should == :error
|
||||
linter.errors.join(' | ').should.include "The resources did not match any file"
|
||||
end
|
||||
|
||||
it "uses the deployment target of the specification" do
|
||||
it "uses the deployment target of the specification" do
|
||||
file = write_podspec(stub_podspec(/s.name *= 'JSONKit'/, "s.name = 'JSONKit'; s.platform = :ios, '5.0'"))
|
||||
linter = Pod::Command::Spec::Linter.new(file)
|
||||
linter.quick = true
|
||||
@@ -114,6 +120,6 @@ describe "Pod::Command::Linter" do
|
||||
podfile = linter.podfile_from_spec
|
||||
deployment_target = podfile.target_definitions[:default].platform.deployment_target
|
||||
deployment_target.to_s.should == "5.0"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user