-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
integration.rb
271 lines (226 loc) · 9.17 KB
/
integration.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# ------------------------------------ #
# CocoaPods Integration tests #
# ------------------------------------ #
#-----------------------------------------------------------------------------#
# The following integrations tests are based on file comparison.
#
# 1. For each test there is a folder with a `before` and `after` subfolders.
# 2. The contents of the before folder are copied to the `TMP_DIR` folder and
# then the given arguments are passed to the `POD_BINARY`.
# 3. After the pod command completes the execution the each file in the
# `after` subfolder is compared to be to the contents of the temporary
# directory. If the contents of the file do not match an error is
# registered. Xcode projects are compared in an UUID agnostic way.
#
# Notes:
#
# - The output of the pod command is saved in the `execution_output.txt` file
# which should be added to the `after` folder to test the CocoaPods UI.
# - To create a new test, just create a before folder with the environment to
# test, copy it to the after folder and run the tested pod command inside.
# Then just add the tests below this files with the name of the folder and
# the arguments.
#
# Rationale:
#
# - Have a way to track precisely the evolution of the artifacts (and of the
# UI) produced by CocoaPods (git diff of the after folders).
# - Allow uses to submit pull requests with the environment necessary to
# reproduce an issue.
# - Have robust tests which don't depend on the programmatic interface of
# CocoaPods. These tests depend only the binary and its arguments an thus are
# suitable for testing CP regardless of the implementation (they could even
# work for an Objective-C one)
#-----------------------------------------------------------------------------#
# @return [Pathname] The root of the repo.
#
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 'clintegracon'
require 'integration/xcodeproj_project_yaml'
require 'tmpdir'
CLIntegracon.configure do |c|
c.spec_path = ROOT + 'spec/cocoapods-integration-specs'
c.temp_path = ROOT + 'tmp'
# 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
# Register special handling for YAML files
paths = [/Podfile\.lock/, /Manifest\.lock$/, /xcodeproj\.yaml$/]
c.has_special_handling_for(*paths) do |path|
# Remove CocoaPods version
yaml = File.open(path) { |f| YAML.load(f) }
yaml.delete('COCOAPODS')
YAML.dump(yaml)
end
# So we don't need to compare them directly
c.ignores /\.xcodeproj\//
c.ignores 'Podfile'
# Ignore certain OSX files
c.ignores '.DS_Store'
# Ignore xcuserdata
c.ignores %r{/xcuserdata/}
# Needed for some test cases
c.ignores '*.podspec'
c.ignores 'PodTest-hg-source/**'
c.hook_into :bacon
end
describe_cli 'pod' do
Process.wait(spawn('which hg', :err => :out, :out => '/dev/null'))
has_mercurial = $?.success?
subject do |s|
s.executable = "ruby #{ROOT + 'bin/pod'}"
s.environment_vars = {
'CP_REPOS_DIR' => ROOT + 'spec/fixtures/spec-repos',
'COCOAPODS_SKIP_CACHE' => 'TRUE',
'XCODEPROJ_DISABLE_XCPROJ' => 'TRUE',
'CLAIDE_DISABLE_AUTO_WRAP' => 'TRUE',
}
s.default_args = [
'--verbose',
'--no-ansi',
]
s.replace_path ROOT.to_s, 'ROOT'
s.replace_path `which git`.chomp, 'GIT_BIN'
s.replace_path `which hg`.chomp, 'HG_BIN' if has_mercurial
s.replace_user_path 'Library/Caches/CocoaPods', 'CACHES_DIR'
s.replace_pattern /#{Dir.tmpdir}\/[\w-]+/i, 'TMPDIR'
s.replace_pattern /\d{4}-\d\d-\d\d \d\d:\d\d:\d\d [-+]\d{4}/, '<#DATE#>'
s.replace_pattern /\(Took \d+.\d+ seconds\)/, '(Took <#DURATION#> seconds)'
end
describe 'Pod install' do
# Test installation with no integration
# Test subspecs inheritance
describe 'Integrates a project with CocoaPods' do
behaves_like cli_spec 'install_new',
'install --no-repo-update'
end
describe 'Adds a Pod to an existing installation' do
behaves_like cli_spec 'install_add_pod',
'install --no-repo-update'
end
describe 'Removes a Pod from an existing installation' do
behaves_like cli_spec 'install_remove_pod',
'install --no-repo-update'
end
describe 'Creates an installation with multiple target definitions' do
behaves_like cli_spec 'install_multiple_targets',
'install --no-repo-update'
end
description = 'Installs a Pod with different subspecs activated across different targets'
if has_mercurial
describe description do
behaves_like cli_spec 'install_subspecs',
'install --no-repo-update'
end
else
Bacon::ErrorLog << "[!] Skipping test due to missing `hg` executable: #{description}".red << "\n\n"
end
describe 'Installs a Pod with subspecs and does not duplicate the prefix header' do
behaves_like cli_spec 'install_subspecs_no_duplicate_prefix',
'install --no-repo-update'
end
describe 'Installs a Pod with a local source' do
behaves_like cli_spec 'install_local_source',
'install --no-repo-update'
end
description = 'Installs a Pod with an external source'
if has_mercurial
describe description do
behaves_like cli_spec 'install_external_source',
'install --no-repo-update'
end
else
Bacon::ErrorLog << "[!] Skipping test due to missing `hg` executable: #{description}".red << "\n\n"
end
describe 'Installs a Pod given the podspec' do
behaves_like cli_spec 'install_podspec',
'install --no-repo-update'
end
describe 'Installs a Pod with a custom module map' do
behaves_like cli_spec 'install_custom_module_map',
'install --no-repo-update'
end
describe 'Installs a Pod with a custom module name' do
behaves_like cli_spec 'install_custom_module_name',
'install --no-repo-update'
end
describe 'Performs an installation using a custom workspace' do
behaves_like cli_spec 'install_custom_workspace',
'install --no-repo-update'
end
describe 'Integrates a target with custom build settings' do
behaves_like cli_spec 'install_custom_build_configuration',
'install --no-repo-update'
end
describe 'Integrates a Pod with resources' do
behaves_like cli_spec 'install_resources',
'install --no-repo-update'
end
describe 'Integrates a Pod without source files but with resources' do
behaves_like cli_spec 'install_resources_no_source_files',
'install --no-repo-update'
end
describe 'Integrates a Pod using frameworks with resources' do
behaves_like cli_spec 'install_framework_resources',
'install --no-repo-update'
end
describe 'Integrates a Pod using non Objective-C source files' do
behaves_like cli_spec 'install_non_objective_c_files',
'install --no-repo-update'
end
# @todo add tests for all the hooks API
#
describe 'Runs the Podfile callbacks' do
behaves_like cli_spec 'install_podfile_callbacks',
'install --no-repo-update'
end
describe 'Uses Lockfile checkout options' do
behaves_like cli_spec 'install_using_checkout_options',
'install --no-repo-update'
end
end
#--------------------------------------#
describe 'Pod update' do
describe 'Updates an existing installation' do
behaves_like cli_spec 'update_all',
'update --no-repo-update'
end
describe 'Updates a selected Pod in an existing installation' do
behaves_like cli_spec 'update_selected',
'update Reachability --no-repo-update'
end
end
#--------------------------------------#
describe 'Pod lint' do
describe 'Lints a Pod from source with a prepare_command' do
# We have to disable verbose mode by adding --no-verbose here,
# otherwise xcodebuild output is included in execution output.
behaves_like cli_spec 'lib_lint_with_prepare_command',
'lib lint',
'--no-verbose'
end
describe 'Lints a Pod' do
behaves_like cli_spec 'spec_lint',
'spec lint --quick'
end
end
#--------------------------------------#
describe 'Pod init' do
describe 'Initializes a Podfile with a single platform' do
behaves_like cli_spec 'init_single_platform',
'init'
end
end
#--------------------------------------#
end