Commit 1a883aba authored by Fabio Pelosin's avatar Fabio Pelosin

Merge branch 'master' into core-extraction

* master:
  Updated master repo fixture.
  [Specs] Fix for master repo update & small performance improvements.

Conflicts:
	spec/functional/command/list_spec.rb
	spec/functional/command/push_spec.rb
	spec/functional/command/repo_spec.rb
	spec/functional/command/setup_spec.rb
	spec/spec_helper/temporary_repos.rb
	spec/unit/resolver_spec.rb
	spec/unit/source_spec.rb
parents 72534339 75f7c742
......@@ -27,6 +27,12 @@ module Pod
errors.empty? && warnings.empty? && deprecations.empty?
end
# TODO
def result_type
:note
end
# @return [Bool] whether the lint should skip the checks that requires
# the download or the build of the library.
#
......
......@@ -39,14 +39,14 @@ module Pod
class New < List
self.summary = 'Lists pods introduced in the master spec-repo since the last check'
def run
def run_a
update_if_necessary!
days = [1,2,3,5,8]
dates, groups = {}, {}
days.each {|d| dates[d] = Time.now - 60 * 60 * 24 * d}
sets = Source.all_sets
creation_dates = Pod::Specification::Set::Statistics.instance.creation_dates(sets)
creation_dates = Specification::Set::Statistics.instance.creation_dates(sets)
sets.each do |set|
set_date = creation_dates[set.name]
......
......@@ -87,7 +87,7 @@ module Pod
lint_argv = ["lint"]
lint_argv << "--only-errors" if @allow_warnings
lint_argv << "--silent" if config.silent
all_valid = true
# all_valid = true
podspec_files.each do |podspec|
Spec.parse(lint_argv + [podspec.to_s]).run
end
......
......@@ -107,7 +107,7 @@ module Pod
invalid_count = 0
podspecs.each do |podspec|
linter = Linter.new(podspec)
linter = DeepLinter.new(podspec)
linter.quick = true
linter.repo_path = dir
......@@ -178,6 +178,8 @@ module Pod
is_compatilbe(versions)
end
#--------------------------------------#
private
def versions(dir)
......
require File.expand_path('../../../spec_helper', __FILE__)
module Pod
describe Command::List do
describe "Command::List" do
extend SpecHelper::TemporaryRepos
extend SpecHelper::TemporaryDirectory
it "lists the known pods" do
out = run_command('list')
[ /ZBarSDK/,
/TouchJSON/,
/SDURLCache/,
/MagicalRecord/,
/A2DynamicDelegate/,
def command(arguments = argv)
command = Command::List.new(arguments)
end
before do
set_up_test_repo
config.repos_dir = SpecHelper.tmp_repos_path
end
it "presents the known pods" do
command.run
UI.output
[ /BananaLib/,
/JSONKit/,
/\d+ pods were found/
].each { |regex| out.should =~ regex }
].each { |regex| UI.output.should =~ regex }
end
it "lists the new pods" do
Time.stubs(:now).returns(Time.mktime(2012,2,3))
out = run_command('list', 'new')
[ 'iCarousel',
'libPusher',
'SSCheckBoxView',
'KKPasscodeLock',
'SOCKit',
'FileMD5Hash',
'cocoa-oauth',
'iRate'
].each {|s| out.should.include s }
it "returns the new pods" do
sets = Source.all_sets
jsonkit_set = sets.find { |s| s.name == 'JSONKit' }
dates = {
'BananaLib' => Time.now,
'JSONKit' => Time.parse('01/01/1970') }
Specification::Set::Statistics.any_instance.stubs(:creation_dates).returns(dates)
command(argv('new')).run
UI.output.should.include('BananaLib')
UI.output.should.not.include('JSONKit')
end
end
end
......
......@@ -10,41 +10,43 @@ module Pod
config.repos_dir = SpecHelper.tmp_repos_path
end
def master_repo
fixture('spec-repos/master')
end
it "requires a spec-repo name" do
lambda { command('push').validate! }.should.raise CLAide::Help
end
it "complains if it can't find the repo" do
repo1 = add_repo('repo1', master_repo)
Dir.chdir(fixture('banana-lib')) do
lambda { run_command('push', 'repo2') }.should.raise Informative
cmd = command('push', 'missing_repo')
cmd.expects(:validate_podspec_files).returns(true)
e = lambda { cmd.run }.should.raise Informative
e.message.should.match(/repo not found/)
end
end
it "complains if it can't find a spec" do
repo1 = add_repo('repo1', master_repo)
lambda { run_command('push', 'repo1') }.should.raise Informative
repo_make('test_repo')
e = lambda { run_command('push', 'test_repo') }.should.raise Pod::Informative
e.message.should.match(/Couldn't find any .podspec/)
end
it "it raises if the pod is not validated" do
repo1 = add_repo('repo1', master_repo)
repo2 = add_repo('repo2', repo1.dir)
git_config('repo2', 'remote.origin.url').should == (tmp_repos_path + 'repo1').to_s
Dir.chdir(fixture('banana-lib')) do
lambda { run_command('push', 'repo2', '--silent') }.should.raise Informative
# TODO: the validation should not use the pod spec command
xit "it raises if the specification doesn't validates" do
repo_make('test_repo')
Dir.chdir(temporary_directory) do
spec = "Spec.new do |s|; s.name = 'Broken'; end"
File.open('Broken.podspec', 'w') {|f| f.write(spec) }
cmd = command('push', 'test_repo')
cmd.expects(:validate_podspec_files).returns(true)
e = lambda { cmd.run }.should.raise Pod::Informative
e.message.should.match(/repo not clean/)
end
# (repo1.dir + 'BananaLib/1.0/BananaLib.podspec').read.should.include 'Added!'
end
#--------------------------------------#
before do
# prepare the repos
@upstream = add_repo('upstream', master_repo)
@local_repo = add_repo('local_repo', @upstream.dir)
git_config('local_repo', 'remote.origin.url').should == (tmp_repos_path + 'upstream').to_s
repo_make('upstream')
repo_clone('upstream', 'local_repo')
# prepare the spec
spec = (fixture('spec-repos') + 'master/JSONKit/1.4/JSONKit.podspec').read
......@@ -55,26 +57,29 @@ module Pod
end
it "refuses to push if the repo is not clean" do
File.open(@local_repo.dir + 'README', 'w') {|f| f.write('Added!') }
(@local_repo.dir + 'README').read.should.include 'Added!'
repo_make_readme_change('local_repo', 'dirty')
Dir.chdir(temporary_directory) do
cmd = command('push', 'local_repo')
cmd.expects(:validate_podspec_files).returns(true)
Dir.chdir(temporary_directory) { lambda { cmd.run }.should.raise Informative }
(@upstream.dir + 'PushTest/1.4/PushTest.podspec').should.not.exist?
e = lambda { cmd.run }.should.raise Pod::Informative
e.message.should.match(/repo not clean/)
end
(repo_path('upstream') + 'PushTest/1.4/PushTest.podspec').should.not.exist?
end
it "sucessfully pushes a spec" do
git('upstream', 'checkout master') # checkout master, to allow push in a non-bare repository
cmd = command('push', 'local_repo')
Dir.chdir(repo_path 'upstream') { `git checkout -b tmp_for_push -q` }
cmd.expects(:validate_podspec_files).returns(true)
Dir.chdir(temporary_directory) { cmd.run }
UI.output.should.include('[Add] PushTest (1.4)')
UI.output.should.include('[Fix] JSONKit (1.4)')
Pod::UI.output.should.include('[Add] PushTest (1.4)')
Pod::UI.output.should.include('[Add] JSONKit (1.4)')
# TODO check the commit messages
# Pod::UI.output.should.include('[Fix] JSONKit (1.4)')
git('upstream', 'checkout test') # checkout because test because is it the branch used in the specs.
(@upstream.dir + 'PushTest/1.4/PushTest.podspec').read.should.include('PushTest')
Dir.chdir(repo_path 'upstream') { `git checkout master -q` }
(repo_path('upstream') + 'PushTest/1.4/PushTest.podspec').read.should.include('PushTest')
end
end
end
require File.expand_path('../../../spec_helper', __FILE__)
describe "Pod::Command::Repo" do
module Pod
describe Command::Repo do
describe "In general" do
extend SpecHelper::Command
extend SpecHelper::TemporaryDirectory
extend SpecHelper::TemporaryRepos
before do
set_up_test_repo
config.repos_dir = SpecHelper.tmp_repos_path
end
describe "In general" do
extend SpecHelper::TemporaryDirectory
extend SpecHelper::TemporaryRepos
it "updates a repository" do
upstream = SpecHelper.temporary_directory + 'upstream'
FileUtils.cp_r(test_repo_path, upstream)
Dir.chdir(test_repo_path) do
`git remote add origin #{upstream}`
`git remote -v`
`git fetch -q`
`git branch --set-upstream master origin/master`
end
lambda { command('repo', 'update').run }.should.not.raise
end
it "lints a repository" do
lambda { run_command('repo', 'lint', temporary_directory.to_s) }.should.not.raise
end
it "adds a spec-repo" do
run_command('repo', 'add', 'private', fixture('spec-repos/master'))
git_config('private', 'remote.origin.url').should == fixture('spec-repos/master').to_s
run_command('repo', 'add', 'private', test_repo_path)
Dir.chdir(config.repos_dir + 'private') do
`git config --get remote.origin.url`.chomp.should == test_repo_path.to_s
end
end
it "adds a spec-repo with on a specified branch" do
repo1 = add_repo('repo1', fixture('spec-repos/master'))
Dir.chdir(repo1.dir) do
it "adds a spec-repo with a specified branch" do
repo1 = repo_make('repo1')
Dir.chdir(repo1) do
`git checkout -b my-branch >/dev/null 2>&1`
`git checkout master >/dev/null 2>&1`
end
repo2 = command( 'repo' ,'add', 'repo2', repo1.dir, 'my-branch')
repo2 = command( 'repo' ,'add', 'repo2', repo1.to_s, 'my-branch')
repo2.run
Dir.chdir(repo2.dir) { `git symbolic-ref HEAD` }.should.include? 'my-branch'
end
it "updates a spec-repo" do
repo1 = add_repo('repo1', fixture('spec-repos/master'))
repo2 = add_repo('repo2', repo1.dir)
make_change(repo1, 'repo1')
repo1 = repo_make('repo1')
repo2 = repo_clone('repo1', 'repo2')
repo_make_readme_change(repo1, 'Updated')
Dir.chdir(repo1) {`git commit -a -m "Update"`}
run_command('repo', 'update', 'repo2')
(repo2.dir + 'README').read.should.include 'Added!'
end
it "updates all the spec-repos" do
repo1 = add_repo('repo1', fixture('spec-repos/master'))
repo2 = add_repo('repo2', repo1.dir)
repo3 = add_repo('repo3', repo1.dir)
make_change(repo1, 'repo1')
run_command('repo', 'update')
(repo2.dir + 'README').read.should.include 'Added!'
(repo3.dir + 'README').read.should.include 'Added!'
end
before do
config.repos_dir = fixture('spec-repos')
end
it "lints a repo" do
cmd = command('repo', 'lint', 'master')
lambda { cmd.run }.should.raise Pod::Informative
Pod::UI.output.should.include "Missing license type"
(repo2 + 'README').read.should.include 'Updated'
end
end
describe "Concerning a repo support" do
describe "CocoaPods version" do
extend SpecHelper::Command
extend SpecHelper::TemporaryDirectory
extend SpecHelper::TemporaryRepos
before do
add_repo('repo1', fixture('spec-repos/master'))
FileUtils.rm_rf(versions_file)
versions_file.should.not.exist?
end
require 'yaml'
def versions_file
tmp_repos_path + "repo1/CocoaPods-version.yml"
before do
config.repos_dir = SpecHelper.tmp_repos_path
@repo = repo_make('repo1')
end
def write_version_file(hash)
yaml = YAML.dump(hash)
File.open(versions_file, 'w') {|f| f.write(yaml) }
@versions_file = tmp_repos_path + "repo1/CocoaPods-version.yml"
File.open(@versions_file, 'w') {|f| f.write(yaml) }
end
it "it doesn't requires CocoaPods-version.yml" do
cmd = command('repo', 'update')
lambda { cmd.check_versions(versions_file.dirname) }.should.not.raise
lambda { cmd.check_versions(@repo) }.should.not.raise
end
it "runs with a compatible repo" do
write_version_file({'min' => "0.0.1"})
cmd = command('repo', 'update')
lambda { cmd.check_versions(versions_file.dirname) }.should.not.raise
lambda { cmd.check_versions(@repo) }.should.not.raise
end
it "raises if a repo is not compatible" do
write_version_file({'min' => "999.0.0"})
cmd = command('repo', 'update')
lambda { cmd.check_versions(versions_file.dirname) }.should.raise Pod::Informative
lambda { cmd.check_versions(@repo) }.should.raise Informative
end
it "informs about a higher known CocoaPods version" do
write_version_file({'last' => "999.0.0"})
cmd = command('repo', 'update')
cmd.check_versions(versions_file.dirname)
Pod::UI.output.should.include "Cocoapods 999.0.0 is available"
cmd.check_versions(@repo)
UI.output.should.include "Cocoapods 999.0.0 is available"
end
it "has a class method that returns if a repo is supported" do
write_version_file({'min' => "999.0.0"})
Pod::Command::Repo.compatible?('repo1').should == false
Command::Repo.compatible?('repo1').should == false
write_version_file({'min' => "0.0.1"})
Pod::Command::Repo.compatible?('repo1').should == true
Command::Repo.compatible?('repo1').should == true
end
end
end
end
require File.expand_path('../../../spec_helper', __FILE__)
module Pod
describe Command::Setup do
describe Pod::Command::Setup do
extend SpecHelper::Command
extend SpecHelper::TemporaryDirectory
extend SpecHelper::TemporaryRepos
......@@ -9,50 +9,47 @@ module Pod
config.repos_dir = SpecHelper.tmp_repos_path
end
it "runs with correct parameters" do
lambda { run_command('setup') }.should.not.raise
end
it "complains for wrong parameters" do
lambda { run_command('setup', 'wrong') }.should.raise CLAide::Help
lambda { run_command('setup', '--wrong') }.should.raise CLAide::Help
end
it "returns the read only URL of the `master' spec-repo" do
cmd = Command::Setup.new(argv)
it "returns the read only URL of the `master` spec-repo" do
cmd = Pod::Command::Setup.new(argv)
cmd.url.should == 'https://github.com/CocoaPods/Specs.git'
end
it "returns the push URL of the `master' spec-repo" do
config.silent = true
cmd = Command::Setup.new(argv('--push'))
cmd = Pod::Command::Setup.new(argv('--push'))
cmd.url.should == 'git@github.com:CocoaPods/Specs.git'
end
class Command::Setup
def read_only_url; SpecHelper.fixture('spec-repos/master'); end
before do
set_up_test_repo
Pod::Command::Setup.any_instance.stubs(:read_only_url).returns(test_repo_path.to_s)
config.repos_dir = SpecHelper.temporary_directory
end
it "runs with correct parameters" do
lambda { run_command('setup') }.should.not.raise
end
it "creates the local spec-repos directory and creates a clone of the `master' repo" do
output = run_command('setup')
output.should.include "Setup completed"
output.should.not.include "push"
git_config('master', 'remote.origin.url').should == fixture('spec-repos/master').to_s
url = Dir.chdir(config.repos_dir + 'master') { `git config --get remote.origin.url`.chomp }
url.should == test_repo_path.to_s
end
it "preserves push access for the `master' repo" do
output = run_command('setup')
output.should.not.include "push"
git('master', 'remote set-url origin git@github.com:CocoaPods/Specs.git')
Dir.chdir(config.repos_dir + 'master') { `git remote set-url origin git@github.com:CocoaPods/Specs.git` }
command('setup').url.should == 'git@github.com:CocoaPods/Specs.git'
end
it "can run if needed" do
output = run_command('setup')
output.should.include "Setup completed"
UI.output = ''
Pod::UI.output = ''
command('setup').run_if_needed
UI.output.should == ''
end
Pod::UI.output.should == ''
end
end
......@@ -15,6 +15,7 @@ describe Pod::UI do
output.should.include? 'CocoaLumberjack'
output.should.include? '1.0'
output.should.include? '1.1'
output.should.include? '[master repo]'
output.should.include? 'A fast & simple, yet powerful & flexible logging framework for Mac and iOS.'
output.should.include? 'https://github.com/robbiehanson/CocoaLumberjack'
output.should.include? 'https://github.com/robbiehanson/CocoaLumberjack.git'
......
......@@ -192,15 +192,19 @@ else
result = installer.lockfile.to_hash
result['PODS'].should == [
{ "ASIHTTPRequest (1.8.1)" => ["ASIHTTPRequest/ASIWebPageRequest (= 1.8.1)",
{ "ASIHTTPRequest (1.8.1)" =>
[ "ASIHTTPRequest/ASIWebPageRequest (= 1.8.1)",
"ASIHTTPRequest/CloudFiles (= 1.8.1)",
"ASIHTTPRequest/S3 (= 1.8.1)",
"Reachability"]},
"Reachability"
]
},
{ "ASIHTTPRequest/ASIWebPageRequest (1.8.1)" => ["Reachability"] },
{ "ASIHTTPRequest/CloudFiles (1.8.1)" => ["Reachability"] },
{ "ASIHTTPRequest/S3 (1.8.1)" => ["Reachability"] },
"JSONKit (1.4)",
"Reachability (3.0.0)"]
"Reachability (3.1.0)"
]
result['DEPENDENCIES'].should == ["ASIHTTPRequest", "JSONKit (= 1.4)"]
# TODO might be nicer looking to not show the dependencies of the top level spec for each subspec (Reachability).
......@@ -300,7 +304,7 @@ else
lockfile_contents = {
'PODS' => [
'JSONKit (999.999.999)',
'Reachability (3.0.0)',
'Reachability (3.1.0)',
'SSZipArchive (0.1.1)',
],
'DEPENDENCIES' => [
......
require 'spec_helper/temporary_directory'
# Important
# Include with temporary directory
module SpecHelper
def self.tmp_repos_path
TemporaryRepos.tmp_repos_path
......@@ -9,41 +12,64 @@ module SpecHelper
extend Pod::Executable
executable :git
def tmp_repos_path
SpecHelper.temporary_directory + 'cocoapods'
# @return [Pathname] The path for the repo with the given name.
#
def repo_path(name)
tmp_repos_path + name
end
module_function :tmp_repos_path
alias_method :git_super, :git
def git(repo, command)
Dir.chdir(tmp_repos_path + repo) do
if output = git_super(command)
output.strip
# Makes a repo with the given name.
#
def repo_make(name)
path = repo_path(name)
path.mkpath
Dir.chdir(path) do
`git init`
repo_make_readme_change(name, 'Added')
`git add .`
`git commit -m "Initialized."`
end
path
end
# Clones a repo to the given name.
#
def repo_clone(from_name, to_name)
Dir.chdir(tmp_repos_path) { `git clone #{from_name} #{to_name}` }
repo_path(to_name)
end
def git_config(repo, attr)
git repo, "config --get #{attr}"
def repo_make_readme_change(name, string)
file = repo_path(name) + 'README'
file.open('w') { |f| f << "#{string}" }
end
def add_repo(name, from)
command = Pod::Command.parse(['repo', 'add', name, from])
command.run
# The test branch is used by the push specs
Dir.chdir(command.dir) do
`git checkout -b test >/dev/null 2>&1`
`git branch --set-upstream test origin/master >/dev/null 2>&1`
#--------------------------------------#
def test_repo_path
repo_path('master')
end
command
# Sets up a lighweight master repo in `tmp/cocoapods/master` with the
# contents of `spec/fixtures/spec-repos/test_repo`.
#
def set_up_test_repo
require 'fileutils'
test_repo_path.mkpath
origin = ROOT + 'spec/fixtures/spec-repos/test_repo/.'
destination = tmp_repos_path + 'master'
FileUtils.cp_r(origin, destination)
repo_make('master')
end
def make_change(repo, name)
(repo.dir + 'README').open('w') { |f| f << 'Added!' }
git(name, 'add README')
git(name, 'commit -m "changed"')
#--------------------------------------#
def tmp_repos_path
SpecHelper.temporary_directory + 'cocoapods'
end
module_function :tmp_repos_path
def self.extended(base)
base.before do
tmp_repos_path.mkpath
......
......@@ -28,9 +28,9 @@ module Pod
end
it "does not raise if all dependencies match the platform of the root spec (Podfile)" do
@podfile.platform :ios
@podfile.platform :ios, '6.0'
lambda { @resolver.resolve }.should.not.raise
@podfile.platform :osx
@podfile.platform :osx, '10.7'
lambda { @resolver.resolve }.should.not.raise
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