rubygems-update 2.1.11 → 2.2.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.autotest +37 -12
  5. data/History.txt +99 -2
  6. data/MIT.txt +1 -0
  7. data/Manifest.txt +59 -19
  8. data/Rakefile +4 -6
  9. data/lib/gauntlet_rubygems.rb +1 -1
  10. data/lib/rubygems.rb +102 -80
  11. data/lib/rubygems/available_set.rb +2 -2
  12. data/lib/rubygems/basic_specification.rb +97 -8
  13. data/lib/rubygems/commands/install_command.rb +58 -15
  14. data/lib/rubygems/commands/list_command.rb +1 -7
  15. data/lib/rubygems/commands/outdated_command.rb +1 -1
  16. data/lib/rubygems/commands/pristine_command.rb +14 -1
  17. data/lib/rubygems/commands/push_command.rb +9 -4
  18. data/lib/rubygems/commands/query_command.rb +33 -17
  19. data/lib/rubygems/commands/search_command.rb +0 -6
  20. data/lib/rubygems/commands/specification_command.rb +1 -1
  21. data/lib/rubygems/commands/unpack_command.rb +1 -1
  22. data/lib/rubygems/commands/update_command.rb +4 -1
  23. data/lib/rubygems/commands/which_command.rb +5 -8
  24. data/lib/rubygems/compatibility.rb +3 -0
  25. data/lib/rubygems/core_ext/kernel_gem.rb +6 -0
  26. data/lib/rubygems/defaults.rb +19 -0
  27. data/lib/rubygems/dependency_installer.rb +28 -9
  28. data/lib/rubygems/doctor.rb +17 -11
  29. data/lib/rubygems/errors.rb +16 -3
  30. data/lib/rubygems/exceptions.rb +52 -5
  31. data/lib/rubygems/ext.rb +1 -2
  32. data/lib/rubygems/ext/build_error.rb +6 -0
  33. data/lib/rubygems/ext/builder.rb +50 -17
  34. data/lib/rubygems/ext/cmake_builder.rb +1 -1
  35. data/lib/rubygems/ext/configure_builder.rb +1 -3
  36. data/lib/rubygems/ext/ext_conf_builder.rb +9 -3
  37. data/lib/rubygems/ext/rake_builder.rb +2 -5
  38. data/lib/rubygems/gemcutter_utilities.rb +8 -1
  39. data/lib/rubygems/installer.rb +14 -4
  40. data/lib/rubygems/installer_test_case.rb +0 -5
  41. data/lib/rubygems/package.rb +11 -2
  42. data/lib/rubygems/psych_additions.rb +1 -1
  43. data/lib/rubygems/rdoc.rb +1 -1
  44. data/lib/rubygems/remote_fetcher.rb +3 -3
  45. data/lib/rubygems/request.rb +16 -8
  46. data/lib/rubygems/request_set.rb +133 -42
  47. data/lib/rubygems/request_set/gem_dependency_api.rb +493 -11
  48. data/lib/rubygems/request_set/lockfile.rb +579 -0
  49. data/lib/rubygems/requirement.rb +58 -30
  50. data/lib/rubygems/resolver.rb +471 -0
  51. data/lib/rubygems/resolver/activation_request.rb +165 -0
  52. data/lib/rubygems/resolver/api_set.rb +110 -0
  53. data/lib/rubygems/resolver/api_specification.rb +79 -0
  54. data/lib/rubygems/resolver/best_set.rb +31 -0
  55. data/lib/rubygems/resolver/composed_set.rb +39 -0
  56. data/lib/rubygems/resolver/conflict.rb +122 -0
  57. data/lib/rubygems/{dependency_resolver → resolver}/current_set.rb +1 -4
  58. data/lib/rubygems/{dependency_resolver → resolver}/dependency_request.rb +37 -7
  59. data/lib/rubygems/resolver/git_set.rb +119 -0
  60. data/lib/rubygems/resolver/git_specification.rb +35 -0
  61. data/lib/rubygems/resolver/index_set.rb +74 -0
  62. data/lib/rubygems/resolver/index_specification.rb +69 -0
  63. data/lib/rubygems/resolver/installed_specification.rb +40 -0
  64. data/lib/rubygems/{dependency_resolver → resolver}/installer_set.rb +18 -17
  65. data/lib/rubygems/resolver/local_specification.rb +16 -0
  66. data/lib/rubygems/resolver/lock_set.rb +78 -0
  67. data/lib/rubygems/resolver/lock_specification.rb +58 -0
  68. data/lib/rubygems/resolver/requirement_list.rb +81 -0
  69. data/lib/rubygems/resolver/set.rb +27 -0
  70. data/lib/rubygems/resolver/spec_specification.rb +58 -0
  71. data/lib/rubygems/resolver/specification.rb +89 -0
  72. data/lib/rubygems/resolver/stats.rb +44 -0
  73. data/lib/rubygems/resolver/vendor_set.rb +83 -0
  74. data/lib/rubygems/resolver/vendor_specification.rb +24 -0
  75. data/lib/rubygems/security/trust_dir.rb +16 -2
  76. data/lib/rubygems/source.rb +71 -18
  77. data/lib/rubygems/source/git.rb +218 -0
  78. data/lib/rubygems/source/installed.rb +8 -1
  79. data/lib/rubygems/source/local.rb +14 -8
  80. data/lib/rubygems/source/lock.rb +48 -0
  81. data/lib/rubygems/source/specific_file.rb +14 -3
  82. data/lib/rubygems/source/vendor.rb +27 -0
  83. data/lib/rubygems/source_list.rb +74 -12
  84. data/lib/rubygems/spec_fetcher.rb +36 -4
  85. data/lib/rubygems/specification.rb +214 -65
  86. data/lib/rubygems/stub_specification.rb +57 -1
  87. data/lib/rubygems/syck_hack.rb +3 -3
  88. data/lib/rubygems/test_case.rb +226 -59
  89. data/lib/rubygems/test_utilities.rb +198 -0
  90. data/lib/rubygems/uninstaller.rb +22 -10
  91. data/lib/rubygems/uri_formatter.rb +20 -0
  92. data/lib/rubygems/user_interaction.rb +193 -71
  93. data/lib/rubygems/util.rb +121 -0
  94. data/lib/rubygems/util/list.rb +4 -0
  95. data/lib/rubygems/util/stringio.rb +34 -0
  96. data/lib/rubygems/validator.rb +6 -2
  97. data/lib/rubygems/version.rb +4 -8
  98. data/test/rubygems/test_bundled_ca.rb +1 -1
  99. data/test/rubygems/test_gem.rb +137 -29
  100. data/test/rubygems/test_gem_available_set.rb +19 -0
  101. data/test/rubygems/test_gem_commands_build_command.rb +1 -1
  102. data/test/rubygems/test_gem_commands_cert_command.rb +2 -2
  103. data/test/rubygems/test_gem_commands_cleanup_command.rb +13 -13
  104. data/test/rubygems/test_gem_commands_dependency_command.rb +24 -34
  105. data/test/rubygems/test_gem_commands_fetch_command.rb +43 -48
  106. data/test/rubygems/test_gem_commands_install_command.rb +244 -279
  107. data/test/rubygems/test_gem_commands_list_command.rb +3 -3
  108. data/test/rubygems/test_gem_commands_outdated_command.rb +7 -12
  109. data/test/rubygems/test_gem_commands_pristine_command.rb +73 -27
  110. data/test/rubygems/test_gem_commands_push_command.rb +76 -8
  111. data/test/rubygems/test_gem_commands_query_command.rb +239 -49
  112. data/test/rubygems/test_gem_commands_sources_command.rb +10 -43
  113. data/test/rubygems/test_gem_commands_specification_command.rb +24 -47
  114. data/test/rubygems/test_gem_commands_stale_command.rb +2 -2
  115. data/test/rubygems/test_gem_commands_uninstall_command.rb +3 -3
  116. data/test/rubygems/test_gem_commands_unpack_command.rb +16 -30
  117. data/test/rubygems/test_gem_commands_update_command.rb +149 -134
  118. data/test/rubygems/test_gem_commands_which_command.rb +4 -2
  119. data/test/rubygems/test_gem_dependency_installer.rb +68 -0
  120. data/test/rubygems/test_gem_dependency_list.rb +17 -17
  121. data/test/rubygems/test_gem_dependency_resolution_error.rb +28 -0
  122. data/test/rubygems/test_gem_doctor.rb +1 -1
  123. data/test/rubygems/test_gem_ext_builder.rb +178 -8
  124. data/test/rubygems/test_gem_ext_cmake_builder.rb +1 -7
  125. data/test/rubygems/test_gem_ext_configure_builder.rb +8 -10
  126. data/test/rubygems/test_gem_ext_ext_conf_builder.rb +18 -21
  127. data/test/rubygems/test_gem_ext_rake_builder.rb +1 -3
  128. data/test/rubygems/test_gem_impossible_dependencies_error.rb +10 -6
  129. data/test/rubygems/test_gem_indexer.rb +6 -6
  130. data/test/rubygems/test_gem_installer.rb +29 -10
  131. data/test/rubygems/test_gem_local_remote_options.rb +1 -1
  132. data/test/rubygems/test_gem_package.rb +18 -0
  133. data/test/rubygems/test_gem_rdoc.rb +1 -1
  134. data/test/rubygems/test_gem_remote_fetcher.rb +1 -1
  135. data/test/rubygems/test_gem_request.rb +37 -10
  136. data/test/rubygems/test_gem_request_set.rb +271 -9
  137. data/test/rubygems/test_gem_request_set_gem_dependency_api.rb +684 -0
  138. data/test/rubygems/test_gem_request_set_lockfile.rb +849 -0
  139. data/test/rubygems/test_gem_requirement.rb +21 -0
  140. data/test/rubygems/{test_gem_dependency_resolver.rb → test_gem_resolver.rb} +231 -70
  141. data/test/rubygems/test_gem_resolver_activation_request.rb +63 -0
  142. data/test/rubygems/test_gem_resolver_api_set.rb +167 -0
  143. data/test/rubygems/test_gem_resolver_api_specification.rb +104 -0
  144. data/test/rubygems/test_gem_resolver_best_set.rb +30 -0
  145. data/test/rubygems/test_gem_resolver_conflict.rb +75 -0
  146. data/test/rubygems/test_gem_resolver_dependency_request.rb +20 -0
  147. data/test/rubygems/test_gem_resolver_git_set.rb +148 -0
  148. data/test/rubygems/test_gem_resolver_git_specification.rb +100 -0
  149. data/test/rubygems/test_gem_resolver_index_set.rb +28 -0
  150. data/test/rubygems/test_gem_resolver_index_specification.rb +89 -0
  151. data/test/rubygems/test_gem_resolver_installed_specification.rb +49 -0
  152. data/test/rubygems/test_gem_resolver_installer_set.rb +22 -0
  153. data/test/rubygems/test_gem_resolver_local_specification.rb +45 -0
  154. data/test/rubygems/test_gem_resolver_lock_set.rb +57 -0
  155. data/test/rubygems/test_gem_resolver_lock_specification.rb +87 -0
  156. data/test/rubygems/test_gem_resolver_requirement_list.rb +20 -0
  157. data/test/rubygems/test_gem_resolver_specification.rb +32 -0
  158. data/test/rubygems/test_gem_resolver_vendor_set.rb +67 -0
  159. data/test/rubygems/test_gem_resolver_vendor_specification.rb +83 -0
  160. data/test/rubygems/test_gem_server.rb +4 -4
  161. data/test/rubygems/test_gem_source.rb +54 -64
  162. data/test/rubygems/test_gem_source_git.rb +231 -0
  163. data/test/rubygems/test_gem_source_list.rb +24 -0
  164. data/test/rubygems/test_gem_source_local.rb +1 -1
  165. data/test/rubygems/test_gem_source_lock.rb +114 -0
  166. data/test/rubygems/test_gem_source_vendor.rb +27 -0
  167. data/test/rubygems/test_gem_spec_fetcher.rb +116 -61
  168. data/test/rubygems/test_gem_specification.rb +526 -94
  169. data/test/rubygems/test_gem_stub_specification.rb +123 -10
  170. data/test/rubygems/test_gem_uninstaller.rb +28 -2
  171. data/test/rubygems/test_gem_util.rb +31 -0
  172. data/test/rubygems/test_gem_validator.rb +9 -0
  173. data/util/update_bundled_ca_certificates.rb +8 -1
  174. metadata +89 -29
  175. metadata.gz.sig +2 -4
  176. data/lib/rubygems/dependency_resolver.rb +0 -254
  177. data/lib/rubygems/dependency_resolver/activation_request.rb +0 -109
  178. data/lib/rubygems/dependency_resolver/api_set.rb +0 -65
  179. data/lib/rubygems/dependency_resolver/api_specification.rb +0 -39
  180. data/lib/rubygems/dependency_resolver/composed_set.rb +0 -18
  181. data/lib/rubygems/dependency_resolver/dependency_conflict.rb +0 -85
  182. data/lib/rubygems/dependency_resolver/index_set.rb +0 -64
  183. data/lib/rubygems/dependency_resolver/index_specification.rb +0 -60
  184. data/lib/rubygems/dependency_resolver/installed_specification.rb +0 -52
  185. data/test/rubygems/test_gem_dependency_resolver_api_specification.rb +0 -33
  186. data/test/rubygems/test_gem_dependency_resolver_dependency_conflict.rb +0 -36
  187. data/test/rubygems/test_gem_dependency_resolver_index_set.rb +0 -53
  188. data/test/rubygems/test_gem_dependency_resolver_index_specification.rb +0 -73
  189. data/test/rubygems/test_gem_dependency_resolver_installed_specification.rb +0 -19
  190. data/test/rubygems/test_gem_dependency_resolver_installer_set.rb +0 -28
@@ -0,0 +1,849 @@
1
+ require 'rubygems/test_case'
2
+ require 'rubygems/request_set'
3
+ require 'rubygems/request_set/lockfile'
4
+
5
+ class TestGemRequestSetLockfile < Gem::TestCase
6
+
7
+ def setup
8
+ super
9
+
10
+ Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new
11
+
12
+ util_set_arch 'i686-darwin8.10.1'
13
+
14
+ @set = Gem::RequestSet.new
15
+
16
+ @git_set = Gem::Resolver::GitSet.new
17
+ @vendor_set = Gem::Resolver::VendorSet.new
18
+
19
+ @set.instance_variable_set :@git_set, @git_set
20
+ @set.instance_variable_set :@vendor_set, @vendor_set
21
+
22
+ @gem_deps_file = 'gem.deps.rb'
23
+
24
+ @lockfile = Gem::RequestSet::Lockfile.new @set, @gem_deps_file
25
+ end
26
+
27
+ def write_gem_deps gem_deps
28
+ open @gem_deps_file, 'w' do |io|
29
+ io.write gem_deps
30
+ end
31
+ end
32
+
33
+ def write_lockfile lockfile
34
+ @lock_file = File.expand_path "#{@gem_deps_file}.lock"
35
+
36
+ open @lock_file, 'w' do |io|
37
+ io.write lockfile
38
+ end
39
+ end
40
+
41
+ def test_get
42
+ @lockfile.instance_variable_set :@tokens, [:token]
43
+
44
+ assert_equal :token, @lockfile.get
45
+ end
46
+
47
+ def test_get_type_mismatch
48
+ @lockfile.instance_variable_set :@tokens, [[:section, 'x', 5, 1]]
49
+
50
+ e = assert_raises Gem::RequestSet::Lockfile::ParseError do
51
+ @lockfile.get :text
52
+ end
53
+
54
+ expected =
55
+ 'unexpected token [:section, "x"], expected :text (at line 1 column 5)'
56
+
57
+ assert_equal expected, e.message
58
+
59
+ assert_equal 1, e.line
60
+ assert_equal 5, e.column
61
+ assert_equal File.expand_path("#{@gem_deps_file}.lock"), e.path
62
+ end
63
+
64
+ def test_get_type_multiple
65
+ @lockfile.instance_variable_set :@tokens, [[:section, 'x', 5, 1]]
66
+
67
+ assert @lockfile.get [:text, :section]
68
+ end
69
+
70
+ def test_get_type_value_mismatch
71
+ @lockfile.instance_variable_set :@tokens, [[:section, 'x', 5, 1]]
72
+
73
+ e = assert_raises Gem::RequestSet::Lockfile::ParseError do
74
+ @lockfile.get :section, 'y'
75
+ end
76
+
77
+ expected =
78
+ 'unexpected token [:section, "x"], expected [:section, "y"] (at line 1 column 5)'
79
+
80
+ assert_equal expected, e.message
81
+
82
+ assert_equal 1, e.line
83
+ assert_equal 5, e.column
84
+ assert_equal File.expand_path("#{@gem_deps_file}.lock"), e.path
85
+ end
86
+
87
+ def test_parse
88
+ write_lockfile <<-LOCKFILE.strip
89
+ GEM
90
+ remote: #{@gem_repo}
91
+ specs:
92
+ a (2)
93
+
94
+ PLATFORMS
95
+ #{Gem::Platform::RUBY}
96
+
97
+ DEPENDENCIES
98
+ a
99
+ LOCKFILE
100
+
101
+ @lockfile.parse
102
+
103
+ assert_equal [dep('a')], @set.dependencies
104
+
105
+ assert_equal [Gem::Platform::RUBY], @lockfile.platforms
106
+
107
+ lockfile_set = @set.sets.find do |set|
108
+ Gem::Resolver::LockSet === set
109
+ end
110
+
111
+ assert lockfile_set, 'could not find a LockSet'
112
+
113
+ assert_equal %w[a-2], lockfile_set.specs.map { |tuple| tuple.full_name }
114
+ end
115
+
116
+ def test_parse_dependencies
117
+ write_lockfile <<-LOCKFILE
118
+ GEM
119
+ remote: #{@gem_repo}
120
+ specs:
121
+ a (2)
122
+
123
+ PLATFORMS
124
+ #{Gem::Platform::RUBY}
125
+
126
+ DEPENDENCIES
127
+ a (>= 1, <= 2)
128
+ LOCKFILE
129
+
130
+ @lockfile.parse
131
+
132
+ assert_equal [dep('a', '>= 1', '<= 2')], @set.dependencies
133
+
134
+ assert_equal [Gem::Platform::RUBY], @lockfile.platforms
135
+
136
+ lockfile_set = @set.sets.find do |set|
137
+ Gem::Resolver::LockSet === set
138
+ end
139
+
140
+ assert lockfile_set, 'could not find a LockSet'
141
+
142
+ assert_equal %w[a-2], lockfile_set.specs.map { |tuple| tuple.full_name }
143
+ end
144
+
145
+ def test_parse_GIT
146
+ write_lockfile <<-LOCKFILE
147
+ GIT
148
+ remote: git://example/a.git
149
+ revision: master
150
+ specs:
151
+ a (2)
152
+ b (>= 3)
153
+
154
+ DEPENDENCIES
155
+ a!
156
+ LOCKFILE
157
+
158
+ @lockfile.parse
159
+
160
+ assert_equal [dep('a', '= 2')], @set.dependencies
161
+
162
+ lockfile_set = @set.sets.find do |set|
163
+ Gem::Resolver::LockSet === set
164
+ end
165
+
166
+ refute lockfile_set, 'fount a LockSet'
167
+
168
+ git_set = @set.sets.find do |set|
169
+ Gem::Resolver::GitSet === set
170
+ end
171
+
172
+ assert git_set, 'could not find a GitSet'
173
+
174
+ assert_equal %w[a-2], git_set.specs.values.map { |s| s.full_name }
175
+
176
+ assert_equal [dep('b', '>= 3')], git_set.specs.values.first.dependencies
177
+ end
178
+
179
+ def test_parse_PATH
180
+ _, _, directory = vendor_gem
181
+
182
+ write_lockfile <<-LOCKFILE
183
+ PATH
184
+ remote: #{directory}
185
+ specs:
186
+ a (1)
187
+
188
+ DEPENDENCIES
189
+ a!
190
+ LOCKFILE
191
+
192
+ @lockfile.parse
193
+
194
+ assert_equal [dep('a', '= 1')], @set.dependencies
195
+
196
+ lockfile_set = @set.sets.find do |set|
197
+ Gem::Resolver::LockSet === set
198
+ end
199
+
200
+ refute lockfile_set, 'found a LockSet'
201
+
202
+ vendor_set = @set.sets.find do |set|
203
+ Gem::Resolver::VendorSet === set
204
+ end
205
+
206
+ assert vendor_set, 'could not find a VendorSet'
207
+
208
+ assert_equal %w[a-1], vendor_set.specs.values.map { |s| s.full_name }
209
+ end
210
+
211
+ def test_parse_gem_specs_dependency
212
+ write_lockfile <<-LOCKFILE
213
+ GEM
214
+ remote: #{@gem_repo}
215
+ specs:
216
+ a (2)
217
+ b (= 3)
218
+ c (~> 4)
219
+ d
220
+ e (~> 5.0, >= 5.0.1)
221
+
222
+ PLATFORMS
223
+ #{Gem::Platform::RUBY}
224
+
225
+ DEPENDENCIES
226
+ a
227
+ LOCKFILE
228
+
229
+ @lockfile.parse
230
+
231
+ assert_equal [dep('a')], @set.dependencies
232
+
233
+ assert_equal [Gem::Platform::RUBY], @lockfile.platforms
234
+
235
+ lockfile_set = @set.sets.find do |set|
236
+ Gem::Resolver::LockSet === set
237
+ end
238
+
239
+ assert lockfile_set, 'could not find a LockSet'
240
+
241
+ assert_equal %w[a-2], lockfile_set.specs.map { |tuple| tuple.full_name }
242
+
243
+ spec = lockfile_set.specs.first
244
+
245
+ expected = [
246
+ dep('b', '= 3'),
247
+ dep('c', '~> 4'),
248
+ dep('d'),
249
+ dep('e', '~> 5.0', '>= 5.0.1'),
250
+ ]
251
+
252
+ assert_equal expected, spec.dependencies
253
+ end
254
+
255
+ def test_parse_missing
256
+ @lockfile.parse
257
+
258
+ lockfile_set = @set.sets.find do |set|
259
+ Gem::Resolver::LockSet === set
260
+ end
261
+
262
+ refute lockfile_set
263
+ end
264
+
265
+ def test_peek
266
+ @lockfile.instance_variable_set :@tokens, [:token]
267
+
268
+ assert_equal :token, @lockfile.peek
269
+
270
+ assert_equal :token, @lockfile.get
271
+
272
+ assert_equal [:EOF], @lockfile.peek
273
+ end
274
+
275
+ def test_skip
276
+ tokens = [[:token]]
277
+
278
+ @lockfile.instance_variable_set :@tokens, tokens
279
+
280
+ @lockfile.skip :token
281
+
282
+ assert_empty tokens
283
+ end
284
+
285
+ def test_token_pos
286
+ assert_equal [5, 0], @lockfile.token_pos(5)
287
+
288
+ @lockfile.instance_variable_set :@line_pos, 2
289
+ @lockfile.instance_variable_set :@line, 1
290
+
291
+ assert_equal [3, 1], @lockfile.token_pos(5)
292
+ end
293
+
294
+ def test_tokenize
295
+ write_lockfile <<-LOCKFILE
296
+ GEM
297
+ remote: #{@gem_repo}
298
+ specs:
299
+ a (2)
300
+ b (= 2)
301
+ c (!= 3)
302
+ d (> 4)
303
+ e (< 5)
304
+ f (>= 6)
305
+ g (<= 7)
306
+ h (~> 8)
307
+
308
+ PLATFORMS
309
+ #{Gem::Platform::RUBY}
310
+
311
+ DEPENDENCIES
312
+ a
313
+ LOCKFILE
314
+
315
+ expected = [
316
+ [:section, 'GEM', 0, 0],
317
+ [:newline, nil, 3, 0],
318
+
319
+ [:entry, 'remote', 2, 1],
320
+ [:text, @gem_repo, 10, 1],
321
+ [:newline, nil, 34, 1],
322
+
323
+ [:entry, 'specs', 2, 2],
324
+ [:newline, nil, 8, 2],
325
+
326
+ [:text, 'a', 4, 3],
327
+ [:l_paren, nil, 6, 3],
328
+ [:text, '2', 7, 3],
329
+ [:r_paren, nil, 8, 3],
330
+ [:newline, nil, 9, 3],
331
+
332
+ [:text, 'b', 6, 4],
333
+ [:l_paren, nil, 8, 4],
334
+ [:requirement, '=', 9, 4],
335
+ [:text, '2', 11, 4],
336
+ [:r_paren, nil, 12, 4],
337
+ [:newline, nil, 13, 4],
338
+
339
+ [:text, 'c', 6, 5],
340
+ [:l_paren, nil, 8, 5],
341
+ [:requirement, '!=', 9, 5],
342
+ [:text, '3', 12, 5],
343
+ [:r_paren, nil, 13, 5],
344
+ [:newline, nil, 14, 5],
345
+
346
+ [:text, 'd', 6, 6],
347
+ [:l_paren, nil, 8, 6],
348
+ [:requirement, '>', 9, 6],
349
+ [:text, '4', 11, 6],
350
+ [:r_paren, nil, 12, 6],
351
+ [:newline, nil, 13, 6],
352
+
353
+ [:text, 'e', 6, 7],
354
+ [:l_paren, nil, 8, 7],
355
+ [:requirement, '<', 9, 7],
356
+ [:text, '5', 11, 7],
357
+ [:r_paren, nil, 12, 7],
358
+ [:newline, nil, 13, 7],
359
+
360
+ [:text, 'f', 6, 8],
361
+ [:l_paren, nil, 8, 8],
362
+ [:requirement, '>=', 9, 8],
363
+ [:text, '6', 12, 8],
364
+ [:r_paren, nil, 13, 8],
365
+ [:newline, nil, 14, 8],
366
+
367
+ [:text, 'g', 6, 9],
368
+ [:l_paren, nil, 8, 9],
369
+ [:requirement, '<=', 9, 9],
370
+ [:text, '7', 12, 9],
371
+ [:r_paren, nil, 13, 9],
372
+ [:newline, nil, 14, 9],
373
+
374
+ [:text, 'h', 6, 10],
375
+ [:l_paren, nil, 8, 10],
376
+ [:requirement, '~>', 9, 10],
377
+ [:text, '8', 12, 10],
378
+ [:r_paren, nil, 13, 10],
379
+ [:newline, nil, 14, 10],
380
+
381
+ [:newline, nil, 0, 11],
382
+
383
+ [:section, 'PLATFORMS', 0, 12],
384
+ [:newline, nil, 9, 12],
385
+
386
+ [:text, Gem::Platform::RUBY, 2, 13],
387
+ [:newline, nil, 6, 13],
388
+
389
+ [:newline, nil, 0, 14],
390
+
391
+ [:section, 'DEPENDENCIES', 0, 15],
392
+ [:newline, nil, 12, 15],
393
+
394
+ [:text, 'a', 2, 16],
395
+ [:newline, nil, 3, 16],
396
+ ]
397
+
398
+ assert_equal expected, @lockfile.tokenize
399
+ end
400
+
401
+ def test_tokenize_capitals
402
+ write_lockfile <<-LOCKFILE
403
+ GEM
404
+ remote: #{@gem_repo}
405
+ specs:
406
+ Ab (2)
407
+
408
+ PLATFORMS
409
+ #{Gem::Platform::RUBY}
410
+
411
+ DEPENDENCIES
412
+ Ab
413
+ LOCKFILE
414
+
415
+ expected = [
416
+ [:section, 'GEM', 0, 0],
417
+ [:newline, nil, 3, 0],
418
+ [:entry, 'remote', 2, 1],
419
+ [:text, @gem_repo, 10, 1],
420
+ [:newline, nil, 34, 1],
421
+ [:entry, 'specs', 2, 2],
422
+ [:newline, nil, 8, 2],
423
+ [:text, 'Ab', 4, 3],
424
+ [:l_paren, nil, 7, 3],
425
+ [:text, '2', 8, 3],
426
+ [:r_paren, nil, 9, 3],
427
+ [:newline, nil, 10, 3],
428
+ [:newline, nil, 0, 4],
429
+ [:section, 'PLATFORMS', 0, 5],
430
+ [:newline, nil, 9, 5],
431
+ [:text, Gem::Platform::RUBY, 2, 6],
432
+ [:newline, nil, 6, 6],
433
+ [:newline, nil, 0, 7],
434
+ [:section, 'DEPENDENCIES', 0, 8],
435
+ [:newline, nil, 12, 8],
436
+ [:text, 'Ab', 2, 9],
437
+ [:newline, nil, 4, 9],
438
+ ]
439
+
440
+ assert_equal expected, @lockfile.tokenize
441
+ end
442
+
443
+ def test_tokenize_conflict_markers
444
+ write_lockfile '<<<<<<<'
445
+
446
+ e = assert_raises Gem::RequestSet::Lockfile::ParseError do
447
+ @lockfile.tokenize
448
+ end
449
+
450
+ assert_equal "your #{@lock_file} contains merge conflict markers (at line 0 column 0)",
451
+ e.message
452
+
453
+ write_lockfile '|||||||'
454
+
455
+ e = assert_raises Gem::RequestSet::Lockfile::ParseError do
456
+ @lockfile.tokenize
457
+ end
458
+
459
+ assert_equal "your #{@lock_file} contains merge conflict markers (at line 0 column 0)",
460
+ e.message
461
+
462
+ write_lockfile '======='
463
+
464
+ e = assert_raises Gem::RequestSet::Lockfile::ParseError do
465
+ @lockfile.tokenize
466
+ end
467
+
468
+ assert_equal "your #{@lock_file} contains merge conflict markers (at line 0 column 0)",
469
+ e.message
470
+
471
+ write_lockfile '>>>>>>>'
472
+
473
+ e = assert_raises Gem::RequestSet::Lockfile::ParseError do
474
+ @lockfile.tokenize
475
+ end
476
+
477
+ assert_equal "your #{@lock_file} contains merge conflict markers (at line 0 column 0)",
478
+ e.message
479
+ end
480
+
481
+ def test_tokenize_git
482
+ write_lockfile <<-LOCKFILE
483
+ DEPENDENCIES
484
+ a!
485
+ LOCKFILE
486
+
487
+ expected = [
488
+ [:section, 'DEPENDENCIES', 0, 0],
489
+ [:newline, nil, 12, 0],
490
+
491
+ [:text, 'a', 2, 1],
492
+ [:bang, nil, 3, 1],
493
+ [:newline, nil, 4, 1],
494
+ ]
495
+
496
+ assert_equal expected, @lockfile.tokenize
497
+ end
498
+
499
+ def test_tokenize_missing
500
+ tokens = @lockfile.tokenize
501
+
502
+ assert_empty tokens
503
+ end
504
+
505
+ def test_tokenize_multiple
506
+ write_lockfile <<-LOCKFILE
507
+ GEM
508
+ remote: #{@gem_repo}
509
+ specs:
510
+ a (2)
511
+ b (~> 3.0, >= 3.0.1)
512
+ LOCKFILE
513
+
514
+ expected = [
515
+ [:section, 'GEM', 0, 0],
516
+ [:newline, nil, 3, 0],
517
+
518
+ [:entry, 'remote', 2, 1],
519
+ [:text, @gem_repo, 10, 1],
520
+ [:newline, nil, 34, 1],
521
+
522
+ [:entry, 'specs', 2, 2],
523
+ [:newline, nil, 8, 2],
524
+
525
+ [:text, 'a', 4, 3],
526
+ [:l_paren, nil, 6, 3],
527
+ [:text, '2', 7, 3],
528
+ [:r_paren, nil, 8, 3],
529
+ [:newline, nil, 9, 3],
530
+
531
+ [:text, 'b', 6, 4],
532
+ [:l_paren, nil, 8, 4],
533
+ [:requirement, '~>', 9, 4],
534
+ [:text, '3.0', 12, 4],
535
+ [:comma, nil, 15, 4],
536
+ [:requirement, '>=', 17, 4],
537
+ [:text, '3.0.1', 20, 4],
538
+ [:r_paren, nil, 25, 4],
539
+ [:newline, nil, 26, 4],
540
+ ]
541
+
542
+ assert_equal expected, @lockfile.tokenize
543
+ end
544
+
545
+ def test_to_s_gem
546
+ spec_fetcher do |fetcher|
547
+ fetcher.spec 'a', 2
548
+ end
549
+
550
+ @set.gem 'a'
551
+
552
+ expected = <<-LOCKFILE
553
+ GEM
554
+ remote: #{@gem_repo}
555
+ specs:
556
+ a (2)
557
+
558
+ PLATFORMS
559
+ #{Gem::Platform::RUBY}
560
+
561
+ DEPENDENCIES
562
+ a
563
+ LOCKFILE
564
+
565
+ assert_equal expected, @lockfile.to_s
566
+ end
567
+
568
+ def test_to_s_gem_dependency
569
+ spec_fetcher do |fetcher|
570
+ fetcher.spec 'a', 2, 'c' => '>= 0', 'b' => '>= 0'
571
+ fetcher.spec 'b', 2
572
+ fetcher.spec 'c', 2
573
+ end
574
+
575
+ @set.gem 'a'
576
+
577
+ expected = <<-LOCKFILE
578
+ GEM
579
+ remote: #{@gem_repo}
580
+ specs:
581
+ a (2)
582
+ b
583
+ c
584
+ b (2)
585
+ c (2)
586
+
587
+ PLATFORMS
588
+ #{Gem::Platform::RUBY}
589
+
590
+ DEPENDENCIES
591
+ a
592
+ b
593
+ c
594
+ LOCKFILE
595
+
596
+ assert_equal expected, @lockfile.to_s
597
+ end
598
+
599
+ def test_to_s_gem_dependency_non_default
600
+ spec_fetcher do |fetcher|
601
+ fetcher.spec 'a', 2, 'b' => '>= 1'
602
+ fetcher.spec 'b', 2
603
+ end
604
+
605
+ @set.gem 'b'
606
+ @set.gem 'a'
607
+
608
+ expected = <<-LOCKFILE
609
+ GEM
610
+ remote: #{@gem_repo}
611
+ specs:
612
+ a (2)
613
+ b (>= 1)
614
+ b (2)
615
+
616
+ PLATFORMS
617
+ #{Gem::Platform::RUBY}
618
+
619
+ DEPENDENCIES
620
+ a
621
+ b
622
+ LOCKFILE
623
+
624
+ assert_equal expected, @lockfile.to_s
625
+ end
626
+
627
+ def test_to_s_gem_dependency_requirement
628
+ spec_fetcher do |fetcher|
629
+ fetcher.spec 'a', 2, 'b' => '>= 0'
630
+ fetcher.spec 'b', 2
631
+ end
632
+
633
+ @set.gem 'a', '>= 1'
634
+
635
+ expected = <<-LOCKFILE
636
+ GEM
637
+ remote: #{@gem_repo}
638
+ specs:
639
+ a (2)
640
+ b
641
+ b (2)
642
+
643
+ PLATFORMS
644
+ #{Gem::Platform::RUBY}
645
+
646
+ DEPENDENCIES
647
+ a (>= 1)
648
+ b
649
+ LOCKFILE
650
+
651
+ assert_equal expected, @lockfile.to_s
652
+ end
653
+
654
+ def test_to_s_gem_path
655
+ name, version, directory = vendor_gem
656
+
657
+ @vendor_set.add_vendor_gem name, directory
658
+
659
+ @set.gem 'a'
660
+
661
+ expected = <<-LOCKFILE
662
+ PATH
663
+ remote: #{directory}
664
+ specs:
665
+ #{name} (#{version})
666
+
667
+ PLATFORMS
668
+ #{Gem::Platform::RUBY}
669
+
670
+ DEPENDENCIES
671
+ a!
672
+ LOCKFILE
673
+
674
+ assert_equal expected, @lockfile.to_s
675
+ end
676
+
677
+ def test_to_s_gem_path_absolute
678
+ name, version, directory = vendor_gem
679
+
680
+ @vendor_set.add_vendor_gem name, File.expand_path(directory)
681
+
682
+ @set.gem 'a'
683
+
684
+ expected = <<-LOCKFILE
685
+ PATH
686
+ remote: #{directory}
687
+ specs:
688
+ #{name} (#{version})
689
+
690
+ PLATFORMS
691
+ #{Gem::Platform::RUBY}
692
+
693
+ DEPENDENCIES
694
+ a!
695
+ LOCKFILE
696
+
697
+ assert_equal expected, @lockfile.to_s
698
+ end
699
+
700
+ def test_to_s_gem_platform
701
+ spec_fetcher do |fetcher|
702
+ fetcher.spec 'a', 2 do |spec|
703
+ spec.platform = Gem::Platform.local
704
+ end
705
+ end
706
+
707
+ @set.gem 'a'
708
+
709
+ expected = <<-LOCKFILE
710
+ GEM
711
+ remote: #{@gem_repo}
712
+ specs:
713
+ a (2-#{Gem::Platform.local})
714
+
715
+ PLATFORMS
716
+ #{Gem::Platform.local}
717
+
718
+ DEPENDENCIES
719
+ a
720
+ LOCKFILE
721
+
722
+ assert_equal expected, @lockfile.to_s
723
+ end
724
+
725
+ def test_to_s_gem_source
726
+ spec_fetcher do |fetcher|
727
+ fetcher.spec 'a', 2
728
+ fetcher.clear
729
+ end
730
+
731
+ spec_fetcher 'http://other.example/' do |fetcher|
732
+ fetcher.spec 'b', 2
733
+ fetcher.clear
734
+ end
735
+
736
+ Gem.sources << 'http://other.example/'
737
+
738
+ @set.gem 'a'
739
+ @set.gem 'b'
740
+
741
+ expected = <<-LOCKFILE
742
+ GEM
743
+ remote: #{@gem_repo}
744
+ specs:
745
+ a (2)
746
+
747
+ GEM
748
+ remote: http://other.example/
749
+ specs:
750
+ b (2)
751
+
752
+ PLATFORMS
753
+ #{Gem::Platform::RUBY}
754
+
755
+ DEPENDENCIES
756
+ a
757
+ b
758
+ LOCKFILE
759
+
760
+ assert_equal expected, @lockfile.to_s
761
+ end
762
+
763
+ def test_to_s_git
764
+ _, _, repository, = git_gem
765
+
766
+ head = nil
767
+
768
+ Dir.chdir repository do
769
+ FileUtils.mkdir 'b'
770
+
771
+ Dir.chdir 'b' do
772
+ b = Gem::Specification.new 'b', 1 do |s|
773
+ s.add_dependency 'a', '~> 1.0'
774
+ s.add_dependency 'c', '~> 1.0'
775
+ end
776
+
777
+ open 'b.gemspec', 'w' do |io|
778
+ io.write b.to_ruby
779
+ end
780
+
781
+ system @git, 'add', 'b.gemspec'
782
+ system @git, 'commit', '--quiet', '-m', 'add b/b.gemspec'
783
+ end
784
+
785
+ FileUtils.mkdir 'c'
786
+
787
+ Dir.chdir 'c' do
788
+ c = Gem::Specification.new 'c', 1
789
+
790
+ open 'c.gemspec', 'w' do |io|
791
+ io.write c.to_ruby
792
+ end
793
+
794
+ system @git, 'add', 'c.gemspec'
795
+ system @git, 'commit', '--quiet', '-m', 'add c/c.gemspec'
796
+ end
797
+
798
+ head = `#{@git} rev-parse HEAD`.strip
799
+ end
800
+
801
+ @git_set.add_git_gem 'a', repository, 'HEAD', true
802
+ @git_set.add_git_gem 'b', repository, 'HEAD', true
803
+ @git_set.add_git_gem 'c', repository, 'HEAD', true
804
+
805
+ @set.gem 'b'
806
+
807
+ expected = <<-LOCKFILE
808
+ GIT
809
+ remote: #{repository}
810
+ revision: #{head}
811
+ specs:
812
+ a (1)
813
+ b (1)
814
+ a (~> 1.0)
815
+ c (~> 1.0)
816
+ c (1)
817
+
818
+ PLATFORMS
819
+ ruby
820
+
821
+ DEPENDENCIES
822
+ a!
823
+ b!
824
+ c!
825
+ LOCKFILE
826
+
827
+ assert_equal expected, @lockfile.to_s
828
+ end
829
+
830
+ def test_unget
831
+ @lockfile.instance_variable_set :@current_token, :token
832
+
833
+ @lockfile.unget
834
+
835
+ assert_equal :token, @lockfile.get
836
+ end
837
+
838
+ def test_write
839
+ @lockfile.write
840
+
841
+ gem_deps_lock_file = "#{@gem_deps_file}.lock"
842
+
843
+ assert_path_exists gem_deps_lock_file
844
+
845
+ refute_empty File.read gem_deps_lock_file
846
+ end
847
+
848
+ end
849
+