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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
#!/usr/bin/env ruby
# vim: set sw=4 sts=4 et tw=80 :
#
# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011 Ciaran McCreesh
# Copyright (c) 2007 Richard Brown
#
# This file is part of the Paludis package manager. Paludis is free software;
# you can redistribute it and/or modify it under the terms of the GNU General
# Public License version 2, as published by the Free Software Foundation.
#
# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
require 'test/unit'
require 'Paludis'
ENV['PALUDIS_HOME'] = Dir.getwd() + '/dep_spec_TEST_dir/home'
module Paludis
class TestCase_DepSpec < Test::Unit::TestCase
def test_create_error
assert_raise NoMethodError do
v = DepSpec.new
end
assert_raise NoMethodError do
v = StringDepSpec.new
end
assert_raise NoMethodError do
v = AnyDepSpec.new
end
assert_raise NoMethodError do
v = AllDepSpec.new
end
end
end
class TestCase_PackageDepSpec < Test::Unit::TestCase
def env
@env or @env = EnvironmentFactory.instance.create("")
end
def pda
Paludis::parse_user_package_dep_spec('>=foo/bar-1:100::testrepo[a][-b]', env, [])
end
def pdb
Paludis::parse_user_package_dep_spec('*/bar', env, [:allow_wildcards])
end
def pdc
Paludis::parse_user_package_dep_spec('foo/bar::installed?', env, [])
end
def pdd
Paludis::parse_user_package_dep_spec('foo/*::/??', env, [:allow_wildcards])
end
def pde
Paludis::parse_user_package_dep_spec('foo/bar::testrepo->/mychroot', env, [])
end
def test_create
pda
pdb
pdc
pdd
pde
end
def test_create_error
assert_raise NoMethodError do
v = PackageDepSpec.new("foo")
end
assert_raise PackageDepSpecError do
Paludis::parse_user_package_dep_spec("=sys-apps/foo", env, [])
end
assert_raise TypeError do
Paludis::parse_user_package_dep_spec("sys-apps/foo", env, {})
end
assert_raise TypeError do
Paludis::parse_user_package_dep_spec("sys-apps/foo", env, ["foo"])
end
assert_raise ArgumentError do
Paludis::parse_user_package_dep_spec("sys-apps/foo", env, [:unknown])
end
assert_raise TypeError do
Paludis::parse_user_package_dep_spec("sys-apps/foo", env, [], "foo")
end
assert_raise ArgumentError do
Paludis::parse_user_package_dep_spec("sys-apps/foo")
end
end
def test_to_s
assert_equal ">=foo/bar-1:100::testrepo[-b][a]", pda.to_s
assert_equal "*/bar", pdb.to_s
assert_equal "foo/bar::installed?", pdc.to_s
assert_equal "foo/*::/??", pdd.to_s
assert_equal "foo/bar::testrepo->/mychroot", pde.to_s
end
def test_text
assert_equal ">=foo/bar-1:100::testrepo[-b][a]", pda.text
assert_equal "*/bar", pdb.text
assert_equal "foo/bar::installed?", pdc.text
assert_equal "foo/*::/??", pdd.text
assert_equal "foo/bar::testrepo->/mychroot", pde.text
end
def test_disambiguate
assert_equal Paludis::parse_user_package_dep_spec("foo", env, []).to_s, "bar/foo"
assert_raise NoSuchPackageError do
Paludis::parse_user_package_dep_spec("foo", env, [], Filter::SupportsAction.new(ConfigAction))
end
assert_raise AmbiguousPackageNameError do
Paludis::parse_user_package_dep_spec("bar", env, [])
end
assert_raise AmbiguousPackageNameError do
Paludis::parse_user_package_dep_spec("bar", env, [], Filter::All.new())
end
assert_equal Paludis::parse_user_package_dep_spec("bar", env, [],
Filter::SupportsAction.new(InstallAction)).to_s, "foo/bar"
end
def test_slot
assert_kind_of SlotExactPartialRequirement, pda.slot_requirement
assert_equal ":100", pda.slot_requirement.to_s
assert_equal "100", pda.slot_requirement.slot
assert_nil pdb.slot_requirement
assert_nil pdc.slot_requirement
assert_nil pdd.slot_requirement
assert_nil pde.slot_requirement
end
def test_package
assert_equal QualifiedPackageName.new("foo/bar"), pda.package
assert_nil pdb.package
assert_equal QualifiedPackageName.new("foo/bar"), pdc.package
assert_nil pdd.package
assert_equal QualifiedPackageName.new("foo/bar"), pde.package
end
def test_from_repository
assert_nil pda.from_repository
assert_nil pdb.from_repository
assert_nil pdc.from_repository
assert_nil pdd.from_repository
assert_equal "testrepo", pde.from_repository
end
def test_in_repository
assert_equal "testrepo", pda.in_repository
assert_nil pdb.in_repository
assert_nil pdc.in_repository
assert_nil pdd.in_repository
assert_nil pde.in_repository
end
def test_installable_to_repository
assert_nil pda.installable_to_repository
assert_nil pdb.installable_to_repository
assert_kind_of Hash, pdc.installable_to_repository
assert_equal "installed", pdc.installable_to_repository[:repository]
assert ! pdc.installable_to_repository[:include_masked?]
assert_nil pdd.installable_to_repository
assert_nil pde.installable_to_repository
end
def test_installed_at_path
assert_nil pda.installed_at_path
assert_nil pdb.installed_at_path
assert_nil pdc.installed_at_path
assert_nil pdd.installed_at_path
assert_equal "/mychroot", pde.installed_at_path
end
def test_installable_to_path
assert_nil pda.installable_to_path
assert_nil pdb.installable_to_path
assert_nil pdc.installable_to_path
assert_kind_of Hash, pdd.installable_to_path
assert_equal "/", pdd.installable_to_path[:path]
assert pdd.installable_to_path[:include_masked?]
assert_nil pde.installable_to_path
end
def test_package_name_part
assert_nil pda.package_name_part
assert_equal "bar", pdb.package_name_part
assert_nil pdc.package_name_part
assert_nil pdd.package_name_part
assert_nil pde.package_name_part
end
def test_category_name_part
assert_nil pda.category_name_part
assert_nil pdb.category_name_part
assert_nil pdc.category_name_part
assert_equal "foo", pdd.category_name_part
assert_nil pde.category_name_part
end
def test_version_requirements
assert_kind_of Array, pda.version_requirements
assert_equal 1, pda.version_requirements.size
assert_equal VersionSpec.new('1'), pda.version_requirements.first[:spec]
assert_equal ">=", pda.version_requirements.first[:operator]
assert_equal 0, pdb.version_requirements.size
assert_equal 0, pdc.version_requirements.size
assert_equal 0, pdd.version_requirements.size
assert_equal 0, pde.version_requirements.size
end
def test_version_requirements_mode
assert_kind_of Fixnum, pda.version_requirements_mode
assert_equal VersionRequirementsMode::And, pda.version_requirements_mode
end
### def test_use_requirements
### assert_kind_of Array, pda.use_requirements
### assert_equal 2, pda.use_requirements.size
###
### assert_equal 'a', pda.use_requirements[0][:flag]
### assert_equal true, pda.use_requirements[0][:state]
###
### assert_equal 'b', pda.use_requirements[1][:flag]
### assert_equal false, pda.use_requirements[1][:state]
### end
end
class TestCase_PlainTextDepSpec < Test::Unit::TestCase
def test_create
v = PlainTextDepSpec.new("monkey")
end
def test_create_error
assert_raise TypeError do
v = PlainTextDepSpec.new(0)
end
end
def test_to_s
assert_equal "monkey", PlainTextDepSpec.new("monkey").to_s
end
end
class TestCase_BlockDepSpec < Test::Unit::TestCase
def env
@env or @env = EnvironmentFactory.instance.create("")
end
def test_create
v = BlockDepSpec.new("!>=foo/bar-1", Paludis::parse_user_package_dep_spec(">=foo/bar-1", env, []))
end
def test_create_error
assert_raise TypeError do
v = BlockDepSpec.new("!>=foo/bar-1", 0)
end
assert_raise TypeError do
v = BlockDepSpec.new("!>=foo/bar-1", PlainTextDepSpec.new('foo-bar/baz'))
end
end
def test_blocked_spec
assert_equal "foo/baz", BlockDepSpec.new("!foo/baz", Paludis::parse_user_package_dep_spec(
"foo/baz", env, [])).blocking.to_s
end
end
class TestCase_Composites < Test::Unit::TestCase
def env
@env or @env = EnvironmentFactory.instance.create("")
end
def test_composites
spec = env[Selection::RequireExactlyOne.new(Generator::Package.new("foo/bar"))].last.build_dependencies_key.parse_value
assert_kind_of AllDepSpec, spec
assert_equal 2, spec.to_a.length
spec.each_with_index do | a, i |
case i
when 0
assert_kind_of AnyDepSpec, a
assert_equal 2, a.to_a.length
a.each_with_index do | b, j |
case j
when 0
assert_kind_of PackageDepSpec, b
assert_equal "foo/bar", b.to_s
when 1
assert_kind_of PackageDepSpec, b
assert_equal "foo/baz", b.to_s
else
throw "Too many items"
end
end
when 1
assert_kind_of PackageDepSpec, a
assert_equal "foo/monkey", a.to_s
else
throw "Too many items"
end
end
end
end
class TestCase_URILabels < Test::Unit::TestCase
def env
@env or @env = EnvironmentFactory.instance.create("")
end
def spec_key
env[Selection::RequireExactlyOne.new(Generator::Package.new("bar/foo"))].last.fetches_key
end
def test_no_create
assert_raise NoMethodError do URILabel.new end
[URILabel, URIMirrorsThenListedLabel, URIMirrorsOnlyLabel,
URIListedOnlyLabel, URIListedThenMirrorsLabel,
URILocalMirrorsOnlyLabel, URIManualOnlyLabel].each do | c |
assert_raise NoMethodError do c.new end
end
end
def test_initial_label
assert_kind_of URIListedThenMirrorsLabel, spec_key.initial_label
assert_equal "default", spec_key.initial_label.text
assert_equal "default", spec_key.initial_label.to_s
end
def test_uri_labels_dep_spec
specs = spec_key.parse_value.to_a
assert_equal 6, specs.length
specs.each do | spec |
assert_kind_of URILabelsDepSpec, spec
assert_kind_of Array, spec.labels
array_from_block = []
spec.labels { | label | array_from_block << label }
[spec.labels, array_from_block].each do | array |
assert_equal 1, array.length
assert_kind_of URILabel, array[0]
assert_equal array[0].text, array[0].to_s
end
assert_equal spec.labels[0].class, array_from_block[0].class
assert_equal spec.labels[0].text, array_from_block[0].text
end
assert_kind_of URIMirrorsThenListedLabel, specs.to_a[0].labels[0]
assert_kind_of URIMirrorsOnlyLabel, specs.to_a[1].labels[0]
assert_kind_of URIListedOnlyLabel, specs.to_a[2].labels[0]
assert_kind_of URIListedThenMirrorsLabel, specs.to_a[3].labels[0]
assert_kind_of URILocalMirrorsOnlyLabel, specs.to_a[4].labels[0]
assert_kind_of URIManualOnlyLabel, specs.to_a[5].labels[0]
assert_equal "mirrors-first", specs.to_a[0].labels[0].text
assert_equal "mirrors-only", specs.to_a[1].labels[0].text
assert_equal "listed-only", specs.to_a[2].labels[0].text
assert_equal "listed-first", specs.to_a[3].labels[0].text
assert_equal "local-only", specs.to_a[4].labels[0].text
assert_equal "manual", specs.to_a[5].labels[0].text
end
end
class TestCase_DependencyLabels < Test::Unit::TestCase
def env
@env or @env = EnvironmentFactory.instance.create("")
end
def spec_key
env[Selection::RequireExactlyOne.new(Generator::Package.new("bar/foo"))].last.dependencies_key
end
def test_initial_labels
assert_kind_of Array, spec_key.initial_labels
assert_kind_of DependenciesBuildLabel, spec_key.initial_labels[0]
assert_equal "build", spec_key.initial_labels[0].text
assert_equal "build", spec_key.initial_labels[0].to_s
end
end
end
|