luislavena-rake 0.8.3.99

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.
Files changed (104) hide show
  1. data/CHANGES +422 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +196 -0
  4. data/Rakefile +416 -0
  5. data/TODO +20 -0
  6. data/bin/rake +31 -0
  7. data/doc/command_line_usage.rdoc +102 -0
  8. data/doc/example/Rakefile1 +38 -0
  9. data/doc/example/Rakefile2 +35 -0
  10. data/doc/example/a.c +6 -0
  11. data/doc/example/b.c +6 -0
  12. data/doc/example/main.c +11 -0
  13. data/doc/glossary.rdoc +51 -0
  14. data/doc/jamis.rb +591 -0
  15. data/doc/proto_rake.rdoc +127 -0
  16. data/doc/rake.1.gz +0 -0
  17. data/doc/rakefile.rdoc +534 -0
  18. data/doc/rational.rdoc +151 -0
  19. data/doc/release_notes/rake-0.4.14.rdoc +23 -0
  20. data/doc/release_notes/rake-0.4.15.rdoc +35 -0
  21. data/doc/release_notes/rake-0.5.0.rdoc +53 -0
  22. data/doc/release_notes/rake-0.5.3.rdoc +78 -0
  23. data/doc/release_notes/rake-0.5.4.rdoc +46 -0
  24. data/doc/release_notes/rake-0.6.0.rdoc +141 -0
  25. data/doc/release_notes/rake-0.7.0.rdoc +119 -0
  26. data/doc/release_notes/rake-0.7.1.rdoc +59 -0
  27. data/doc/release_notes/rake-0.7.2.rdoc +121 -0
  28. data/doc/release_notes/rake-0.7.3.rdoc +47 -0
  29. data/doc/release_notes/rake-0.8.0.rdoc +114 -0
  30. data/doc/release_notes/rake-0.8.2.rdoc +165 -0
  31. data/doc/release_notes/rake-0.8.3.rdoc +112 -0
  32. data/doc/release_notes/rake-0.8.4.rdoc +125 -0
  33. data/install.rb +88 -0
  34. data/lib/rake.rb +2478 -0
  35. data/lib/rake/classic_namespace.rb +8 -0
  36. data/lib/rake/clean.rb +33 -0
  37. data/lib/rake/contrib/compositepublisher.rb +24 -0
  38. data/lib/rake/contrib/ftptools.rb +153 -0
  39. data/lib/rake/contrib/publisher.rb +75 -0
  40. data/lib/rake/contrib/rubyforgepublisher.rb +18 -0
  41. data/lib/rake/contrib/sshpublisher.rb +47 -0
  42. data/lib/rake/contrib/sys.rb +209 -0
  43. data/lib/rake/gempackagetask.rb +97 -0
  44. data/lib/rake/loaders/makefile.rb +42 -0
  45. data/lib/rake/packagetask.rb +184 -0
  46. data/lib/rake/rake_test_loader.rb +5 -0
  47. data/lib/rake/rdoctask.rb +209 -0
  48. data/lib/rake/ruby182_test_unit_fix.rb +23 -0
  49. data/lib/rake/runtest.rb +23 -0
  50. data/lib/rake/tasklib.rb +23 -0
  51. data/lib/rake/testtask.rb +161 -0
  52. data/lib/rake/win32.rb +57 -0
  53. data/test/capture_stdout.rb +26 -0
  54. data/test/check_expansion.rb +5 -0
  55. data/test/contrib/test_sys.rb +47 -0
  56. data/test/data/chains/Rakefile +15 -0
  57. data/test/data/default/Rakefile +19 -0
  58. data/test/data/dryrun/Rakefile +22 -0
  59. data/test/data/file_creation_task/Rakefile +33 -0
  60. data/test/data/imports/Rakefile +19 -0
  61. data/test/data/imports/deps.mf +1 -0
  62. data/test/data/multidesc/Rakefile +17 -0
  63. data/test/data/namespace/Rakefile +57 -0
  64. data/test/data/rakelib/test1.rb +3 -0
  65. data/test/data/rbext/rakefile.rb +3 -0
  66. data/test/data/sample.mf +14 -0
  67. data/test/data/statusreturn/Rakefile +8 -0
  68. data/test/data/unittest/Rakefile +1 -0
  69. data/test/filecreation.rb +32 -0
  70. data/test/functional.rb +15 -0
  71. data/test/in_environment.rb +30 -0
  72. data/test/rake_test_setup.rb +24 -0
  73. data/test/reqfile.rb +3 -0
  74. data/test/reqfile2.rb +3 -0
  75. data/test/session_functional.rb +339 -0
  76. data/test/shellcommand.rb +3 -0
  77. data/test/test_application.rb +713 -0
  78. data/test/test_clean.rb +14 -0
  79. data/test/test_definitions.rb +85 -0
  80. data/test/test_earlytime.rb +35 -0
  81. data/test/test_extension.rb +63 -0
  82. data/test/test_file_creation_task.rb +62 -0
  83. data/test/test_file_task.rb +143 -0
  84. data/test/test_filelist.rb +620 -0
  85. data/test/test_fileutils.rb +266 -0
  86. data/test/test_ftp.rb +59 -0
  87. data/test/test_invocation_chain.rb +81 -0
  88. data/test/test_makefile_loader.rb +26 -0
  89. data/test/test_multitask.rb +45 -0
  90. data/test/test_namespace.rb +55 -0
  91. data/test/test_package_task.rb +118 -0
  92. data/test/test_pathmap.rb +210 -0
  93. data/test/test_rake.rb +41 -0
  94. data/test/test_rdoc_task.rb +88 -0
  95. data/test/test_require.rb +35 -0
  96. data/test/test_rules.rb +349 -0
  97. data/test/test_task_arguments.rb +89 -0
  98. data/test/test_task_manager.rb +173 -0
  99. data/test/test_tasklib.rb +12 -0
  100. data/test/test_tasks.rb +374 -0
  101. data/test/test_test_task.rb +77 -0
  102. data/test/test_top_level_functions.rb +86 -0
  103. data/test/test_win32.rb +72 -0
  104. metadata +186 -0
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake/clean'
5
+
6
+ class TestClean < Test::Unit::TestCase
7
+ include Rake
8
+ def test_clean
9
+ assert Task['clean'], "Should define clean"
10
+ assert Task['clobber'], "Should define clobber"
11
+ assert Task['clobber'].prerequisites.include?("clean"),
12
+ "Clobber should require clean"
13
+ end
14
+ end
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'fileutils'
5
+ require 'rake'
6
+ require 'test/filecreation'
7
+ require 'test/rake_test_setup'
8
+
9
+ ######################################################################
10
+ class TestDefinitions < Test::Unit::TestCase
11
+ include Rake
12
+ include TestMethods
13
+
14
+ EXISTINGFILE = "testdata/existing"
15
+
16
+ def setup
17
+ Task.clear
18
+ end
19
+
20
+ def test_task
21
+ done = false
22
+ task :one => [:two] do done = true end
23
+ task :two
24
+ task :three => [:one, :two]
25
+ check_tasks(:one, :two, :three)
26
+ assert done, "Should be done"
27
+ end
28
+
29
+ def test_file_task
30
+ done = false
31
+ file "testdata/one" => "testdata/two" do done = true end
32
+ file "testdata/two"
33
+ file "testdata/three" => ["testdata/one", "testdata/two"]
34
+ check_tasks("testdata/one", "testdata/two", "testdata/three")
35
+ assert done, "Should be done"
36
+ end
37
+
38
+ def check_tasks(n1, n2, n3)
39
+ t = Task[n1]
40
+ assert Task === t, "Should be a Task"
41
+ assert_equal n1.to_s, t.name
42
+ assert_equal [n2.to_s], t.prerequisites.collect{|n| n.to_s}
43
+ t.invoke
44
+ t2 = Task[n2]
45
+ assert_equal FileList[], t2.prerequisites
46
+ t3 = Task[n3]
47
+ assert_equal [n1.to_s, n2.to_s], t3.prerequisites.collect{|n|n.to_s}
48
+ end
49
+
50
+ def test_incremental_definitions
51
+ runs = []
52
+ task :t1 => [:t2] do runs << "A"; 4321 end
53
+ task :t1 => [:t3] do runs << "B"; 1234 end
54
+ task :t1 => [:t3]
55
+ task :t2
56
+ task :t3
57
+ Task[:t1].invoke
58
+ assert_equal ["A", "B"], runs
59
+ assert_equal ["t2", "t3"], Task[:t1].prerequisites
60
+ end
61
+
62
+ def test_missing_dependencies
63
+ task :x => ["testdata/missing"]
64
+ assert_exception(RuntimeError) { Task[:x].invoke }
65
+ end
66
+
67
+ def test_implicit_file_dependencies
68
+ runs = []
69
+ create_existing_file
70
+ task :y => [EXISTINGFILE] do |t| runs << t.name end
71
+ Task[:y].invoke
72
+ assert_equal runs, ['y']
73
+ end
74
+
75
+ private # ----------------------------------------------------------
76
+
77
+ def create_existing_file
78
+ Dir.mkdir File.dirname(EXISTINGFILE) unless
79
+ File.exist?(File.dirname(EXISTINGFILE))
80
+ open(EXISTINGFILE, "w") do |f| f.puts "HI" end unless
81
+ File.exist?(EXISTINGFILE)
82
+ end
83
+
84
+ end
85
+
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+
6
+ class TestEarlyTime < Test::Unit::TestCase
7
+ def test_create
8
+ early = Rake::EarlyTime.instance
9
+ time = Time.mktime(1970, 1, 1, 0, 0, 0)
10
+ assert early <= Time.now
11
+ assert early < Time.now
12
+ assert early != Time.now
13
+ assert Time.now > early
14
+ assert Time.now >= early
15
+ assert Time.now != early
16
+ end
17
+
18
+ def test_equality
19
+ early = Rake::EarlyTime.instance
20
+ assert_equal early, early, "two early times should be equal"
21
+ end
22
+
23
+ def test_original_time_compare_is_not_messed_up
24
+ t1 = Time.mktime(1970, 1, 1, 0, 0, 0)
25
+ t2 = Time.now
26
+ assert t1 < t2
27
+ assert t2 > t1
28
+ assert t1 == t1
29
+ assert t2 == t2
30
+ end
31
+
32
+ def test_to_s
33
+ assert_equal "<EARLY TIME>", Rake::EARLY.to_s
34
+ end
35
+ end
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+ require 'stringio'
6
+
7
+ ######################################################################
8
+ class TestExtension < Test::Unit::TestCase
9
+
10
+ module Redirect
11
+ def error_redirect
12
+ old_err = $stderr
13
+ result = StringIO.new
14
+ $stderr = result
15
+ yield
16
+ result
17
+ ensure
18
+ $stderr = old_err
19
+ end
20
+ end
21
+
22
+ class Sample
23
+ extend Redirect
24
+
25
+ def duplicate_method
26
+ :original
27
+ end
28
+
29
+ OK_ERRS = error_redirect do
30
+ rake_extension("a") do
31
+ def ok_method
32
+ end
33
+ end
34
+ end
35
+
36
+
37
+ DUP_ERRS = error_redirect do
38
+ rake_extension("duplicate_method") do
39
+ def duplicate_method
40
+ :override
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ def test_methods_actually_exist
47
+ sample = Sample.new
48
+ sample.ok_method
49
+ sample.duplicate_method
50
+ end
51
+
52
+ def test_no_warning_when_defining_ok_method
53
+ assert_equal "", Sample::OK_ERRS.string
54
+ end
55
+
56
+ def test_extension_complains_when_a_method_that_is_present
57
+ assert_match(/warning:/i, Sample::DUP_ERRS.string)
58
+ assert_match(/already exists/i, Sample::DUP_ERRS.string)
59
+ assert_match(/duplicate_method/i, Sample::DUP_ERRS.string)
60
+ assert_equal :original, Sample.new.duplicate_method
61
+ end
62
+
63
+ end
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'fileutils'
5
+ require 'rake'
6
+ require 'test/filecreation'
7
+
8
+ ######################################################################
9
+ class TestFileCreationTask < Test::Unit::TestCase
10
+ include Rake
11
+ include FileCreation
12
+
13
+ DUMMY_DIR = 'testdata/dummy_dir'
14
+
15
+ def setup
16
+ Task.clear
17
+ end
18
+
19
+ def teardown
20
+ FileUtils.rm_rf DUMMY_DIR
21
+ end
22
+
23
+ def test_file_needed
24
+ create_dir DUMMY_DIR
25
+ fc_task = Task[DUMMY_DIR]
26
+ assert_equal DUMMY_DIR, fc_task.name
27
+ FileUtils.rm_rf fc_task.name
28
+ assert fc_task.needed?, "file should be needed"
29
+ FileUtils.mkdir fc_task.name
30
+ assert_equal nil, fc_task.prerequisites.collect{|n| Task[n].timestamp}.max
31
+ assert ! fc_task.needed?, "file should not be needed"
32
+ end
33
+
34
+ def test_directory
35
+ directory DUMMY_DIR
36
+ fc_task = Task[DUMMY_DIR]
37
+ assert_equal DUMMY_DIR, fc_task.name
38
+ assert FileCreationTask === fc_task
39
+ end
40
+
41
+ def test_no_retriggers_on_filecreate_task
42
+ create_timed_files(OLDFILE, NEWFILE)
43
+ t1 = Rake.application.intern(FileCreationTask, OLDFILE).enhance([NEWFILE])
44
+ t2 = Rake.application.intern(FileCreationTask, NEWFILE)
45
+ assert ! t2.needed?, "Should not need to build new file"
46
+ assert ! t1.needed?, "Should not need to rebuild old file because of new"
47
+ end
48
+
49
+ def test_no_retriggers_on_file_task
50
+ create_timed_files(OLDFILE, NEWFILE)
51
+ t1 = Rake.application.intern(FileCreationTask, OLDFILE).enhance([NEWFILE])
52
+ t2 = Rake.application.intern(FileCreationTask, NEWFILE)
53
+ assert ! t2.needed?, "Should not need to build new file"
54
+ assert ! t1.needed?, "Should not need to rebuild old file because of new"
55
+ end
56
+
57
+ def test_very_early_timestamp
58
+ t1 = Rake.application.intern(FileCreationTask, OLDFILE)
59
+ assert t1.timestamp < Time.now
60
+ assert t1.timestamp < Time.now - 1000000
61
+ end
62
+ end
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'fileutils'
5
+ require 'rake'
6
+ require 'test/filecreation'
7
+ require 'test/rake_test_setup'
8
+
9
+ ######################################################################
10
+ class TestFileTask < Test::Unit::TestCase
11
+ include Rake
12
+ include FileCreation
13
+ include TestMethods
14
+
15
+ def setup
16
+ Task.clear
17
+ @runs = Array.new
18
+ FileUtils.rm_f NEWFILE
19
+ FileUtils.rm_f OLDFILE
20
+ end
21
+
22
+ def test_file_need
23
+ name = "testdata/dummy"
24
+ file name
25
+ ftask = Task[name]
26
+ assert_equal name.to_s, ftask.name
27
+ File.delete(ftask.name) rescue nil
28
+ assert ftask.needed?, "file should be needed"
29
+ open(ftask.name, "w") { |f| f.puts "HI" }
30
+ assert_equal nil, ftask.prerequisites.collect{|n| Task[n].timestamp}.max
31
+ assert ! ftask.needed?, "file should not be needed"
32
+ File.delete(ftask.name) rescue nil
33
+ end
34
+
35
+ def test_file_times_new_depends_on_old
36
+ create_timed_files(OLDFILE, NEWFILE)
37
+
38
+ t1 = Rake.application.intern(FileTask, NEWFILE).enhance([OLDFILE])
39
+ t2 = Rake.application.intern(FileTask, OLDFILE)
40
+ assert ! t2.needed?, "Should not need to build old file"
41
+ assert ! t1.needed?, "Should not need to rebuild new file because of old"
42
+ end
43
+
44
+ def test_file_times_old_depends_on_new
45
+ create_timed_files(OLDFILE, NEWFILE)
46
+
47
+ t1 = Rake.application.intern(FileTask,OLDFILE).enhance([NEWFILE])
48
+ t2 = Rake.application.intern(FileTask, NEWFILE)
49
+ assert ! t2.needed?, "Should not need to build new file"
50
+ preq_stamp = t1.prerequisites.collect{|t| Task[t].timestamp}.max
51
+ assert_equal t2.timestamp, preq_stamp
52
+ assert t1.timestamp < preq_stamp, "T1 should be older"
53
+ assert t1.needed?, "Should need to rebuild old file because of new"
54
+ end
55
+
56
+ def test_file_depends_on_task_depend_on_file
57
+ create_timed_files(OLDFILE, NEWFILE)
58
+
59
+ file NEWFILE => [:obj] do |t| @runs << t.name end
60
+ task :obj => [OLDFILE] do |t| @runs << t.name end
61
+ file OLDFILE do |t| @runs << t.name end
62
+
63
+ Task[:obj].invoke
64
+ Task[NEWFILE].invoke
65
+ assert ! @runs.include?(NEWFILE)
66
+ end
67
+
68
+ def test_existing_file_depends_on_non_existing_file
69
+ create_file(OLDFILE)
70
+ delete_file(NEWFILE)
71
+ file NEWFILE
72
+ file OLDFILE => NEWFILE
73
+ assert_nothing_raised do Task[OLDFILE].invoke end
74
+ end
75
+
76
+ # I have currently disabled this test. I'm not convinced that
77
+ # deleting the file target on failure is always the proper thing to
78
+ # do. I'm willing to hear input on this topic.
79
+ def ztest_file_deletes_on_failure
80
+ task :obj
81
+ file NEWFILE => [:obj] do |t|
82
+ FileUtils.touch NEWFILE
83
+ fail "Ooops"
84
+ end
85
+ assert Task[NEWFILE]
86
+ begin
87
+ Task[NEWFILE].invoke
88
+ rescue Exception
89
+ end
90
+ assert( ! File.exist?(NEWFILE), "NEWFILE should be deleted")
91
+ end
92
+
93
+ end
94
+
95
+ ######################################################################
96
+ class TestDirectoryTask < Test::Unit::TestCase
97
+ include Rake
98
+
99
+ def setup
100
+ rm_rf "testdata", :verbose=>false
101
+ end
102
+
103
+ def teardown
104
+ rm_rf "testdata", :verbose=>false
105
+ end
106
+
107
+ def test_directory
108
+ desc "DESC"
109
+ directory "testdata/a/b/c"
110
+ assert_equal FileCreationTask, Task["testdata"].class
111
+ assert_equal FileCreationTask, Task["testdata/a"].class
112
+ assert_equal FileCreationTask, Task["testdata/a/b/c"].class
113
+ assert_nil Task["testdata"].comment
114
+ assert_equal "DESC", Task["testdata/a/b/c"].comment
115
+ assert_nil Task["testdata/a/b"].comment
116
+ verbose(false) {
117
+ Task['testdata/a/b'].invoke
118
+ }
119
+ assert File.exist?("testdata/a/b")
120
+ assert ! File.exist?("testdata/a/b/c")
121
+ end
122
+
123
+ if Rake::Win32.windows?
124
+ def test_directory_win32
125
+ desc "WIN32 DESC"
126
+ FileUtils.mkdir_p("testdata")
127
+ Dir.chdir("testdata") do
128
+ directory 'c:/testdata/a/b/c'
129
+ assert_equal FileCreationTask, Task['c:/testdata'].class
130
+ assert_equal FileCreationTask, Task['c:/testdata/a'].class
131
+ assert_equal FileCreationTask, Task['c:/testdata/a/b/c'].class
132
+ assert_nil Task['c:/testdata'].comment
133
+ assert_equal "WIN32 DESC", Task['c:/testdata/a/b/c'].comment
134
+ assert_nil Task['c:/testdata/a/b'].comment
135
+ verbose(false) {
136
+ Task['c:/testdata/a/b'].invoke
137
+ }
138
+ assert File.exist?('c:/testdata/a/b')
139
+ assert ! File.exist?('c:/testdata/a/b/c')
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,620 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'rake'
5
+
6
+ require 'test/capture_stdout'
7
+ require 'test/rake_test_setup'
8
+
9
+ class TestFileList < Test::Unit::TestCase
10
+ FileList = Rake::FileList
11
+ include CaptureStdout
12
+ include TestMethods
13
+
14
+ def setup
15
+ create_test_data
16
+ end
17
+
18
+ def teardown
19
+ # FileList.select_default_ignore_patterns
20
+ FileUtils.rm_rf("testdata")
21
+ end
22
+
23
+ def test_delgating_methods_do_not_include_to_a_or_to_ary
24
+ assert ! FileList::DELEGATING_METHODS.include?("to_a"), "should not include to_a"
25
+ assert ! FileList::DELEGATING_METHODS.include?(:to_a), "should not include to_a"
26
+ assert ! FileList::DELEGATING_METHODS.include?("to_ary"), "should not include to_ary"
27
+ assert ! FileList::DELEGATING_METHODS.include?(:to_ary), "should not include to_ary"
28
+ end
29
+
30
+ def test_create
31
+ fl = FileList.new
32
+ assert_equal 0, fl.size
33
+ end
34
+
35
+ def test_create_with_args
36
+ fl = FileList.new("testdata/*.c", "x")
37
+ assert_equal ["testdata/abc.c", "testdata/x.c", "testdata/xyz.c", "x"].sort,
38
+ fl.sort
39
+ end
40
+
41
+ def test_create_with_block
42
+ fl = FileList.new { |f| f.include("x") }
43
+ assert_equal ["x"], fl.resolve
44
+ end
45
+
46
+ def test_create_with_brackets
47
+ fl = FileList["testdata/*.c", "x"]
48
+ assert_equal ["testdata/abc.c", "testdata/x.c", "testdata/xyz.c", "x"].sort,
49
+ fl.sort
50
+ end
51
+
52
+ def test_create_with_brackets_and_filelist
53
+ fl = FileList[FileList["testdata/*.c", "x"]]
54
+ assert_equal ["testdata/abc.c", "testdata/x.c", "testdata/xyz.c", "x"].sort,
55
+ fl.sort
56
+ end
57
+
58
+ def test_include_with_another_array
59
+ fl = FileList.new.include(["x", "y", "z"])
60
+ assert_equal ["x", "y", "z"].sort, fl.sort
61
+ end
62
+
63
+ def test_include_with_another_filelist
64
+ fl = FileList.new.include(FileList["testdata/*.c", "x"])
65
+ assert_equal ["testdata/abc.c", "testdata/x.c", "testdata/xyz.c", "x"].sort,
66
+ fl.sort
67
+ end
68
+
69
+ def test_append
70
+ fl = FileList.new
71
+ fl << "a.rb" << "b.rb"
72
+ assert_equal ['a.rb', 'b.rb'], fl
73
+ end
74
+
75
+ def test_add_many
76
+ fl = FileList.new
77
+ fl.include %w(a d c)
78
+ fl.include('x', 'y')
79
+ assert_equal ['a', 'd', 'c', 'x', 'y'], fl
80
+ assert_equal ['a', 'd', 'c', 'x', 'y'], fl.resolve
81
+ end
82
+
83
+ def test_add_return
84
+ f = FileList.new
85
+ g = f << "x"
86
+ assert_equal f.object_id, g.object_id
87
+ h = f.include("y")
88
+ assert_equal f.object_id, h.object_id
89
+ end
90
+
91
+ def test_match
92
+ fl = FileList.new
93
+ fl.include('test/test*.rb')
94
+ assert fl.include?("test/test_filelist.rb")
95
+ assert fl.size > 3
96
+ fl.each { |fn| assert_match(/\.rb$/, fn) }
97
+ end
98
+
99
+ def test_add_matching
100
+ fl = FileList.new
101
+ fl << "a.java"
102
+ fl.include("test/*.rb")
103
+ assert_equal "a.java", fl[0]
104
+ assert fl.size > 2
105
+ assert fl.include?("test/test_filelist.rb")
106
+ end
107
+
108
+ def test_multiple_patterns
109
+ create_test_data
110
+ fl = FileList.new
111
+ fl.include('*.c', '*xist*')
112
+ assert_equal [], fl
113
+ fl.include('testdata/*.c', 'testdata/*xist*')
114
+ assert_equal [
115
+ 'testdata/x.c', 'testdata/xyz.c', 'testdata/abc.c', 'testdata/existing'
116
+ ].sort, fl.sort
117
+ end
118
+
119
+ def test_square_bracket_pattern
120
+ fl = FileList.new
121
+ fl.include("testdata/abc.[ch]")
122
+ assert fl.size == 2
123
+ assert fl.include?("testdata/abc.c")
124
+ assert fl.include?("testdata/abc.h")
125
+ end
126
+
127
+ def test_curly_bracket_pattern
128
+ fl = FileList.new
129
+ fl.include("testdata/abc.{c,h}")
130
+ assert fl.size == 2
131
+ assert fl.include?("testdata/abc.c")
132
+ assert fl.include?("testdata/abc.h")
133
+ end
134
+
135
+ def test_reject
136
+ fl = FileList.new
137
+ fl.include %w(testdata/x.c testdata/abc.c testdata/xyz.c testdata/existing)
138
+ fl.reject! { |fn| fn =~ %r{/x} }
139
+ assert_equal [
140
+ 'testdata/abc.c', 'testdata/existing'
141
+ ], fl
142
+ end
143
+
144
+ def test_exclude
145
+ fl = FileList['testdata/x.c', 'testdata/abc.c', 'testdata/xyz.c', 'testdata/existing']
146
+ fl.each { |fn| touch fn, :verbose => false }
147
+ x = fl.exclude(%r{/x.+\.})
148
+ assert_equal FileList, x.class
149
+ assert_equal %w(testdata/x.c testdata/abc.c testdata/existing), fl
150
+ assert_equal fl.object_id, x.object_id
151
+ fl.exclude('testdata/*.c')
152
+ assert_equal ['testdata/existing'], fl
153
+ fl.exclude('testdata/existing')
154
+ assert_equal [], fl
155
+ end
156
+
157
+ def test_excluding_via_block
158
+ fl = FileList['testdata/a.c', 'testdata/b.c', 'testdata/xyz.c']
159
+ fl.exclude { |fn| fn.pathmap('%n') == 'xyz' }
160
+ assert fl.exclude?("xyz.c"), "Should exclude xyz.c"
161
+ assert_equal ['testdata/a.c', 'testdata/b.c'], fl
162
+ end
163
+
164
+ def test_exclude_return_on_create
165
+ fl = FileList['testdata/*'].exclude(/.*\.[hcx]$/)
166
+ assert_equal ['testdata/existing', 'testdata/cfiles'].sort, fl.sort
167
+ assert_equal FileList, fl.class
168
+ end
169
+
170
+ def test_exclude_with_string_return_on_create
171
+ fl = FileList['testdata/*'].exclude('testdata/abc.c')
172
+ assert_equal %w(testdata/existing testdata/cfiles testdata/x.c testdata/abc.h testdata/abc.x testdata/xyz.c).sort, fl.sort
173
+ assert_equal FileList, fl.class
174
+ end
175
+
176
+ def test_default_exclude
177
+ fl = FileList.new
178
+ fl.clear_exclude
179
+ fl.include("**/*~", "**/*.bak", "**/core")
180
+ assert fl.member?("testdata/core"), "Should include core"
181
+ assert fl.member?("testdata/x.bak"), "Should include .bak files"
182
+ end
183
+
184
+ def test_unique
185
+ fl = FileList.new
186
+ fl << "x.c" << "a.c" << "b.rb" << "a.c"
187
+ assert_equal ['x.c', 'a.c', 'b.rb', 'a.c'], fl
188
+ fl.uniq!
189
+ assert_equal ['x.c', 'a.c', 'b.rb'], fl
190
+ end
191
+
192
+ def test_to_string
193
+ fl = FileList.new
194
+ fl << "a.java" << "b.java"
195
+ assert_equal "a.java b.java", fl.to_s
196
+ assert_equal "a.java b.java", "#{fl}"
197
+ end
198
+
199
+ def test_to_array
200
+ fl = FileList['a.java', 'b.java']
201
+ assert_equal ['a.java', 'b.java'], fl.to_a
202
+ assert_equal Array, fl.to_a.class
203
+ assert_equal ['a.java', 'b.java'], fl.to_ary
204
+ assert_equal Array, fl.to_ary.class
205
+ end
206
+
207
+ def test_to_s_pending
208
+ fl = FileList['testdata/abc.*']
209
+ result = fl.to_s
210
+ assert_match(%r{testdata/abc\.c}, result)
211
+ assert_match(%r{testdata/abc\.h}, result)
212
+ assert_match(%r{testdata/abc\.x}, result)
213
+ assert_match(%r{(testdata/abc\..\b ?){2}}, result)
214
+ end
215
+
216
+ def test_inspect_pending
217
+ fl = FileList['testdata/abc.*']
218
+ result = fl.inspect
219
+ assert_match(%r{"testdata/abc\.c"}, result)
220
+ assert_match(%r{"testdata/abc\.h"}, result)
221
+ assert_match(%r{"testdata/abc\.x"}, result)
222
+ assert_match(%r|^\[("testdata/abc\..", ){2}"testdata/abc\.."\]$|, result)
223
+ end
224
+
225
+ def test_sub
226
+ fl = FileList["testdata/*.c"]
227
+ f2 = fl.sub(/\.c$/, ".o")
228
+ assert_equal FileList, f2.class
229
+ assert_equal ["testdata/abc.o", "testdata/x.o", "testdata/xyz.o"].sort,
230
+ f2.sort
231
+ f3 = fl.gsub(/\.c$/, ".o")
232
+ assert_equal FileList, f3.class
233
+ assert_equal ["testdata/abc.o", "testdata/x.o", "testdata/xyz.o"].sort,
234
+ f3.sort
235
+ end
236
+
237
+ def test_claim_to_be_a_kind_of_array
238
+ fl = FileList['testdata/*.c']
239
+ assert fl.is_a?(Array)
240
+ assert fl.kind_of?(Array)
241
+ end
242
+
243
+ def test_claim_to_be_a_kind_of_filelist
244
+ fl = FileList['testdata/*.c']
245
+ assert fl.is_a?(FileList)
246
+ assert fl.kind_of?(FileList)
247
+ end
248
+
249
+ def test_claim_to_be_a_filelist_instance
250
+ fl = FileList['testdata/*.c']
251
+ assert fl.instance_of?(FileList)
252
+ end
253
+
254
+ def test_dont_claim_to_be_an_array_instance
255
+ fl = FileList['testdata/*.c']
256
+ assert ! fl.instance_of?(Array)
257
+ end
258
+
259
+ def test_sub!
260
+ f = "x/a.c"
261
+ fl = FileList[f, "x/b.c"]
262
+ res = fl.sub!(/\.c$/, ".o")
263
+ assert_equal ["x/a.o", "x/b.o"].sort, fl.sort
264
+ assert_equal "x/a.c", f
265
+ assert_equal fl.object_id, res.object_id
266
+ end
267
+
268
+ def test_sub_with_block
269
+ fl = FileList["src/org/onestepback/a.java", "src/org/onestepback/b.java"]
270
+ # The block version doesn't work the way I want it to ...
271
+ # f2 = fl.sub(%r{^src/(.*)\.java$}) { |x| "classes/" + $1 + ".class" }
272
+ f2 = fl.sub(%r{^src/(.*)\.java$}, "classes/\\1.class")
273
+ assert_equal [
274
+ "classes/org/onestepback/a.class",
275
+ "classes/org/onestepback/b.class"
276
+ ].sort,
277
+ f2.sort
278
+ end
279
+
280
+ def test_string_ext
281
+ assert_equal "one.net", "one.two".ext("net")
282
+ assert_equal "one.net", "one.two".ext(".net")
283
+ assert_equal "one.net", "one".ext("net")
284
+ assert_equal "one.net", "one".ext(".net")
285
+ assert_equal "one.two.net", "one.two.c".ext(".net")
286
+ assert_equal "one/two.net", "one/two.c".ext(".net")
287
+ assert_equal "one.x/two.net", "one.x/two.c".ext(".net")
288
+ assert_equal "one.x\\two.net", "one.x\\two.c".ext(".net")
289
+ assert_equal "one.x/two.net", "one.x/two".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
+ end
301
+
302
+ def test_filelist_ext
303
+ assert_equal FileList['one.c', '.one.c'],
304
+ FileList['one.net', '.one'].ext('c')
305
+ end
306
+
307
+ def test_gsub
308
+ create_test_data
309
+ fl = FileList["testdata/*.c"]
310
+ f2 = fl.gsub(/a/, "A")
311
+ assert_equal ["testdAtA/Abc.c", "testdAtA/x.c", "testdAtA/xyz.c"].sort,
312
+ f2.sort
313
+ end
314
+
315
+ def test_gsub!
316
+ create_test_data
317
+ f = FileList["testdata/*.c"]
318
+ f.gsub!(/a/, "A")
319
+ assert_equal ["testdAtA/Abc.c", "testdAtA/x.c", "testdAtA/xyz.c"].sort,
320
+ f.sort
321
+ end
322
+
323
+ def test_egrep_with_output
324
+ files = FileList['test/test*.rb']
325
+ the_line_number = __LINE__ + 1
326
+ out = capture_stdout do files.egrep(/PUGH/) end
327
+ assert_match(/:#{the_line_number}:/, out)
328
+ end
329
+
330
+ def test_egrep_with_block
331
+ files = FileList['test/test*.rb']
332
+ found = false
333
+ the_line_number = __LINE__ + 1
334
+ files.egrep(/XYZZY/) do |fn, ln, line |
335
+ assert_equal 'test/test_filelist.rb', fn
336
+ assert_equal the_line_number, ln
337
+ assert_match(/files\.egrep/, line)
338
+ found = true
339
+ end
340
+ assert found, "should have found a matching line"
341
+ end
342
+
343
+ def test_existing
344
+ fl = FileList['testdata/abc.c', 'testdata/notthere.c']
345
+ assert_equal ["testdata/abc.c"], fl.existing
346
+ assert fl.existing.is_a?(FileList)
347
+ end
348
+
349
+ def test_existing!
350
+ fl = FileList['testdata/abc.c', 'testdata/notthere.c']
351
+ result = fl.existing!
352
+ assert_equal ["testdata/abc.c"], fl
353
+ assert_equal fl.object_id, result.object_id
354
+ end
355
+
356
+ def test_ignore_special
357
+ f = FileList['testdata/*']
358
+ assert ! f.include?("testdata/CVS"), "Should not contain CVS"
359
+ assert ! f.include?("testdata/.svn"), "Should not contain .svn"
360
+ assert ! f.include?("testdata/.dummy"), "Should not contain dot files"
361
+ assert ! f.include?("testdata/x.bak"), "Should not contain .bak files"
362
+ assert ! f.include?("testdata/x~"), "Should not contain ~ files"
363
+ assert ! f.include?("testdata/core"), "Should not contain core files"
364
+ end
365
+
366
+ def test_clear_ignore_patterns
367
+ f = FileList['testdata/*', 'testdata/.svn']
368
+ f.clear_exclude
369
+ assert f.include?("testdata/abc.c")
370
+ assert f.include?("testdata/xyz.c")
371
+ assert f.include?("testdata/CVS")
372
+ assert f.include?("testdata/.svn")
373
+ assert f.include?("testdata/x.bak")
374
+ assert f.include?("testdata/x~")
375
+ end
376
+
377
+ def test_exclude_with_alternate_file_seps
378
+ fl = FileList.new
379
+ assert fl.exclude?("x/CVS/y")
380
+ assert fl.exclude?("x\\CVS\\y")
381
+ assert fl.exclude?("x/.svn/y")
382
+ assert fl.exclude?("x\\.svn\\y")
383
+ assert fl.exclude?("x/core")
384
+ assert fl.exclude?("x\\core")
385
+ end
386
+
387
+ def test_add_default_exclude_list
388
+ fl = FileList.new
389
+ fl.exclude(/~\d+$/)
390
+ assert fl.exclude?("x/CVS/y")
391
+ assert fl.exclude?("x\\CVS\\y")
392
+ assert fl.exclude?("x/.svn/y")
393
+ assert fl.exclude?("x\\.svn\\y")
394
+ assert fl.exclude?("x/core")
395
+ assert fl.exclude?("x\\core")
396
+ assert fl.exclude?("x/abc~1")
397
+ end
398
+
399
+ def test_basic_array_functions
400
+ f = FileList['b', 'c', 'a']
401
+ assert_equal 'b', f.first
402
+ assert_equal 'b', f[0]
403
+ assert_equal 'a', f.last
404
+ assert_equal 'a', f[2]
405
+ assert_equal 'a', f[-1]
406
+ assert_equal ['a', 'b', 'c'], f.sort
407
+ f.sort!
408
+ assert_equal ['a', 'b', 'c'], f
409
+ end
410
+
411
+ def test_flatten
412
+ assert_equal ['a', 'testdata/x.c', 'testdata/xyz.c', 'testdata/abc.c'].sort,
413
+ ['a', FileList['testdata/*.c']].flatten.sort
414
+ end
415
+
416
+ def test_clone_and_dup
417
+ a = FileList['a', 'b', 'c']
418
+ c = a.clone
419
+ d = a.dup
420
+ a << 'd'
421
+ assert_equal ['a', 'b', 'c', 'd'], a
422
+ assert_equal ['a', 'b', 'c'], c
423
+ assert_equal ['a', 'b', 'c'], d
424
+ end
425
+
426
+ def test_dup_and_clone_replicate_taint
427
+ a = FileList['a', 'b', 'c']
428
+ a.taint
429
+ c = a.clone
430
+ d = a.dup
431
+ assert c.tainted?, "Clone should be tainted"
432
+ assert d.tainted?, "Dup should be tainted"
433
+ end
434
+
435
+ def test_duped_items_will_thaw
436
+ a = FileList['a', 'b', 'c']
437
+ a.freeze
438
+ d = a.dup
439
+ d << 'more'
440
+ assert_equal ['a', 'b', 'c', 'more'], d
441
+ end
442
+
443
+ def test_cloned_items_stay_frozen
444
+ a = FileList['a', 'b', 'c']
445
+ a.freeze
446
+ c = a.clone
447
+ assert_exception(TypeError, RuntimeError) do
448
+ c << 'more'
449
+ end
450
+ end
451
+
452
+ def test_array_comparisons
453
+ fl = FileList['b', 'b']
454
+ a = ['b', 'a']
455
+ b = ['b', 'b']
456
+ c = ['b', 'c']
457
+ assert_equal( 1, fl <=> a )
458
+ assert_equal( 0, fl <=> b )
459
+ assert_equal( -1, fl <=> c )
460
+ assert_equal( -1, a <=> fl )
461
+ assert_equal( 0, b <=> fl )
462
+ assert_equal( 1, c <=> fl )
463
+ end
464
+
465
+ def test_array_equality
466
+ a = FileList['a', 'b']
467
+ b = ['a', 'b']
468
+ assert a == b
469
+ assert b == a
470
+ # assert a.eql?(b)
471
+ # assert b.eql?(a)
472
+ assert ! a.equal?(b)
473
+ assert ! b.equal?(a)
474
+ end
475
+
476
+ def test_enumeration_methods
477
+ a = FileList['a', 'b']
478
+ b = a.collect { |it| it.upcase }
479
+ assert_equal ['A', 'B'], b
480
+ assert_equal FileList, b.class
481
+
482
+ b = a.map { |it| it.upcase }
483
+ assert_equal ['A', 'B'], b
484
+ assert_equal FileList, b.class
485
+
486
+ b = a.sort
487
+ assert_equal ['a', 'b'], b
488
+ assert_equal FileList, b.class
489
+
490
+ b = a.sort_by { |it| it }
491
+ assert_equal ['a', 'b'], b
492
+ assert_equal FileList, b.class
493
+
494
+ b = a.find_all { |it| it == 'b'}
495
+ assert_equal ['b'], b
496
+ assert_equal FileList, b.class
497
+
498
+ b = a.select { |it| it.size == 1 }
499
+ assert_equal ['a', 'b'], b
500
+ assert_equal FileList, b.class
501
+
502
+ b = a.reject { |it| it == 'b' }
503
+ assert_equal ['a'], b
504
+ assert_equal FileList, b.class
505
+
506
+ b = a.grep(/./)
507
+ assert_equal ['a', 'b'], b
508
+ assert_equal FileList, b.class
509
+
510
+ b = a.partition { |it| it == 'b' }
511
+ assert_equal [['b'], ['a']], b
512
+ assert_equal Array, b.class
513
+ assert_equal FileList, b[0].class
514
+ assert_equal FileList, b[1].class
515
+
516
+ b = a.zip(['x', 'y']).to_a
517
+ assert_equal [['a', 'x'], ['b', 'y']], b
518
+ assert_equal Array, b.class
519
+ assert_equal Array, b[0].class
520
+ assert_equal Array, b[1].class
521
+ end
522
+
523
+ def test_array_operators
524
+ a = ['a', 'b']
525
+ b = ['c', 'd']
526
+ f = FileList['x', 'y']
527
+ g = FileList['w', 'z']
528
+
529
+ r = f + g
530
+ assert_equal ['x', 'y', 'w', 'z'], r
531
+ assert_equal FileList, r.class
532
+
533
+ r = a + g
534
+ assert_equal ['a', 'b', 'w', 'z'], r
535
+ assert_equal Array, r.class
536
+
537
+ r = f + b
538
+ assert_equal ['x', 'y', 'c', 'd'], r
539
+ assert_equal FileList, r.class
540
+
541
+ r = FileList['w', 'x', 'y', 'z'] - f
542
+ assert_equal ['w', 'z'], r
543
+ assert_equal FileList, r.class
544
+
545
+ r = FileList['w', 'x', 'y', 'z'] & f
546
+ assert_equal ['x', 'y'], r
547
+ assert_equal FileList, r.class
548
+
549
+ r = f * 2
550
+ assert_equal ['x', 'y', 'x', 'y'], r
551
+ assert_equal FileList, r.class
552
+
553
+ r = f * ','
554
+ assert_equal 'x,y', r
555
+ assert_equal String, r.class
556
+
557
+ r = f | ['a', 'x']
558
+ assert_equal ['a', 'x', 'y'].sort, r.sort
559
+ assert_equal FileList, r.class
560
+ end
561
+
562
+ def test_other_array_returning_methods
563
+ f = FileList['a', nil, 'b']
564
+ r = f.compact
565
+ assert_equal ['a', 'b'], r
566
+ assert_equal FileList, r.class
567
+
568
+ f = FileList['a', 'b']
569
+ r = f.concat(['x', 'y'])
570
+ assert_equal ['a', 'b', 'x', 'y'], r
571
+ assert_equal FileList, r.class
572
+
573
+ f = FileList['a', ['b', 'c'], FileList['d', 'e']]
574
+ r = f.flatten
575
+ assert_equal ['a', 'b', 'c', 'd', 'e'], r
576
+ assert_equal FileList, r.class
577
+
578
+ f = FileList['a', 'b', 'a']
579
+ r = f.uniq
580
+ assert_equal ['a', 'b'], r
581
+ assert_equal FileList, r.class
582
+
583
+ f = FileList['a', 'b', 'c', 'd']
584
+ r = f.values_at(1,3)
585
+ assert_equal ['b', 'd'], r
586
+ assert_equal FileList, r.class
587
+ end
588
+
589
+ def test_file_utils_can_use_filelists
590
+ cfiles = FileList['testdata/*.c']
591
+
592
+ cp cfiles, @cdir, :verbose => false
593
+
594
+ assert File.exist?(File.join(@cdir, 'abc.c'))
595
+ assert File.exist?(File.join(@cdir, 'xyz.c'))
596
+ assert File.exist?(File.join(@cdir, 'x.c'))
597
+ end
598
+
599
+ def create_test_data
600
+ verbose(false) do
601
+
602
+ mkdir "testdata" unless File.exist? "testdata"
603
+ mkdir "testdata/CVS" rescue nil
604
+ mkdir "testdata/.svn" rescue nil
605
+ @cdir = "testdata/cfiles"
606
+ mkdir @cdir rescue nil
607
+ touch "testdata/.dummy"
608
+ touch "testdata/x.bak"
609
+ touch "testdata/x~"
610
+ touch "testdata/core"
611
+ touch "testdata/x.c"
612
+ touch "testdata/xyz.c"
613
+ touch "testdata/abc.c"
614
+ touch "testdata/abc.h"
615
+ touch "testdata/abc.x"
616
+ touch "testdata/existing"
617
+ end
618
+ end
619
+
620
+ end