Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
4d7d4e6a
Commit
4d7d4e6a
authored
Jun 14, 2014
by
Marius Rackwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use CLIntegracon for integration specs
parent
19271996
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
258 deletions
+81
-258
integration.rb
spec/integration.rb
+66
-258
xcodeproj_project_yaml.rb
spec/integration/xcodeproj_project_yaml.rb
+15
-0
No files found.
spec/integration.rb
View file @
4d7d4e6a
...
...
@@ -37,274 +37,82 @@
#-----------------------------------------------------------------------------#
# The spec helper is not required on purpose to keep those tests segregated.
# It would also create issues because it clears the temp folder before every
# requirement (`it` call).
require
'pathname'
# @return [Pathname] The root of the repo.
#
ROOT
=
Pathname
.
new
(
File
.
expand_path
(
'../../'
,
__FILE__
))
unless
defined?
ROOT
ROOT
=
Pathname
.
new
(
File
.
expand_path
(
"../../"
,
__FILE__
))
unless
defined?
ROOT
$:
.
unshift
((
ROOT
+
'spec'
).
to_s
)
require
'rubygems'
require
'bundler/setup'
require
'pretty_bacon'
require
'colored'
require
'diffy'
require
'xcodeproj'
# For Differ
# @return [Pathname The folder where the CocoaPods binary should operate.
#
TMP_DIR
=
ROOT
+
'tmp'
unless
defined?
TMP_DIR
# @return [String] The CocoaPods binary to use for the tests.
#
POD_BINARY
=
"ruby "
+
ROOT
.
to_s
+
'/bin/pod'
unless
defined?
POD_BINARY
#-----------------------------------------------------------------------------#
# @!group Helpers
require
"clintegracon"
require
"integration/xcodeproj_project_yaml"
# Copies the before subdirectory of the given tests folder in the temporary
# directory.
#
# @param [String] folder
# the name of the folder of the tests.
#
def
copy_files
(
folder
)
source
=
File
.
expand_path
(
"../cocoapods-integration-specs/
#{
folder
}
/before"
,
__FILE__
)
destination
=
TMP_DIR
+
folder
destination
.
mkpath
FileUtils
.
cp_r
(
Dir
.
glob
(
"
#{
source
}
/*"
),
destination
)
end
# Runs the Pod executable with the given arguments in the temporary directory.
#
# @param [String] arguments
# the arguments to pass to the CocoaPods binary.
#
# @note If the pod binary is called with the ruby executable it requires
# bundler ensuring that the execution is performed in the correct
# environment.
#
def
launch_binary
(
arguments
,
folder
)
command
=
"CP_AGGRESSIVE_CACHE=TRUE
#{
POD_BINARY
}
#{
arguments
}
--verbose --no-ansi 2>&1"
Dir
.
chdir
(
TMP_DIR
+
folder
)
do
output
=
`
#{
command
}
`
it
"$ pod
#{
arguments
}
"
do
$?
.
should
.
satisfy
(
"Pod binary failed
\n\n
#{
output
}
"
)
do
$?
.
success?
end
end
File
.
open
(
'execution_output.txt'
,
'w'
)
do
|
file
|
file
.
write
(
command
.
gsub
(
POD_BINARY
,
'$ pod'
))
file
.
write
(
output
.
gsub
(
ROOT
.
to_s
,
'ROOT'
).
gsub
(
%r[/Users/.*/Library/Caches/CocoaPods/]
,
"CACHES_DIR/"
))
end
end
$?
.
success?
end
CLIntegracon
.
configure
do
|
c
|
c
.
spec_path
=
ROOT
+
"spec/cocoapods-integration-specs"
c
.
temp_path
=
ROOT
+
"tmp"
# Creates a YAML representation of the Xcodeproj files which should be used as
# a reference.
#
def
run_post_execution_actions
(
folder
)
Dir
.
glob
(
"
#{
TMP_DIR
+
folder
}
/**/*.xcodeproj"
)
do
|
project_path
|
xcodeproj
=
Xcodeproj
::
Project
.
open
(
project_path
)
require
'yaml'
pretty_print
=
xcodeproj
.
pretty_print
sections
=
[]
sorted_keys
=
[
'File References'
,
'Targets'
,
'Build Configurations'
]
sorted_keys
.
each
do
|
key
|
yaml
=
{
key
=>
pretty_print
[
key
]}.
to_yaml
sections
<<
yaml
end
file_contents
=
(
sections
*
"
\n\n
"
).
gsub!
(
"---"
,
''
)
File
.
open
(
"
#{
project_path
}
.yaml"
,
'w'
)
do
|
file
|
file
.
write
(
file_contents
)
# Transform produced project files to YAMLs
c
.
transform_produced
"**/*.xcodeproj"
do
|
path
|
# Creates a YAML representation of the Xcodeproj files
# which should be used as a reference for comparison.
xcodeproj
=
Xcodeproj
::
Project
.
open
(
path
)
File
.
open
(
"
#{
path
}
.yaml"
,
"w"
)
do
|
file
|
file
.
write
xcodeproj
.
to_yaml
end
end
end
# Creates a requirement which compares every file in the after folder with the
# artifacts created by the pod executable in the temporary directory according
# to its file type.
#
# @param [String] folder
# the name of the folder of the tests.
#
def
check_with_folder
(
folder
)
source
=
File
.
expand_path
(
"../cocoapods-integration-specs/
#{
folder
}
"
,
__FILE__
)
Dir
.
glob
(
"
#{
source
}
/after/**/*"
)
do
|
expected_path
|
next
unless
File
.
file?
(
expected_path
)
relative_path
=
expected_path
.
gsub
(
"
#{
source
}
/after/"
,
''
)
expected
=
Pathname
.
new
(
expected_path
)
produced
=
TMP_DIR
+
folder
+
relative_path
case
expected_path
when
%r[/xcuserdata/]
,
%r[
\.
pbxproj$]
# Projects are compared through the more readable yaml representation
next
when
%r[execution_output.txt$]
# TODO The output from the caches changes on Travis
next
end
it
relative_path
do
case
expected_path
when
%r[Podfile
\.
lock$]
,
%r[Manifest
\.
lock$]
,
%r[xcodeproj
\.
yaml$]
file_should_exist
(
produced
)
yaml_should_match
(
expected
,
produced
)
else
file_should_exist
(
produced
)
file_should_match
(
expected
,
produced
)
end
end
end
end
#--------------------------------------#
# @!group File Comparisons
# Checks that the file exits.
#
# @param [Pathname] file
# The file to check.
#
def
file_should_exist
(
file
)
file
.
should
.
exist?
end
# Compares two lockfiles because CocoaPods 0.16 doesn't oder them in 1.8.7.
#
# @param [Pathname] expected
# The reference in the `after` folder.
#
# @param [Pathname] produced
# The file in the temporary directory after running the pod command.
#
def
yaml_should_match
(
expected
,
produced
)
expected_yaml
=
File
.
open
(
expected
)
{
|
f
|
YAML
.
load
(
f
)
}
produced_yaml
=
File
.
open
(
produced
)
{
|
f
|
YAML
.
load
(
f
)
}
# Remove CocoaPods version
expected_yaml
.
delete
(
'COCOAPODS'
)
produced_yaml
.
delete
(
'COCOAPODS'
)
desc
=
[]
desc
<<
"YAML comparison error `
#{
expected
}
`"
desc
<<
(
"--- YAML DIFF "
<<
"-"
*
65
)
diffy_diff
=
''
Diffy
::
Diff
.
new
(
expected
.
to_s
,
produced
.
to_s
,
:source
=>
'files'
,
:context
=>
3
).
each
do
|
line
|
case
line
when
/^\+/
then
diffy_diff
<<
line
.
green
when
/^-/
then
diffy_diff
<<
line
.
red
else
diffy_diff
<<
line
end
end
desc
<<
diffy_diff
desc
<<
(
"--- XCODEPROJ DIFF "
<<
"-"
*
60
)
diff_options
=
{
:key_1
=>
"$produced"
,
:key_2
=>
"$expected"
}
diff
=
Xcodeproj
::
Differ
.
diff
(
produced_yaml
,
expected_yaml
,
diff_options
).
to_yaml
diff
.
gsub!
(
"$produced"
,
"produced"
.
green
)
diff
.
gsub!
(
"$expected"
,
"expected"
.
red
)
desc
<<
diff
desc
<<
(
"--- END "
<<
"-"
*
70
)
expected_yaml
.
should
.
satisfy
(
desc
*
"
\n\n
"
)
do
# Register special handling for YAML files
c
.
has_special_handling_for
%r{Podfile
\.
lock}
,
%r{Manifest
\.
lock$}
,
%r{xcodeproj
\.
yaml$}
do
|
path
|
if
RUBY_VERSION
<
"1.9"
true
# CP is not sorting array derived from hashes whose order is
# undefined in 1.8.7
nil
# CP is not sorting array derived from hashes whose order is
# undefined in 1.8.7
else
expected_yaml
==
produced_yaml
# Remove CocoaPods version
yaml
=
File
.
open
(
path
)
{
|
f
|
YAML
.
load
(
f
)
}
yaml
.
delete
(
"COCOAPODS"
)
yaml
.
to_s
end
end
end
# Compares two Xcode projects in an UUID insensitive fashion and producing a
# clear diff to highlight the differences.
#
# @param [Pathname] expected @see #yaml_should_match
# @param [Pathname] produced @see #yaml_should_match
#
# def xcodeproj_should_match(expected, produced)
# expected_proj = Xcodeproj::Project.open(expected + '..')
# produced_proj = Xcodeproj::Project.open(produced + '..')
# diff = produced_proj.to_tree_hash.recursive_diff(expected_proj.to_tree_hash, "#produced#", "#reference#")
# desc = "Project comparison error `#{expected}`"
# if diff
# desc << "\n\n#{diff.inspect.cyan}"
# pretty_yaml = diff.to_yaml
# pretty_yaml = pretty_yaml.gsub(/['"]#produced#['"]/,'produced'.cyan)
# pretty_yaml = pretty_yaml.gsub(/['"]#reference#['"]/,'reference'.magenta)
# desc << "\n\n#{pretty_yaml}"
# end
# diff.should.satisfy(desc) do |diff|
# diff.nil?
# end
# end
# Compares two files to check if they are identical and produces a clear diff
# to highlight the differences.
#
# @param [Pathname] expected @see #yaml_should_match
# @param [Pathname] produced @see #yaml_should_match
#
def
file_should_match
(
expected
,
produced
)
is_equal
=
FileUtils
.
compare_file
(
expected
,
produced
)
description
=
[]
description
<<
"File comparison error `
#{
expected
}
`"
description
<<
""
description
<<
(
"--- DIFF "
<<
"-"
*
70
)
Diffy
::
Diff
.
new
(
expected
.
to_s
,
produced
.
to_s
,
:source
=>
'files'
,
:context
=>
3
).
each
do
|
line
|
case
line
when
/^\+/
then
description
<<
line
.
gsub
(
"
\n
"
,
''
).
green
when
/^-/
then
description
<<
line
.
gsub
(
"
\n
"
,
''
).
red
else
description
<<
line
.
gsub
(
"
\n
"
,
''
)
end
end
description
<<
(
"--- END "
<<
"-"
*
70
)
description
<<
""
is_equal
.
should
.
satisfy
(
description
*
"
\n
"
)
do
is_equal
==
true
end
end
# So we don't need to compare them directly
c
.
ignores
%r{
\.
xcodeproj/}
c
.
ignores
"Podfile"
#-----------------------------------------------------------------------------#
# Ignore certain OSX files
c
.
ignores
".DS_Store"
# @!group Description implementation
# Ignore xcuserdata
c
.
ignores
%r{/xcuserdata/}
# Performs the checks for the test with the given folder using the given
# arguments.
#
# @param [String] arguments
# The arguments to pass to the Pod executable.
#
# @param [String] folder
# The name of the folder which contains the `before` and `after`
# subfolders.
#
def
check
(
arguments
,
folder
)
focused_check
(
arguments
,
folder
)
end
# TODO The output from the caches changes on Travis
c
.
ignores
"execution_output.txt"
# Shortcut to focus on a test: Comment the implementation of #check and
# call this from the relevant test.
#
def
focused_check
(
arguments
,
folder
)
copy_files
(
folder
)
executed
=
launch_binary
(
arguments
,
folder
)
run_post_execution_actions
(
folder
)
check_with_folder
(
folder
)
if
executed
# Needed for some test cases
c
.
ignores
"Reachability.podspec"
c
.
ignores
"PodTest-hg-source/**"
c
.
hook_into
:bacon
end
#-----------------------------------------------------------------------------#
describe
"Integration"
do
TMP_DIR
.
rmtree
if
TMP_DIR
.
exist?
TMP_DIR
.
mkpath
describe_cli
"pod"
do
subject
do
|
s
|
s
.
executable
=
"ruby
#{
ROOT
+
"bin/pod"
}
"
s
.
environment_vars
=
{
"CP_AGGRESSIVE_CACHE"
=>
"TRUE"
}
s
.
default_args
=
[
"--verbose"
,
"--no-ansi"
]
s
.
replace_path
ROOT
.
to_s
,
"ROOT"
s
.
replace_user_path
"Library/Caches/CocoaPods"
,
"CACHES_DIR"
end
describe
"Pod install"
do
...
...
@@ -312,53 +120,53 @@ describe "Integration" do
# Test subspecs inheritance
describe
"Integrates a project with CocoaPods"
do
check
"install --no-repo-update"
,
"install_new
"
behaves_like
cli_spec
"install_new"
,
"install --no-repo-update
"
end
describe
"Adds a Pod to an existing installation"
do
check
"install --no-repo-update"
,
"install_add_pod
"
behaves_like
cli_spec
"install_add_pod"
,
"install --no-repo-update
"
end
describe
"Removes a Pod from an existing installation"
do
check
"install --no-repo-update"
,
"install_remove_pod
"
behaves_like
cli_spec
"install_remove_pod"
,
"install --no-repo-update
"
end
describe
"Creates an installation with multiple target definitions"
do
check
"install --no-repo-update"
,
"install_multiple_targets
"
behaves_like
cli_spec
"install_multiple_targets"
,
"install --no-repo-update
"
end
describe
"Installs a Pod with different subspecs activated across different targets"
do
check
"install --no-repo-update"
,
"install_subspecs
"
behaves_like
cli_spec
"install_subspecs"
,
"install --no-repo-update
"
end
describe
"Installs a Pod with subspecs and does not duplicate the prefix header"
do
check
"install --no-repo-update"
,
"install_subspecs_no_duplicate_prefix
"
behaves_like
cli_spec
"install_subspecs_no_duplicate_prefix"
,
"install --no-repo-update
"
end
describe
"Installs a Pod with a local source"
do
check
"install --no-repo-update"
,
"install_local_sourc
e"
behaves_like
cli_spec
"install_local_source"
,
"install --no-repo-updat
e"
end
describe
"Installs a Pod with an external source"
do
check
"install --no-repo-update"
,
"install_external_sourc
e"
behaves_like
cli_spec
"install_external_source"
,
"install --no-repo-updat
e"
end
describe
"Installs a Pod given the podspec"
do
check
"install --no-repo-update"
,
"install_podspec
"
behaves_like
cli_spec
"install_podspec"
,
"install --no-repo-update
"
end
describe
"Performs an installation using a custom workspace"
do
check
"install --no-repo-update"
,
"install_custom_workspac
e"
behaves_like
cli_spec
"install_custom_workspace"
,
"install --no-repo-updat
e"
end
describe
"Integrates a target with custom build settings"
do
check
"install --no-repo-update"
,
"install_custom_build_configuration
"
behaves_like
cli_spec
"install_custom_build_configuration"
,
"install --no-repo-update
"
end
# @todo add tests for all the hooks API
#
describe
"Runs the Podfile callbacks"
do
check
"install --no-repo-update"
,
"install_podfile_callbacks
"
behaves_like
cli_spec
"install_podfile_callbacks"
,
"install --no-repo-update
"
end
end
...
...
@@ -367,11 +175,11 @@ describe "Integration" do
describe
"Pod update"
do
describe
"Updates an existing installation"
do
check
"update --no-repo-update"
,
"update_all
"
behaves_like
cli_spec
"update_all"
,
"update --no-repo-update
"
end
describe
"Updates a selected Pod in an existing installation"
do
check
"update Reachability --no-repo-update"
,
"update_selected
"
behaves_like
cli_spec
"update_selected"
,
"update Reachability --no-repo-update
"
end
end
...
...
@@ -381,7 +189,7 @@ describe "Integration" do
describe
"Pod lint"
do
describe
"Lints a Pod"
do
check
"spec lint --quick"
,
"spec_lint
"
behaves_like
cli_spec
"spec_lint"
,
"spec lint --quick
"
end
end
...
...
@@ -391,7 +199,7 @@ describe "Integration" do
describe
"Pod init"
do
describe
"Initializes a Podfile with a single platform"
do
check
"init"
,
"init_single_platform
"
behaves_like
cli_spec
"init_single_platform"
,
"init
"
end
end
...
...
spec/integration/xcodeproj_project_yaml.rb
0 → 100644
View file @
4d7d4e6a
require
"xcodeproj"
require
"yaml"
class
Xcodeproj
::
Project
def
to_yaml
pretty_print_output
=
pretty_print
sections
=
[]
sorted_keys
=
[
"File References"
,
"Targets"
,
"Build Configurations"
]
sorted_keys
.
each
do
|
key
|
yaml
=
{
key
=>
pretty_print_output
[
key
]
}.
to_yaml
sections
<<
yaml
end
(
sections
*
"
\n\n
"
).
gsub!
(
"---"
,
''
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment