~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/rake/test_filelist.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require 'test/unit'
2
 
require 'tmpdir'
3
 
require 'rake'
4
 
 
5
 
require_relative 'capture_stdout'
6
 
 
7
 
class Rake::TestFileList < Test::Unit::TestCase
8
 
  FileList = Rake::FileList
9
 
  include CaptureStdout
10
 
 
11
 
  def setup
12
 
    @oldwd = Dir.pwd
13
 
    @tmpwd = Dir.mktmpdir
14
 
    Dir.chdir(@tmpwd)
15
 
    create_test_data
16
 
  end
17
 
 
18
 
  def teardown
19
 
#    FileList.select_default_ignore_patterns
20
 
    FileUtils.rm_rf("testdata")
21
 
    Dir.chdir(@oldwd)
22
 
    FileUtils.rm_rf(@tmpwd)
23
 
  end
24
 
 
25
 
  def test_delgating_methods_do_not_include_to_a_or_to_ary
26
 
    assert ! FileList::DELEGATING_METHODS.include?("to_a"), "should not include to_a"
27
 
    assert ! FileList::DELEGATING_METHODS.include?(:to_a), "should not include to_a"
28
 
    assert ! FileList::DELEGATING_METHODS.include?("to_ary"), "should not include to_ary"
29
 
    assert ! FileList::DELEGATING_METHODS.include?(:to_ary), "should not include to_ary"
30
 
  end
31
 
 
32
 
  def test_create
33
 
    fl = FileList.new
34
 
    assert_equal 0, fl.size
35
 
  end
36
 
 
37
 
  def test_create_with_args
38
 
    fl = FileList.new("testdata/*.c", "x")
39
 
    assert_equal ["testdata/abc.c", "testdata/x.c", "testdata/xyz.c", "x"].sort,
40
 
      fl.sort
41
 
  end
42
 
 
43
 
  def test_create_with_block
44
 
    fl = FileList.new { |f| f.include("x") }
45
 
    assert_equal ["x"], fl.resolve
46
 
  end
47
 
 
48
 
  def test_create_with_brackets
49
 
    fl = FileList["testdata/*.c", "x"]
50
 
    assert_equal ["testdata/abc.c", "testdata/x.c", "testdata/xyz.c", "x"].sort,
51
 
      fl.sort
52
 
  end
53
 
 
54
 
  def test_create_with_brackets_and_filelist
55
 
    fl = FileList[FileList["testdata/*.c", "x"]]
56
 
    assert_equal ["testdata/abc.c", "testdata/x.c", "testdata/xyz.c", "x"].sort,
57
 
      fl.sort
58
 
  end
59
 
 
60
 
  def test_include_with_another_array
61
 
    fl = FileList.new.include(["x", "y", "z"])
62
 
    assert_equal ["x", "y", "z"].sort, fl.sort
63
 
  end
64
 
 
65
 
  def test_include_with_another_filelist
66
 
    fl = FileList.new.include(FileList["testdata/*.c", "x"])
67
 
    assert_equal ["testdata/abc.c", "testdata/x.c", "testdata/xyz.c", "x"].sort,
68
 
      fl.sort
69
 
  end
70
 
 
71
 
  def test_append
72
 
    fl = FileList.new
73
 
    fl << "a.rb" << "b.rb"
74
 
    assert_equal ['a.rb', 'b.rb'], fl
75
 
  end
76
 
 
77
 
  def test_add_many
78
 
    fl = FileList.new
79
 
    fl.include %w(a d c)
80
 
    fl.include('x', 'y')
81
 
    assert_equal ['a', 'd', 'c', 'x', 'y'], fl
82
 
    assert_equal ['a', 'd', 'c', 'x', 'y'], fl.resolve
83
 
  end
84
 
 
85
 
  def test_add_return
86
 
    f = FileList.new
87
 
    g = f << "x"
88
 
    assert_equal f.object_id, g.object_id
89
 
    h = f.include("y")
90
 
    assert_equal f.object_id, h.object_id
91
 
  end
92
 
  
93
 
  def test_match
94
 
    fl = FileList.new
95
 
    fl.include(File.expand_path('../test*.rb', __FILE__))
96
 
    assert fl.include?(__FILE__)
97
 
    assert fl.size > 3
98
 
    fl.each { |fn| assert_match(/\.rb$/, fn) }
99
 
  end
100
 
 
101
 
  def test_add_matching
102
 
    fl = FileList.new
103
 
    fl << "a.java"
104
 
    fl.include(File.dirname(__FILE__)+"/*.rb")
105
 
    assert_equal "a.java", fl[0]
106
 
    assert fl.size > 2
107
 
    assert fl.include?(__FILE__)
108
 
  end
109
 
 
110
 
  def test_multiple_patterns
111
 
    create_test_data
112
 
    fl = FileList.new
113
 
    fl.include('*.c', '*xist*')
114
 
    assert_equal [], fl
115
 
    fl.include('testdata/*.c', 'testdata/*xist*')
116
 
    assert_equal [
117
 
      'testdata/x.c', 'testdata/xyz.c', 'testdata/abc.c', 'testdata/existing'
118
 
    ].sort, fl.sort
119
 
  end
120
 
 
121
 
  def test_square_bracket_pattern
122
 
    fl = FileList.new
123
 
    fl.include("testdata/abc.[ch]")
124
 
    assert fl.size == 2
125
 
    assert fl.include?("testdata/abc.c")
126
 
    assert fl.include?("testdata/abc.h")
127
 
  end
128
 
 
129
 
  def test_curly_bracket_pattern
130
 
    fl = FileList.new
131
 
    fl.include("testdata/abc.{c,h}")
132
 
    assert fl.size == 2
133
 
    assert fl.include?("testdata/abc.c")
134
 
    assert fl.include?("testdata/abc.h")
135
 
  end
136
 
 
137
 
  def test_reject
138
 
    fl = FileList.new
139
 
    fl.include %w(testdata/x.c testdata/abc.c testdata/xyz.c testdata/existing)
140
 
    fl.reject! { |fn| fn =~ %r{/x} }
141
 
    assert_equal [
142
 
      'testdata/abc.c', 'testdata/existing'
143
 
    ], fl
144
 
  end
145
 
 
146
 
  def test_exclude
147
 
    fl = FileList['testdata/x.c', 'testdata/abc.c', 'testdata/xyz.c', 'testdata/existing']
148
 
    fl.each { |fn| touch fn, :verbose => false }
149
 
    x = fl.exclude(%r{/x.+\.})
150
 
    assert_equal FileList, x.class
151
 
    assert_equal %w(testdata/x.c testdata/abc.c testdata/existing), fl
152
 
    assert_equal fl.object_id, x.object_id
153
 
    fl.exclude('testdata/*.c')
154
 
    assert_equal ['testdata/existing'], fl
155
 
    fl.exclude('testdata/existing')
156
 
    assert_equal [], fl
157
 
  end
158
 
  
159
 
  def test_excluding_via_block
160
 
    fl = FileList['testdata/a.c', 'testdata/b.c', 'testdata/xyz.c']
161
 
    fl.exclude { |fn| fn.pathmap('%n') == 'xyz' }
162
 
    assert fl.exclude?("xyz.c"), "Should exclude xyz.c"
163
 
    assert_equal ['testdata/a.c', 'testdata/b.c'], fl
164
 
  end
165
 
 
166
 
  def test_exclude_return_on_create
167
 
    fl = FileList['testdata/*'].exclude(/.*\.[hcx]$/)
168
 
    assert_equal ['testdata/existing', 'testdata/cfiles'].sort, fl.sort
169
 
    assert_equal FileList, fl.class
170
 
  end
171
 
 
172
 
  def test_exclude_with_string_return_on_create
173
 
    fl = FileList['testdata/*'].exclude('testdata/abc.c')
174
 
    assert_equal %w(testdata/existing testdata/cfiles testdata/x.c testdata/abc.h testdata/abc.x testdata/xyz.c).sort, fl.sort
175
 
    assert_equal FileList, fl.class
176
 
  end
177
 
 
178
 
  def test_default_exclude
179
 
    fl = FileList.new
180
 
    fl.clear_exclude
181
 
    fl.include("**/*~", "**/*.bak", "**/core")
182
 
    assert fl.member?("testdata/core"), "Should include core"
183
 
    assert fl.member?("testdata/x.bak"), "Should include .bak files"
184
 
  end
185
 
 
186
 
  def test_unique
187
 
    fl = FileList.new
188
 
    fl << "x.c" << "a.c" << "b.rb" << "a.c"
189
 
    assert_equal ['x.c', 'a.c', 'b.rb', 'a.c'], fl
190
 
    fl.uniq!
191
 
    assert_equal ['x.c', 'a.c', 'b.rb'], fl
192
 
  end
193
 
 
194
 
  def test_to_string
195
 
    fl = FileList.new
196
 
    fl << "a.java" << "b.java"
197
 
    assert_equal  "a.java b.java", fl.to_s
198
 
    assert_equal  "a.java b.java", "#{fl}"
199
 
  end
200
 
 
201
 
  def test_to_array
202
 
    fl = FileList['a.java', 'b.java']
203
 
    assert_equal  ['a.java', 'b.java'], fl.to_a
204
 
    assert_equal  Array, fl.to_a.class
205
 
    assert_equal  ['a.java', 'b.java'], fl.to_ary
206
 
    assert_equal  Array, fl.to_ary.class
207
 
  end
208
 
 
209
 
  def test_to_s_pending
210
 
    fl = FileList['testdata/abc.*']
211
 
    result = fl.to_s
212
 
    assert_match(%r{testdata/abc\.c}, result)
213
 
    assert_match(%r{testdata/abc\.h}, result)
214
 
    assert_match(%r{testdata/abc\.x}, result)
215
 
    assert_match(%r{(testdata/abc\..\b ?){2}}, result)
216
 
  end
217
 
 
218
 
  def test_inspect_pending
219
 
    fl = FileList['testdata/abc.*']
220
 
    result = fl.inspect
221
 
    assert_match(%r{"testdata/abc\.c"}, result)
222
 
    assert_match(%r{"testdata/abc\.h"}, result)
223
 
    assert_match(%r{"testdata/abc\.x"}, result)
224
 
    assert_match(%r|^\[("testdata/abc\..", ){2}"testdata/abc\.."\]$|, result)
225
 
  end
226
 
 
227
 
  def test_sub
228
 
    fl = FileList["testdata/*.c"]
229
 
    f2 = fl.sub(/\.c$/, ".o")
230
 
    assert_equal FileList, f2.class
231
 
    assert_equal ["testdata/abc.o", "testdata/x.o", "testdata/xyz.o"].sort,
232
 
      f2.sort
233
 
    f3 = fl.gsub(/\.c$/, ".o")
234
 
    assert_equal FileList, f3.class
235
 
    assert_equal ["testdata/abc.o", "testdata/x.o", "testdata/xyz.o"].sort,
236
 
      f3.sort
237
 
  end
238
 
  
239
 
  def test_claim_to_be_a_kind_of_array
240
 
    fl = FileList['testdata/*.c']
241
 
    assert fl.is_a?(Array)
242
 
    assert fl.kind_of?(Array)
243
 
  end
244
 
  
245
 
  def test_claim_to_be_a_kind_of_filelist
246
 
    fl = FileList['testdata/*.c']
247
 
    assert fl.is_a?(FileList)
248
 
    assert fl.kind_of?(FileList)
249
 
  end
250
 
  
251
 
  def test_claim_to_be_a_filelist_instance
252
 
    fl = FileList['testdata/*.c']
253
 
    assert fl.instance_of?(FileList)
254
 
  end
255
 
  
256
 
  def test_dont_claim_to_be_an_array_instance
257
 
    fl = FileList['testdata/*.c']
258
 
    assert ! fl.instance_of?(Array)
259
 
  end
260
 
 
261
 
  def test_sub!
262
 
    f = "x/a.c"
263
 
    fl = FileList[f, "x/b.c"]
264
 
    res = fl.sub!(/\.c$/, ".o")
265
 
    assert_equal ["x/a.o", "x/b.o"].sort, fl.sort
266
 
    assert_equal "x/a.c", f
267
 
    assert_equal fl.object_id, res.object_id
268
 
  end
269
 
 
270
 
  def test_sub_with_block
271
 
    fl = FileList["src/org/onestepback/a.java", "src/org/onestepback/b.java"]
272
 
# The block version doesn't work the way I want it to ...
273
 
#    f2 = fl.sub(%r{^src/(.*)\.java$}) { |x|  "classes/" + $1 + ".class" }
274
 
    f2 = fl.sub(%r{^src/(.*)\.java$}, "classes/\\1.class")
275
 
    assert_equal [
276
 
      "classes/org/onestepback/a.class",
277
 
      "classes/org/onestepback/b.class"
278
 
    ].sort,
279
 
      f2.sort
280
 
  end
281
 
 
282
 
  def test_string_ext
283
 
    assert_equal "one.net", "one.two".ext("net")
284
 
    assert_equal "one.net", "one.two".ext(".net")
285
 
    assert_equal "one.net", "one".ext("net")
286
 
    assert_equal "one.net", "one".ext(".net")
287
 
    assert_equal "one.two.net", "one.two.c".ext(".net")
288
 
    assert_equal "one/two.net", "one/two.c".ext(".net")
289
 
    assert_equal "one.x/two.net", "one.x/two.c".ext(".net")
290
 
    assert_equal "one.x/two.net", "one.x/two".ext(".net")
291
 
    assert_equal ".onerc.net", ".onerc.dot".ext("net")
292
 
    assert_equal ".onerc.net", ".onerc".ext("net")
293
 
    assert_equal ".a/.onerc.net", ".a/.onerc".ext("net")
294
 
    assert_equal "one", "one.two".ext('')
295
 
    assert_equal "one", "one.two".ext
296
 
    assert_equal ".one", ".one.two".ext
297
 
    assert_equal ".one", ".one".ext
298
 
    assert_equal ".", ".".ext("c")
299
 
    assert_equal "..", "..".ext("c")
300
 
    # These only need to work in windows
301
 
    if Rake::Win32.windows?
302
 
      assert_equal "one.x\\two.net", "one.x\\two.c".ext(".net")
303
 
      assert_equal "one.x\\two.net", "one.x\\two".ext(".net")
304
 
    end
305
 
  end
306
 
 
307
 
  def test_filelist_ext
308
 
    assert_equal FileList['one.c', '.one.c'],
309
 
      FileList['one.net', '.one'].ext('c')
310
 
  end
311
 
 
312
 
  def test_gsub
313
 
    create_test_data
314
 
    fl = FileList["testdata/*.c"]
315
 
    f2 = fl.gsub(/a/, "A")
316
 
    assert_equal ["testdAtA/Abc.c", "testdAtA/x.c", "testdAtA/xyz.c"].sort,
317
 
      f2.sort
318
 
  end
319
 
 
320
 
  def test_gsub!
321
 
    create_test_data
322
 
    f = FileList["testdata/*.c"]
323
 
    f.gsub!(/a/, "A")
324
 
    assert_equal ["testdAtA/Abc.c", "testdAtA/x.c", "testdAtA/xyz.c"].sort,
325
 
      f.sort
326
 
  end
327
 
 
328
 
  def test_egrep_with_output
329
 
    files = FileList[File.expand_path('../test*.rb', __FILE__)]
330
 
    the_line_number = __LINE__ + 1
331
 
    out = capture_stdout do files.egrep(/PUGH/) end
332
 
    assert_match(/:#{the_line_number}:/, out)
333
 
  end
334
 
 
335
 
  def test_egrep_with_block
336
 
    files = FileList[File.expand_path('../test*.rb', __FILE__)]
337
 
    found = false
338
 
    the_line_number = __LINE__ + 1
339
 
    files.egrep(/XYZZY/) do |fn, ln, line |
340
 
      assert_equal __FILE__, fn
341
 
      assert_equal the_line_number, ln
342
 
      assert_match(/files\.egrep/, line)
343
 
      found = true
344
 
    end
345
 
    assert found, "should have found a matching line"
346
 
  end
347
 
 
348
 
  def test_existing
349
 
    fl = FileList['testdata/abc.c', 'testdata/notthere.c']
350
 
    assert_equal ["testdata/abc.c"], fl.existing
351
 
    assert fl.existing.is_a?(FileList)
352
 
  end
353
 
 
354
 
  def test_existing!
355
 
    fl = FileList['testdata/abc.c', 'testdata/notthere.c']
356
 
    result = fl.existing!
357
 
    assert_equal ["testdata/abc.c"], fl
358
 
    assert_equal fl.object_id, result.object_id
359
 
  end
360
 
 
361
 
  def test_ignore_special
362
 
    f = FileList['testdata/*']
363
 
    assert ! f.include?("testdata/CVS"), "Should not contain CVS"
364
 
    assert ! f.include?("testdata/.svn"), "Should not contain .svn"
365
 
    assert ! f.include?("testdata/.dummy"), "Should not contain dot files"
366
 
    assert ! f.include?("testdata/x.bak"), "Should not contain .bak files"
367
 
    assert ! f.include?("testdata/x~"), "Should not contain ~ files"
368
 
    assert ! f.include?("testdata/core"), "Should not contain core files"
369
 
  end
370
 
 
371
 
  def test_clear_ignore_patterns
372
 
    f = FileList['testdata/*', 'testdata/.svn']
373
 
    f.clear_exclude
374
 
    assert f.include?("testdata/abc.c")
375
 
    assert f.include?("testdata/xyz.c")
376
 
    assert f.include?("testdata/CVS")
377
 
    assert f.include?("testdata/.svn")
378
 
    assert f.include?("testdata/x.bak")
379
 
    assert f.include?("testdata/x~")
380
 
  end
381
 
 
382
 
  def test_exclude_with_alternate_file_seps
383
 
    fl = FileList.new
384
 
    assert fl.exclude?("x/CVS/y")
385
 
    assert fl.exclude?("x\\CVS\\y")
386
 
    assert fl.exclude?("x/.svn/y")
387
 
    assert fl.exclude?("x\\.svn\\y")
388
 
    assert fl.exclude?("x/core")
389
 
    assert fl.exclude?("x\\core")
390
 
  end
391
 
 
392
 
  def test_add_default_exclude_list
393
 
    fl = FileList.new
394
 
    fl.exclude(/~\d+$/)
395
 
    assert fl.exclude?("x/CVS/y")
396
 
    assert fl.exclude?("x\\CVS\\y")
397
 
    assert fl.exclude?("x/.svn/y")
398
 
    assert fl.exclude?("x\\.svn\\y")
399
 
    assert fl.exclude?("x/core")
400
 
    assert fl.exclude?("x\\core")
401
 
    assert fl.exclude?("x/abc~1")
402
 
  end
403
 
 
404
 
  def test_basic_array_functions
405
 
    f = FileList['b', 'c', 'a']
406
 
    assert_equal 'b', f.first
407
 
    assert_equal 'b', f[0]
408
 
    assert_equal 'a', f.last
409
 
    assert_equal 'a', f[2]
410
 
    assert_equal 'a', f[-1]
411
 
    assert_equal ['a', 'b', 'c'], f.sort
412
 
    f.sort!
413
 
    assert_equal ['a', 'b', 'c'], f
414
 
  end
415
 
 
416
 
  def test_flatten
417
 
    assert_equal ['a', 'testdata/x.c', 'testdata/xyz.c', 'testdata/abc.c'].sort,
418
 
      ['a', FileList['testdata/*.c']].flatten.sort
419
 
  end
420
 
 
421
 
  def test_clone_and_dup
422
 
    a = FileList['a', 'b', 'c']
423
 
    c = a.clone
424
 
    d = a.dup
425
 
    a << 'd'
426
 
    assert_equal ['a', 'b', 'c', 'd'], a
427
 
    assert_equal ['a', 'b', 'c'], c
428
 
    assert_equal ['a', 'b', 'c'], d
429
 
  end
430
 
 
431
 
  def test_dup_and_clone_replicate_taint
432
 
    a = FileList['a', 'b', 'c']
433
 
    a.taint
434
 
    c = a.clone
435
 
    d = a.dup
436
 
    assert c.tainted?, "Clone should be tainted"
437
 
    assert d.tainted?, "Dup should be tainted"
438
 
  end
439
 
 
440
 
  def test_duped_items_will_thaw
441
 
    a = FileList['a', 'b', 'c']
442
 
    a.freeze
443
 
    d = a.dup
444
 
    d << 'more'
445
 
    assert_equal ['a', 'b', 'c', 'more'], d
446
 
  end
447
 
 
448
 
  def test_cloned_items_stay_frozen
449
 
    a = FileList['a', 'b', 'c']
450
 
    a.freeze
451
 
    c = a.clone
452
 
    assert_raise(TypeError, RuntimeError) do
453
 
      c << 'more'
454
 
    end
455
 
  end
456
 
 
457
 
  def test_array_comparisons
458
 
    fl = FileList['b', 'b']
459
 
    a = ['b', 'a']
460
 
    b = ['b', 'b']
461
 
    c = ['b', 'c']
462
 
    assert_equal( 1,  fl <=> a )
463
 
    assert_equal( 0,  fl <=> b )
464
 
    assert_equal( -1, fl <=> c )
465
 
    assert_equal( -1, a <=> fl )
466
 
    assert_equal( 0,  b <=> fl )
467
 
    assert_equal( 1,  c <=> fl )
468
 
  end
469
 
 
470
 
  def test_array_equality
471
 
    a = FileList['a', 'b']
472
 
    b = ['a', 'b']
473
 
    assert a == b
474
 
    assert b == a
475
 
#   assert a.eql?(b)
476
 
#    assert b.eql?(a)
477
 
    assert ! a.equal?(b)
478
 
    assert ! b.equal?(a)
479
 
  end
480
 
 
481
 
  def test_enumeration_methods
482
 
    a = FileList['a', 'b']
483
 
    b = a.collect { |it| it.upcase }
484
 
    assert_equal ['A', 'B'], b
485
 
    assert_equal FileList,  b.class
486
 
 
487
 
    b = a.map { |it| it.upcase }
488
 
    assert_equal ['A', 'B'], b
489
 
    assert_equal FileList,  b.class
490
 
 
491
 
    b = a.sort
492
 
    assert_equal ['a', 'b'], b
493
 
    assert_equal FileList,  b.class
494
 
 
495
 
    b = a.sort_by { |it| it }
496
 
    assert_equal ['a', 'b'], b
497
 
    assert_equal FileList,  b.class
498
 
 
499
 
    b = a.find_all { |it| it == 'b'}
500
 
    assert_equal ['b'], b
501
 
    assert_equal FileList,  b.class
502
 
 
503
 
    b = a.select { |it| it.size == 1 }
504
 
    assert_equal ['a', 'b'], b
505
 
    assert_equal FileList,  b.class
506
 
 
507
 
    b = a.reject { |it| it == 'b' }
508
 
    assert_equal ['a'], b
509
 
    assert_equal FileList,  b.class
510
 
 
511
 
    b = a.grep(/./)
512
 
    assert_equal ['a', 'b'], b
513
 
    assert_equal FileList,  b.class
514
 
 
515
 
    b = a.partition { |it| it == 'b' }
516
 
    assert_equal [['b'], ['a']], b
517
 
    assert_equal Array, b.class
518
 
    assert_equal FileList,  b[0].class
519
 
    assert_equal FileList,  b[1].class
520
 
 
521
 
    b = a.zip(['x', 'y']).to_a
522
 
    assert_equal [['a', 'x'], ['b', 'y']], b
523
 
    assert_equal Array, b.class
524
 
    assert_equal Array, b[0].class
525
 
    assert_equal Array, b[1].class
526
 
  end
527
 
 
528
 
  def test_array_operators
529
 
    a = ['a', 'b']
530
 
    b = ['c', 'd']
531
 
    f = FileList['x', 'y']
532
 
    g = FileList['w', 'z']
533
 
 
534
 
    r = f + g
535
 
    assert_equal ['x', 'y', 'w', 'z'], r
536
 
    assert_equal FileList, r.class
537
 
 
538
 
    r = a + g
539
 
    assert_equal ['a', 'b', 'w', 'z'], r
540
 
    assert_equal Array, r.class
541
 
 
542
 
    r = f + b
543
 
    assert_equal ['x', 'y', 'c', 'd'], r
544
 
    assert_equal FileList, r.class
545
 
 
546
 
    r = FileList['w', 'x', 'y', 'z'] - f
547
 
    assert_equal ['w', 'z'], r
548
 
    assert_equal FileList, r.class
549
 
 
550
 
    r = FileList['w', 'x', 'y', 'z'] & f
551
 
    assert_equal ['x', 'y'], r
552
 
    assert_equal FileList, r.class
553
 
 
554
 
    r = f * 2
555
 
    assert_equal ['x', 'y', 'x', 'y'], r
556
 
    assert_equal FileList, r.class
557
 
 
558
 
    r = f * ','
559
 
    assert_equal 'x,y', r
560
 
    assert_equal String, r.class
561
 
 
562
 
    r = f | ['a', 'x']
563
 
    assert_equal ['a', 'x', 'y'].sort, r.sort
564
 
    assert_equal FileList, r.class
565
 
  end
566
 
 
567
 
  def test_other_array_returning_methods
568
 
    f = FileList['a', nil, 'b']
569
 
    r = f.compact
570
 
    assert_equal ['a', 'b'], r
571
 
    assert_equal FileList, r.class
572
 
 
573
 
    f = FileList['a', 'b']
574
 
    r = f.concat(['x', 'y'])
575
 
    assert_equal ['a', 'b', 'x', 'y'], r
576
 
    assert_equal FileList, r.class
577
 
 
578
 
    f = FileList['a', ['b', 'c'], FileList['d', 'e']]
579
 
    r = f.flatten
580
 
    assert_equal ['a', 'b', 'c', 'd', 'e'], r
581
 
    assert_equal FileList, r.class
582
 
 
583
 
    f = FileList['a', 'b', 'a']
584
 
    r = f.uniq
585
 
    assert_equal ['a', 'b'], r
586
 
    assert_equal FileList, r.class
587
 
 
588
 
    f = FileList['a', 'b', 'c', 'd']
589
 
    r = f.values_at(1,3)
590
 
    assert_equal ['b', 'd'], r
591
 
    assert_equal FileList, r.class
592
 
  end
593
 
  
594
 
  def test_file_utils_can_use_filelists
595
 
    cfiles = FileList['testdata/*.c']
596
 
    
597
 
    cp cfiles, @cdir, :verbose => false
598
 
    
599
 
    assert File.exist?(File.join(@cdir, 'abc.c'))
600
 
    assert File.exist?(File.join(@cdir, 'xyz.c'))
601
 
    assert File.exist?(File.join(@cdir, 'x.c'))
602
 
  end
603
 
 
604
 
  def create_test_data
605
 
    verbose(false) do
606
 
      
607
 
      mkdir "testdata" unless File.exist? "testdata"
608
 
      mkdir "testdata/CVS" rescue nil
609
 
      mkdir "testdata/.svn" rescue nil
610
 
      @cdir = "testdata/cfiles"
611
 
      mkdir @cdir rescue nil
612
 
      touch "testdata/.dummy"
613
 
      touch "testdata/x.bak"
614
 
      touch "testdata/x~"
615
 
      touch "testdata/core"
616
 
      touch "testdata/x.c"
617
 
      touch "testdata/xyz.c"
618
 
      touch "testdata/abc.c"
619
 
      touch "testdata/abc.h"
620
 
      touch "testdata/abc.x"
621
 
      touch "testdata/existing"
622
 
    end
623
 
  end
624
 
  
625
 
end