ext 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,16 @@ module Externals
6
6
  class TestProjects < TestCase
7
7
  include ExtTestCase
8
8
 
9
+ def setup
10
+ teardown
11
+ end
12
+
13
+ def teardown
14
+ Dir.chdir File.join(root_dir, 'test') do
15
+ `rm -rf test_svn_global_opts`
16
+ end
17
+ end
18
+
9
19
  def test_project_scm
10
20
  assert_equal "svn", SvnProject.scm
11
21
  assert_equal "git", GitProject.scm
@@ -13,5 +13,37 @@ module Externals
13
13
  assert_equal "lol_your_mom".classify, "LolYourMom"
14
14
  assert_equal "".classify, ""
15
15
  end
16
+
17
+ def test_lines_by_width
18
+ assert_equal [
19
+ "this",
20
+ "is a",
21
+ "test"
22
+ ],
23
+ "this is a test".lines_by_width(4)
24
+
25
+ assert_equal [
26
+ "this",
27
+ "is",
28
+ "a",
29
+ "test"
30
+ ],
31
+ "this is a test".lines_by_width(2)
32
+
33
+ assert_equal ["this is a test"], "this is a test".lines_by_width
34
+
35
+ assert_equal [
36
+ "The working directory to execute",
37
+ "commands from. Use this if for",
38
+ "some reason you cannot execute",
39
+ "ext from the main project's",
40
+ "directory (or if it's just",
41
+ "inconvenient, such as in a",
42
+ "script or in a Capistrano task)"
43
+ ],
44
+ "The working directory to execute commands from. Use this if for some reason you
45
+ cannot execute ext from the main project's directory (or if it's just inconvenient, such as in a script
46
+ or in a Capistrano task)".lines_by_width
47
+ end
16
48
  end
17
49
  end
@@ -0,0 +1,501 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib') if $0 == __FILE__
2
+ require 'externals/test_case'
3
+ require 'externals/ext'
4
+
5
+ module Externals
6
+ class TestSvnBranches < TestCase
7
+ include ExtTestCase
8
+
9
+ def teardown
10
+ destroy_rails_application
11
+ destroy_with_svn_branches_repository
12
+ destroy_with_svn_branches_modules_repository
13
+
14
+ Dir.chdir File.join(root_dir, 'test') do
15
+ parts = 'workdir/checkout/rails_app/vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/connection_adapters/.svn/text-base/table_definition.rb.svn-base'.split('/')
16
+ if File.exists? File.join(*parts)
17
+ Dir.chdir File.join(*(parts[0..-2])) do
18
+ File.delete parts[-1]
19
+ end
20
+ end
21
+ `rm -rf workdir`
22
+ end
23
+ end
24
+
25
+ def setup
26
+ teardown
27
+
28
+ create_rails_application
29
+
30
+ create_with_svn_branches_repository
31
+ create_with_svn_branches_modules_repository
32
+ initialize_with_svn_branches_repository
33
+ initialize_with_svn_branches_modules_repository
34
+ end
35
+
36
+ def test_checkout_with_subproject
37
+ Dir.chdir File.join(root_dir, 'test') do
38
+ Dir.chdir 'workdir' do
39
+ `mkdir checkout`
40
+ Dir.chdir 'checkout' do
41
+ source = with_svn_branches_repository_url
42
+ if windows?
43
+ source = source.gsub(/\\/, "/")
44
+ end
45
+
46
+ puts "About to checkout #{source}"
47
+ Ext.run "checkout", "--svn", source, "-b", "current", 'rails_app'
48
+
49
+ Dir.chdir 'rails_app' do
50
+ assert File.exists?('.svn')
51
+
52
+ %w(foreign_key_migrations redhillonrails_core acts_as_list).each do |proj|
53
+ ignore_text = `svn propget svn:ignore vendor/plugins`
54
+ puts "ignore_text is:"
55
+ puts ignore_text
56
+ assert(ignore_text =~ /^#{proj}$/)
57
+ end
58
+
59
+ ignore_text = `svn propget svn:ignore vendor`
60
+ assert(ignore_text =~ /^rails$/)
61
+
62
+ %w(foreign_key_migrations redhillonrails_core acts_as_list engines).each do |proj|
63
+ assert File.exists?(File.join('vendor', 'plugins', proj, 'lib'))
64
+ end
65
+
66
+ assert File.exists?(File.join('vendor', 'rails', 'activerecord', 'lib'))
67
+
68
+ assert File.exists?(File.join('vendor', 'rails', '.git'))
69
+
70
+ assert File.exists?(File.join('modules', 'modules.txt'))
71
+
72
+ assert File.read(File.join('modules', 'modules.txt')) =~ /line1 of/
73
+
74
+ ext = Ext.new
75
+ main_project = ext.main_project
76
+ engines = ext.subproject("engines")
77
+ modules = ext.subproject("modules")
78
+
79
+ assert_equal "current", main_project.current_branch
80
+
81
+ assert_equal "edge", engines.current_branch
82
+ assert_equal "edge", ext.configuration["vendor/plugins/engines"]["branch"]
83
+
84
+ assert_equal "current", modules.current_branch
85
+ assert_equal "current", ext.configuration["modules"]["branch"]
86
+
87
+ `svn switch #{[source, "branches", "new_branch"].join("/")}`
88
+ unless $? == 0
89
+ raise
90
+ end
91
+
92
+ assert !main_project.ignore_contains?("vendor/rails")
93
+
94
+ ext = Ext.new
95
+ main_project = ext.main_project
96
+ engines = ext.subproject("engines")
97
+ modules = ext.subproject("modules")
98
+
99
+ assert_equal "branches/new_branch", main_project.current_branch
100
+
101
+ assert_equal "edge", engines.current_branch
102
+ assert_equal "branch1", ext.configuration["vendor/plugins/engines"]["branch"]
103
+
104
+ assert_equal "current", modules.current_branch
105
+ assert_equal "branches/branch2", ext.configuration["modules"]["branch"]
106
+
107
+ Ext.run "up"
108
+
109
+ assert_equal "branches/new_branch", main_project.current_branch
110
+
111
+ assert_equal "branch1", engines.current_branch
112
+ assert_equal "branch1", ext.configuration["vendor/plugins/engines"]["branch"]
113
+
114
+ assert_equal "branches/branch2", modules.current_branch
115
+ assert_equal "branches/branch2", ext.configuration["modules"]["branch"]
116
+
117
+ assert File.read(File.join('modules', 'modules.txt')) =~
118
+ /line 2 of modules.txt ... this is branch2!/
119
+
120
+ `svn switch #{[source, "current"].join("/")}`
121
+ ext = Ext.new
122
+ main_project = ext.main_project
123
+ engines = ext.subproject("engines")
124
+ modules = ext.subproject("modules")
125
+
126
+ assert_equal "current", main_project.current_branch
127
+
128
+ assert_equal "branch1", engines.current_branch
129
+ assert_equal "edge", ext.configuration["vendor/plugins/engines"]["branch"]
130
+
131
+ assert_equal "branches/branch2", modules.current_branch
132
+ assert_equal "current", ext.configuration["modules"]["branch"]
133
+ assert File.read(File.join('modules', 'modules.txt')) =~
134
+ /line 2 of modules.txt ... this is branch2!/
135
+
136
+ Ext.run "up"
137
+ ext = Ext.new
138
+ main_project = ext.main_project
139
+ engines = ext.subproject("engines")
140
+ modules = ext.subproject("modules")
141
+
142
+ assert File.exists?(File.join('vendor', 'rails', 'activerecord', 'lib'))
143
+
144
+ assert File.exists?(File.join('vendor', 'rails', '.git'))
145
+
146
+ assert_equal "current", main_project.current_branch
147
+
148
+ assert_equal "edge", engines.current_branch
149
+ assert_equal "edge", ext.configuration["vendor/plugins/engines"]["branch"]
150
+
151
+ assert_equal "current", modules.current_branch
152
+ assert_equal "current", ext.configuration["modules"]["branch"]
153
+ assert File.read(File.join('modules', 'modules.txt')) !~
154
+ /line 2 of modules.txt ... this is branch2!/
155
+ assert File.read(File.join('modules', 'modules.txt')) =~ /line1 of/
156
+
157
+ assert main_project.ignore_contains?("vendor/rails")
158
+
159
+ # let's test the switch command.
160
+ capture = StringIO.new
161
+ begin
162
+ $stdout = capture
163
+
164
+ Ext.run "switch", "branches/new_branch"
165
+
166
+ ext = Ext.new
167
+ main_project = ext.main_project
168
+ engines = ext.subproject("engines")
169
+ modules = ext.subproject("modules")
170
+
171
+ ensure
172
+ $stdout = STDOUT
173
+ end
174
+ capture = capture.string
175
+
176
+ assert_equal "branches/new_branch", main_project.current_branch
177
+
178
+ assert_equal "branch1", engines.current_branch
179
+ assert_equal "branch1", ext.configuration["vendor/plugins/engines"]["branch"]
180
+
181
+ assert_equal "branches/branch2", modules.current_branch
182
+ assert_equal "branches/branch2", ext.configuration["modules"]["branch"]
183
+
184
+ assert capture =~ /WARNING:/
185
+ assert capture =~ /rm\s+-rf?\s+vendor.rails/
186
+ assert capture.scan(/rm/).size == 1
187
+
188
+ assert !main_project.ignore_contains?("vendor/rails")
189
+
190
+ `rm -rf vendor/rails`
191
+ unless $? == 0
192
+ raise
193
+ end
194
+
195
+ assert File.read(File.join('modules', 'modules.txt')) =~
196
+ /line 2 of modules.txt ... this is branch2!/
197
+
198
+ capture = StringIO.new
199
+ begin
200
+ $stdout = capture
201
+
202
+ Ext.run "switch", "current"
203
+ ext = Ext.new
204
+ main_project = ext.main_project
205
+ engines = ext.subproject("engines")
206
+ modules = ext.subproject("modules")
207
+
208
+ ensure
209
+ $stdout = STDOUT
210
+ end
211
+
212
+ capture = capture.string
213
+
214
+ assert File.exists?(File.join('vendor', 'rails', 'activerecord', 'lib'))
215
+
216
+ assert File.exists?(File.join('vendor', 'rails', '.git'))
217
+
218
+
219
+ assert_equal "current", main_project.current_branch
220
+
221
+ assert_equal "edge", engines.current_branch
222
+ assert_equal "edge", ext.configuration["vendor/plugins/engines"]["branch"]
223
+
224
+ assert_equal "current", modules.current_branch
225
+ assert_equal "current", ext.configuration["modules"]["branch"]
226
+
227
+ assert capture !~ /WARNING:/
228
+ assert capture !~ /rm\s+-rf?\s+vendor.rails/
229
+ assert main_project.ignore_contains?("vendor/rails")
230
+ assert capture.scan(/rm/).size == 0
231
+
232
+ assert File.read(File.join('modules', 'modules.txt')) !~
233
+ /line 2 of modules.txt ... this is branch2!/
234
+ assert File.read(File.join('modules', 'modules.txt')) =~ /line1 of/
235
+ end
236
+ end
237
+ end
238
+ end
239
+ end
240
+
241
+ def test_update_with_missing_subproject_git
242
+ Dir.chdir File.join(root_dir, 'test') do
243
+ Dir.chdir 'workdir' do
244
+ `mkdir update`
245
+ Dir.chdir 'update' do
246
+ source = with_svn_branches_repository_url
247
+ if windows?
248
+ source = source.gsub(/\\/, "/")
249
+ end
250
+
251
+
252
+ puts "About to checkout #{source}"
253
+ Ext.run "checkout", "--svn", "-b", "current", source, 'rails_app'
254
+
255
+ Dir.chdir 'rails_app' do
256
+ pretests = proc do
257
+ assert File.exists?('.svn')
258
+ assert !File.exists?(File.join('vendor', 'plugins', 'ssl_requirement', 'lib'))
259
+ assert File.read(".externals") =~ /rails/
260
+ assert File.read(".externals") !~ /ssl_requirement/
261
+ end
262
+
263
+ pretests.call
264
+
265
+ #add a project
266
+ Dir.chdir File.join(root_dir, 'test') do
267
+ `mkdir rails_app`
268
+ Dir.chdir 'workdir' do
269
+ Ext.run "checkout", "--svn", "-b", "current", source, 'rails_app'
270
+
271
+ Dir.chdir "rails_app" do
272
+ #install a new project
273
+ Ext.run "install", File.join(root_dir, 'test', 'cleanreps', 'ssl_requirement.git')
274
+
275
+ SvnProject.add_all
276
+
277
+ puts `svn commit -m "added another subproject (ssl_requirement)"`
278
+ end
279
+ end
280
+ end
281
+
282
+ pretests.call
283
+
284
+ #update the project and make sure ssl_requirement was added and checked out
285
+ Ext.run "update"
286
+ assert File.read(".externals") =~ /ssl_requirement/
287
+ assert File.exists?(File.join('vendor', 'plugins', 'ssl_requirement', 'lib'))
288
+ end
289
+ end
290
+ end
291
+ end
292
+ end
293
+
294
+ def test_update_with_missing_subproject_by_revision_git
295
+ subproject = "ssl_requirement"
296
+ revision = "aa2dded823f8a9b378c22ba0159971508918928a"
297
+
298
+ Dir.chdir File.join(root_dir, 'test') do
299
+ Dir.chdir 'workdir' do
300
+ `mkdir update`
301
+ Dir.chdir 'update' do
302
+ source = with_svn_branches_repository_url
303
+
304
+ puts "About to checkout #{source}"
305
+ Ext.run "checkout", "--svn", source, "-b", "current", 'rails_app'
306
+
307
+ Dir.chdir 'rails_app' do
308
+ pretests = proc do
309
+ assert File.exists?('.svn')
310
+ assert !File.exists?(File.join('vendor', 'plugins', subproject, 'lib'))
311
+ assert File.read(".externals") =~ /rails/
312
+ assert File.read(".externals") !~ /#{subproject}/
313
+ end
314
+
315
+ pretests.call
316
+
317
+ #add a project
318
+ Dir.chdir File.join(root_dir, 'test') do
319
+ Dir.chdir File.join('workdir') do
320
+ Ext.run "checkout", "--svn", source, "-b", "current", 'rails_app'
321
+
322
+ Dir.chdir File.join("rails_app") do
323
+ #install a new project
324
+ Ext.run "install", File.join(root_dir, 'test', 'cleanreps', "#{subproject}.git")
325
+ Dir.chdir File.join("vendor",'plugins', subproject) do
326
+ assert `git show HEAD` !~ /^\s*commit\s*#{revision}\s*$/i
327
+ end
328
+ #freeze it to a revision
329
+ Ext.run "freeze", subproject, revision
330
+ Dir.chdir File.join("vendor",'plugins', subproject) do
331
+ regex = /^\s*commit\s*#{revision}\s*$/i
332
+ output = `git show HEAD`
333
+ result = output =~ regex
334
+ unless result
335
+ puts "Expecting output to match #{regex} but it was: #{output}"
336
+ end
337
+ assert result
338
+ end
339
+
340
+ SvnProject.add_all
341
+
342
+ puts `svn commit -m "added another subproject (#{subproject}) frozen to #{revision}"`
343
+ end
344
+
345
+ `rm -rf rails_app`
346
+ end
347
+ end
348
+
349
+ pretests.call
350
+
351
+ #update the project and make sure ssl_requirement was added and checked out at the right revision
352
+ Ext.run "update"
353
+ assert File.read(".externals") =~ /ssl_requirement/
354
+
355
+ assert File.exists?(File.join('vendor', 'plugins', subproject, 'lib'))
356
+
357
+ Dir.chdir File.join("vendor",'plugins', subproject) do
358
+ assert `git show HEAD` =~ /^\s*commit\s*#{revision}\s*$/i
359
+ end
360
+ end
361
+ end
362
+ end
363
+ end
364
+ end
365
+
366
+ def test_update_with_missing_subproject_svn
367
+ Dir.chdir File.join(root_dir, 'test') do
368
+ Dir.chdir 'workdir' do
369
+ `mkdir update`
370
+ Dir.chdir 'update' do
371
+ source = with_svn_branches_repository_url
372
+
373
+ puts "About to checkout #{source}"
374
+ Ext.run "checkout", "--svn", "-b", "current", source, 'rails_app'
375
+
376
+ Dir.chdir 'rails_app' do
377
+ pretests = proc do
378
+ assert File.exists?('.svn')
379
+ assert !File.exists?(File.join('vendor', 'plugins', 'empty_plugin', 'lib'))
380
+ assert File.read(".externals") =~ /rails/
381
+ assert File.read(".externals") !~ /empty_plugin/
382
+ end
383
+
384
+ pretests.call
385
+
386
+ #add a project
387
+ Dir.chdir File.join(root_dir, 'test') do
388
+ `mkdir rails_app`
389
+ Dir.chdir 'workdir' do
390
+ Ext.run "checkout", "--svn", "-b", "current", source, 'rails_app'
391
+
392
+ Dir.chdir "rails_app" do
393
+ #install a new project
394
+ Ext.run "install", "--svn",
395
+ "file:///#{File.join(root_dir, 'test', 'cleanreps', 'empty_plugin')}"
396
+
397
+ SvnProject.add_all
398
+
399
+ puts `svn commit -m "added another subproject (empty_plugin)"`
400
+ end
401
+ end
402
+ end
403
+
404
+ pretests.call
405
+
406
+ #update the project and make sure ssl_requirement was added and checked out
407
+ Ext.run "update"
408
+ assert File.read(".externals") =~ /empty_plugin/
409
+ assert File.exists?(File.join('vendor', 'plugins', 'empty_plugin', 'lib'))
410
+ end
411
+ end
412
+ end
413
+ end
414
+ end
415
+
416
+ def test_export_with_subproject
417
+ Dir.chdir File.join(root_dir, 'test') do
418
+ Dir.chdir 'workdir' do
419
+ `mkdir export`
420
+ Dir.chdir 'export' do
421
+ source = with_svn_branches_repository_url
422
+
423
+ puts "About to export #{source}"
424
+ Ext.run "export", "--svn", "-b", "current", source, 'rails_app'
425
+
426
+ Dir.chdir 'rails_app' do
427
+ assert File.exists?('.svn')
428
+
429
+ %w(foreign_key_migrations redhillonrails_core acts_as_list).each do |proj|
430
+ puts(ignore_text = `svn propget svn:ignore vendor/plugins`)
431
+ assert(ignore_text =~ /^#{proj}$/)
432
+ end
433
+
434
+ puts(ignore_text = `svn propget svn:ignore vendor`)
435
+ assert(ignore_text =~ /^rails$/)
436
+
437
+ Dir.chdir File.join('vendor', 'rails') do
438
+ #can't check this if it's local. It seems --depth 1 is ignored for
439
+ #repositories on the local machine.
440
+ #assert `git show 92f944818eece9fe4bc62ffb39accdb71ebc32be` !~ /azimux/
441
+ end
442
+
443
+ %w(foreign_key_migrations redhillonrails_core acts_as_list).each do |proj|
444
+ puts "filethere? #{proj}: #{File.exists?(File.join('vendor', 'plugins', proj, 'lib'))}"
445
+ if !File.exists?(File.join('vendor', 'plugins', proj, 'lib'))
446
+ puts "here"
447
+ end
448
+ assert File.exists?(File.join('vendor', 'plugins', proj, 'lib'))
449
+ end
450
+
451
+ %w(foreign_key_migrations redhillonrails_core).each do |proj|
452
+ assert !File.exists?(File.join('vendor', 'plugins',proj, '.svn'))
453
+ end
454
+
455
+ assert File.exists?(File.join('vendor', 'rails', 'activerecord', 'lib'))
456
+ end
457
+ end
458
+ end
459
+ end
460
+ end
461
+
462
+ def test_uninstall
463
+ Dir.chdir File.join(root_dir, 'test') do
464
+ Dir.chdir 'workdir' do
465
+ `mkdir checkout`
466
+ Dir.chdir 'checkout' do
467
+ source = with_svn_branches_repository_url
468
+
469
+ puts "About to checkout #{source}"
470
+ Ext.run "checkout", "--svn", "-b", "current", source, "rails_app"
471
+
472
+ Dir.chdir 'rails_app' do
473
+ mp = Ext.new.main_project
474
+
475
+ projs = %w(foreign_key_migrations redhillonrails_core acts_as_list)
476
+ projs_i = projs.dup
477
+ projs_ni = []
478
+
479
+ #let's uninstall acts_as_list
480
+ Ext.run "uninstall", "acts_as_list"
481
+
482
+ projs_ni << projs_i.delete('acts_as_list')
483
+
484
+ mp.assert_e_dne_i_ni proc{|a|assert(a)}, projs, [], projs_i, projs_ni
485
+
486
+ Ext.run "uninstall", "-f", "foreign_key_migrations"
487
+
488
+ projs_ni << projs_i.delete('foreign_key_migrations')
489
+
490
+ projs_dne = []
491
+ projs_dne << projs.delete('foreign_key_migrations')
492
+
493
+ mp.assert_e_dne_i_ni proc{|a|assert(a)}, projs, projs_dne, projs_i, projs_ni
494
+ end
495
+ end
496
+ end
497
+ end
498
+ end
499
+
500
+ end
501
+ end