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