rant 0.4.8 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +31 -0
- data/README +3 -1
- data/Rantfile +53 -2
- data/doc/advanced.rdoc +86 -1
- data/doc/c.rdoc +8 -0
- data/doc/homepage/index.html +2 -0
- data/doc/rant.1 +4 -0
- data/doc/rant.rdoc +38 -0
- data/doc/rant_vs_rake.rdoc +13 -0
- data/doc/rantfile.rdoc +93 -63
- data/doc/sys.rdoc +568 -0
- data/lib/rant/coregen.rb +43 -16
- data/lib/rant/import/command.rb +7 -4
- data/lib/rant/import/filelist/more.rb +57 -0
- data/lib/rant/import/metadata.rb +5 -1
- data/lib/rant/import/nodes/default.rb +3 -24
- data/lib/rant/import/signedfile.rb +1 -8
- data/lib/rant/import/sys/more.rb +2 -1
- data/lib/rant/import/var/booleans.rb +65 -0
- data/lib/rant/import/var/lists.rb +34 -0
- data/lib/rant/import/var/numbers.rb +116 -0
- data/lib/rant/import/var/strings.rb +43 -0
- data/lib/rant/import.rb +19 -3
- data/lib/rant/node.rb +39 -6
- data/lib/rant/rantlib.rb +44 -8
- data/lib/rant/rantsys.rb +22 -54
- data/lib/rant/rantvar.rb +89 -256
- data/misc/TODO +18 -0
- data/misc/devel-notes +26 -1
- data/test/action.rant +24 -0
- data/test/deprecated/test_0_5_4.rb +53 -0
- data/test/deprecated/test_0_6_0.rb +1 -1
- data/test/dryrun/Rantfile +10 -0
- data/test/dryrun/foo.c +8 -0
- data/test/dryrun/test_dryrun.rb +31 -0
- data/test/import/c/dependencies/Rantfile +1 -1
- data/test/import/command/Rantfile +1 -1
- data/test/import/sys/test_tgz.rb +22 -0
- data/test/subdirs2/root.rant +11 -1
- data/test/subdirs2/sub1/sub.rant +3 -0
- data/test/subdirs2/test_subdirs2.rb +19 -0
- data/test/test_action.rb +75 -0
- data/test/test_filelist.rb +13 -10
- data/test/test_rant_interface.rb +2 -2
- data/test/test_rule.rb +121 -3
- data/test/test_sys_methods.rb +558 -0
- data/test/test_var.rb +10 -0
- data/test/tutil.rb +81 -8
- metadata +19 -2
@@ -0,0 +1,558 @@
|
|
1
|
+
|
2
|
+
require 'test/unit'
|
3
|
+
require 'tutil'
|
4
|
+
require 'rant/import/sys/more'
|
5
|
+
|
6
|
+
$testDir ||= File.expand_path(File.dirname(__FILE__))
|
7
|
+
|
8
|
+
class TestSysMethods < Test::Unit::TestCase
|
9
|
+
include Rant::TestUtil
|
10
|
+
def setup
|
11
|
+
# Ensure we run in test directory.
|
12
|
+
Dir.chdir($testDir)
|
13
|
+
@rant = Rant::RantApp.new
|
14
|
+
@cx = @rant.cx
|
15
|
+
@sys = @cx.sys
|
16
|
+
end
|
17
|
+
def teardown
|
18
|
+
Dir.chdir($testDir)
|
19
|
+
Rant::Sys.rm_rf "t"
|
20
|
+
Rant::Sys.rm_rf Rant::FileList["*.t"]
|
21
|
+
end
|
22
|
+
def test_pwd
|
23
|
+
assert_equal Dir.pwd, @sys.pwd
|
24
|
+
end
|
25
|
+
def test_cd__mkdir_single_str__pwd__rmdir_single_empty_dir
|
26
|
+
out, err = capture_std do
|
27
|
+
assert_nothing_raised do
|
28
|
+
@sys.mkdir "t"
|
29
|
+
assert(test(?d, "t"))
|
30
|
+
@sys.cd "t"
|
31
|
+
assert_equal(File.join($testDir, "t"), @sys.pwd)
|
32
|
+
@sys.cd ".."
|
33
|
+
assert_equal($testDir, @sys.pwd)
|
34
|
+
@sys.rmdir "t"
|
35
|
+
assert(!test(?e, "t"))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
assert err.empty?
|
39
|
+
lines = out.split(/\n/)
|
40
|
+
assert_equal 4, lines.size
|
41
|
+
assert_match(/mkdir\s+t/, lines[0])
|
42
|
+
assert_match(/cd\s+t/, lines[1])
|
43
|
+
assert_match(/cd\s+/, lines[2])
|
44
|
+
assert_match(/rmdir\s+t/, lines[3])
|
45
|
+
end
|
46
|
+
def test_cd_absolute_path_with_block
|
47
|
+
out, err = capture_std do
|
48
|
+
assert_raise(RuntimeError) do
|
49
|
+
@sys.mkdir "t"
|
50
|
+
@sys.cd(File.join($testDir, "t")) do
|
51
|
+
assert_equal(File.join($testDir, "t"), @sys.pwd)
|
52
|
+
raise
|
53
|
+
end
|
54
|
+
end
|
55
|
+
assert_equal $testDir, @sys.pwd
|
56
|
+
end
|
57
|
+
assert err.empty?
|
58
|
+
lines = out.split(/\n/)
|
59
|
+
assert_match(/mkdir\s+t/, lines[0])
|
60
|
+
assert_match(/cd\s.*t/, lines[1])
|
61
|
+
end
|
62
|
+
def test_mkdir_array__rmdir_array
|
63
|
+
out, err = capture_std do
|
64
|
+
assert_nothing_raised do
|
65
|
+
@sys.mkdir ["foo.t", File.join($testDir, "bar.t")]
|
66
|
+
assert test(?d, "foo.t")
|
67
|
+
assert test(?d, "bar.t")
|
68
|
+
assert_raise_kind_of(SystemCallError) do
|
69
|
+
@sys.mkdir "foo.t"
|
70
|
+
end
|
71
|
+
assert test(?d, "foo.t")
|
72
|
+
@sys.rmdir [File.join($testDir, "foo.t")]
|
73
|
+
assert !test(?e, "foo.t")
|
74
|
+
@sys.rmdir @sys["*.t"]
|
75
|
+
assert !test(?e, "bar.t")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
assert err.empty?
|
79
|
+
lines = out.split(/\n/)
|
80
|
+
assert_equal 4, lines.size
|
81
|
+
assert_match(/mkdir.*foo\.t.*bar\.t/, lines[0])
|
82
|
+
assert_match(/mkdir.*foo\.t/, lines[1])
|
83
|
+
assert_match(/rmdir.*foo\.t/, lines[2])
|
84
|
+
assert_match(/rmdir.*bar\.t/, lines[3])
|
85
|
+
end
|
86
|
+
def test_plain_cp
|
87
|
+
open "a.t", "wb" do |f|
|
88
|
+
f << "a\nb\rc\n\rd\r\n"
|
89
|
+
end
|
90
|
+
out, err = capture_std do
|
91
|
+
assert_nothing_raised do
|
92
|
+
@sys.cp "a.t", "b.t"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
assert test(?f, "b.t")
|
96
|
+
ca = File.open("a.t", "rb") { |f| f.read }
|
97
|
+
cb = File.open("b.t", "rb") { |f| f.read }
|
98
|
+
assert_equal ca, "a\nb\rc\n\rd\r\n"
|
99
|
+
assert_equal ca, cb
|
100
|
+
assert err.empty?
|
101
|
+
lines = out.split(/\n/)
|
102
|
+
assert_equal 1, lines.size
|
103
|
+
assert_match(/cp\s+a\.t\s+b\.t/, lines[0])
|
104
|
+
end
|
105
|
+
def test_cp_filelist_to_dir
|
106
|
+
open "a.t", "wb" do |f|
|
107
|
+
f << "a\nb\rc\n\rd\r\n"
|
108
|
+
end
|
109
|
+
out, err = capture_std do
|
110
|
+
assert_nothing_raised do
|
111
|
+
@sys.cp "a.t", "b.t"
|
112
|
+
@sys.mkdir "t"
|
113
|
+
@sys.cp @sys["*.t"], "t"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
assert test(?f, "b.t")
|
117
|
+
assert test(?f, "t/a.t")
|
118
|
+
assert test(?f, "t/b.t")
|
119
|
+
ca = File.open("t/a.t", "rb") { |f| f.read }
|
120
|
+
cb = File.open("t/b.t", "rb") { |f| f.read }
|
121
|
+
assert_equal ca, "a\nb\rc\n\rd\r\n"
|
122
|
+
assert_equal ca, cb
|
123
|
+
assert err.empty?
|
124
|
+
lines = out.split(/\n/)
|
125
|
+
assert_equal 3, lines.size
|
126
|
+
assert_match(/cp\s+a\.t\s+b\.t/, lines[0])
|
127
|
+
assert_match(/mkdir\s+t/, lines[1])
|
128
|
+
assert_match(/cp\s+a\.t\s+b\.t\s+t/, lines[2])
|
129
|
+
end
|
130
|
+
def test_cp_dir_fail
|
131
|
+
out, err = capture_std do
|
132
|
+
@sys.mkdir "t"
|
133
|
+
assert test(?d, "t")
|
134
|
+
assert_raise_kind_of(SystemCallError) do
|
135
|
+
@sys.cp "t", "a.t"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
#assert !test(?e, "a.t") # TODO
|
139
|
+
assert err.empty?
|
140
|
+
lines = out.split(/\n/)
|
141
|
+
assert_equal(2, lines.size)
|
142
|
+
end
|
143
|
+
def test_cp_r_like_cp
|
144
|
+
open "a.t", "wb" do |f|
|
145
|
+
f << "a\nb\rc\n\rd\r\n"
|
146
|
+
end
|
147
|
+
out, err = capture_std do
|
148
|
+
assert_nothing_raised do
|
149
|
+
@sys.cp_r "a.t", "b.t"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
assert test(?f, "b.t")
|
153
|
+
ca = File.open("a.t", "rb") { |f| f.read }
|
154
|
+
cb = File.open("b.t", "rb") { |f| f.read }
|
155
|
+
assert_equal ca, "a\nb\rc\n\rd\r\n"
|
156
|
+
assert_equal ca, cb
|
157
|
+
assert err.empty?
|
158
|
+
lines = out.split(/\n/)
|
159
|
+
assert_equal 1, lines.size
|
160
|
+
assert_match(/cp -r\s+a\.t\s+b\.t/, lines[0])
|
161
|
+
end
|
162
|
+
def test_cp_r
|
163
|
+
out, err = capture_std do
|
164
|
+
@sys.mkdir "a.t"
|
165
|
+
@sys.mkdir "t"
|
166
|
+
open "a.t/a", "wb" do |f|
|
167
|
+
f << "a\nb\rc\n\rd\r\n"
|
168
|
+
end
|
169
|
+
@sys.touch "b.t"
|
170
|
+
assert_nothing_raised do
|
171
|
+
@sys.cp_r @sys["*.t"], "t"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
assert test(?d, "t/a.t")
|
175
|
+
ca = File.open("t/a.t/a", "rb") { |f| f.read }
|
176
|
+
assert_equal ca, "a\nb\rc\n\rd\r\n"
|
177
|
+
assert test(?f, "t/b.t")
|
178
|
+
assert test(?d, "a.t")
|
179
|
+
assert test(?f, "a.t/a")
|
180
|
+
assert test(?f, "b.t")
|
181
|
+
lines = out.split(/\n/)
|
182
|
+
assert_equal 4, lines.size
|
183
|
+
assert_match(/cp -r\s.*t/, lines[3])
|
184
|
+
end
|
185
|
+
def test_plain_mv
|
186
|
+
open "a.t", "wb" do |f|
|
187
|
+
f << "a\nb\rc\n\rd\r\n"
|
188
|
+
end
|
189
|
+
out, err = capture_std do
|
190
|
+
assert_nothing_raised do
|
191
|
+
@sys.mv "a.t", "b.t"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
assert test(?f, "b.t")
|
195
|
+
assert !test(?e, "a.t")
|
196
|
+
cb = File.open("b.t", "rb") { |f| f.read }
|
197
|
+
assert_equal cb, "a\nb\rc\n\rd\r\n"
|
198
|
+
assert err.empty?
|
199
|
+
lines = out.split(/\n/)
|
200
|
+
assert_equal 1, lines.size
|
201
|
+
assert_match(/mv\s+a\.t\s+b\.t/, lines[0])
|
202
|
+
end
|
203
|
+
def test_mv_dirs_and_files
|
204
|
+
out, err = capture_std do
|
205
|
+
@sys.mkdir "a.t"
|
206
|
+
@sys.mkdir "t"
|
207
|
+
@sys.touch "a.t/a"
|
208
|
+
@sys.touch "b.t"
|
209
|
+
assert_nothing_raised do
|
210
|
+
@sys.mv @sys["*.t"], "t"
|
211
|
+
end
|
212
|
+
end
|
213
|
+
assert test(?d, "t/a.t")
|
214
|
+
assert test(?f, "t/a.t/a")
|
215
|
+
assert test(?f, "t/b.t")
|
216
|
+
assert !test(?e, "a.t")
|
217
|
+
assert !test(?e, "b.t")
|
218
|
+
lines = out.split(/\n/)
|
219
|
+
assert_equal 5, lines.size
|
220
|
+
end
|
221
|
+
def test_plain_rm
|
222
|
+
out, err = capture_std do
|
223
|
+
@sys.touch "a.t"
|
224
|
+
assert test(?f, "a.t")
|
225
|
+
@sys.rm "a.t"
|
226
|
+
assert !test(?e, "a.t")
|
227
|
+
assert_raise_kind_of(SystemCallError) do
|
228
|
+
@sys.rm "a.t"
|
229
|
+
end
|
230
|
+
end
|
231
|
+
assert err.empty?
|
232
|
+
lines = out.split(/\n/)
|
233
|
+
assert_equal 3, lines.size
|
234
|
+
assert_match(/rm\s+a\.t/, lines[1])
|
235
|
+
end
|
236
|
+
def test_rm_dir_fail
|
237
|
+
out, err = capture_std do
|
238
|
+
@sys.mkdir "a.t"
|
239
|
+
assert test(?d, "a.t")
|
240
|
+
assert_raise_kind_of(SystemCallError) do
|
241
|
+
@sys.rm "a.t"
|
242
|
+
end
|
243
|
+
assert test(?d, "a.t")
|
244
|
+
end
|
245
|
+
end
|
246
|
+
def test_rm_filelist__touch_array
|
247
|
+
out, err = capture_std do
|
248
|
+
@sys.touch ["a.t", "b.t"]
|
249
|
+
assert test(?f, "a.t")
|
250
|
+
assert test(?f, "b.t")
|
251
|
+
@sys.rm @sys["*.t"]
|
252
|
+
assert !test(?e, "a.t")
|
253
|
+
assert !test(?e, "b.t")
|
254
|
+
end
|
255
|
+
assert err.empty?
|
256
|
+
lines = out.split(/\n/)
|
257
|
+
assert_equal 2, lines.size
|
258
|
+
end
|
259
|
+
def test_rm_f
|
260
|
+
out, err = capture_std do
|
261
|
+
@sys.touch "a.t"
|
262
|
+
assert test(?f, "a.t")
|
263
|
+
@sys.rm_f "a.t"
|
264
|
+
assert !test(?e, "a.t")
|
265
|
+
assert_nothing_raised do
|
266
|
+
@sys.rm_f "a.t"
|
267
|
+
@sys.rm_f ["a.t", "b.t"]
|
268
|
+
end
|
269
|
+
end
|
270
|
+
assert err.empty?
|
271
|
+
lines = out.split(/\n/)
|
272
|
+
assert_equal 4, lines.size
|
273
|
+
assert_match(/rm -f\s+a\.t/, lines[1])
|
274
|
+
end
|
275
|
+
def test_rm_r_dir__rm_r_fail_not_exist
|
276
|
+
out, err = capture_std do
|
277
|
+
@sys.mkdir "t"
|
278
|
+
@sys.touch "t/a"
|
279
|
+
@sys.mkdir "t/sub"
|
280
|
+
assert_nothing_raised do
|
281
|
+
@sys.rm_r "t"
|
282
|
+
end
|
283
|
+
assert !test(?e, "t")
|
284
|
+
assert_raise_kind_of(SystemCallError) do
|
285
|
+
@sys.rm_r "t"
|
286
|
+
end
|
287
|
+
end
|
288
|
+
assert err.empty?
|
289
|
+
lines = out.split(/\n/)
|
290
|
+
assert_equal 5, lines.size
|
291
|
+
assert_match(/rm -r\s+t/, lines[3])
|
292
|
+
end
|
293
|
+
def test_rm_rf
|
294
|
+
out, err = capture_std do
|
295
|
+
@sys.mkdir "t"
|
296
|
+
@sys.touch "t/a"
|
297
|
+
@sys.mkdir "t/sub"
|
298
|
+
assert_nothing_raised do
|
299
|
+
@sys.rm_rf "t"
|
300
|
+
end
|
301
|
+
assert !test(?e, "t")
|
302
|
+
assert_nothing_raised do
|
303
|
+
@sys.rm_rf "t"
|
304
|
+
end
|
305
|
+
end
|
306
|
+
assert err.empty?
|
307
|
+
lines = out.split(/\n/)
|
308
|
+
assert_equal 5, lines.size
|
309
|
+
assert_match(/rm -rf\s+t/, lines[3])
|
310
|
+
end
|
311
|
+
=begin
|
312
|
+
# TODO, but tested indirectly in many other tests anyway
|
313
|
+
def test_touch
|
314
|
+
end
|
315
|
+
=end
|
316
|
+
def test_safe_ln
|
317
|
+
open "a.t", "wb" do |f|
|
318
|
+
f << "a\nb\rc\n\rd\r\n"
|
319
|
+
end
|
320
|
+
out, err = capture_std do
|
321
|
+
assert_nothing_raised do
|
322
|
+
@sys.safe_ln "a.t", "b.t"
|
323
|
+
end
|
324
|
+
end
|
325
|
+
assert test(?f, "b.t")
|
326
|
+
ca = File.open("a.t", "rb") { |f| f.read }
|
327
|
+
cb = File.open("b.t", "rb") { |f| f.read }
|
328
|
+
assert_equal ca, "a\nb\rc\n\rd\r\n"
|
329
|
+
assert_equal ca, cb
|
330
|
+
assert err.empty?
|
331
|
+
lines = out.split(/\n/)
|
332
|
+
assert lines.size == 1 || lines.size == 2
|
333
|
+
assert_match(/(ln|cp)\s+a\.t\s+b\.t/, lines[-1])
|
334
|
+
lines[-1] =~ /(ln|cp)\s+a\.t\s+b\.t/
|
335
|
+
puts "\n*** hardlinks #{$1 == "ln" ? "" : "not"} supported ***"
|
336
|
+
if $1 == "ln"
|
337
|
+
assert test_hardlink("a.t", "b.t", :allow_write => true)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
def test_compare_file
|
341
|
+
open "a.t", "wb" do |f|
|
342
|
+
f << "a\nb\rc\n\rd\r\n"
|
343
|
+
end
|
344
|
+
open "b.t", "wb" do |f|
|
345
|
+
f << "a\nb\rc\n\rd\r\n"
|
346
|
+
end
|
347
|
+
assert @sys.compare_file("a.t", "b.t")
|
348
|
+
end
|
349
|
+
def test_compare_file_binary?
|
350
|
+
# probably not the right test...
|
351
|
+
open "a.t", "wb" do |f|
|
352
|
+
f << "a\nb\rc\n\rd\r\n"
|
353
|
+
end
|
354
|
+
open "b.t", "wb" do |f|
|
355
|
+
f << "a\nb\rc\n\rd\n"
|
356
|
+
end
|
357
|
+
assert !@sys.compare_file("a.t", "b.t")
|
358
|
+
end
|
359
|
+
def test_compare_empty_files
|
360
|
+
Rant::Sys.touch "a.t"
|
361
|
+
Rant::Sys.touch "b.t"
|
362
|
+
assert @sys.compare_file("a.t", "b.t")
|
363
|
+
end
|
364
|
+
def test_ln__ln_f
|
365
|
+
Rant::Sys.write_to_file "a.t", "abc\n"
|
366
|
+
e = nil
|
367
|
+
out, err = capture_std do
|
368
|
+
begin
|
369
|
+
@sys.ln "a.t", "b.t"
|
370
|
+
rescue Exception => e
|
371
|
+
puts "\n*** hard links not supported ***"
|
372
|
+
assert(e.kind_of?(SystemCallError) ||
|
373
|
+
e.kind_of?(NotImplementedError),
|
374
|
+
"exception Errno::EOPNOTSUPP " +
|
375
|
+
"expected but #{e.class} risen")
|
376
|
+
end
|
377
|
+
end
|
378
|
+
if e
|
379
|
+
assert !test(?e, "b.t")
|
380
|
+
else
|
381
|
+
#assert test(?-, "b.t", "a.t")
|
382
|
+
assert test_hardlink("a.t", "b.t")
|
383
|
+
assert !test(?l, "b.t") # shouldn't be necessary
|
384
|
+
assert_file_content "b.t", "abc\n"
|
385
|
+
assert err.empty?
|
386
|
+
lines = out.split(/\n/)
|
387
|
+
assert_equal 1, lines.size
|
388
|
+
assert_match(/ln\s+a\.t\s+b\.t/, lines[0])
|
389
|
+
|
390
|
+
# further tests
|
391
|
+
|
392
|
+
Rant::Sys.mkdir "t"
|
393
|
+
out, err = capture_std do
|
394
|
+
assert_nothing_raised do
|
395
|
+
@sys.ln "a.t", "t"
|
396
|
+
end
|
397
|
+
end
|
398
|
+
#assert test(?-, "t/a.t", "a.t")
|
399
|
+
assert test_hardlink("t/a.t", "a.t")
|
400
|
+
assert_file_content "t/a.t", "abc\n"
|
401
|
+
|
402
|
+
Rant::Sys.touch "c.t"
|
403
|
+
capture_std do
|
404
|
+
assert_raise_kind_of(SystemCallError) do
|
405
|
+
@sys.ln "a.t", "c.t"
|
406
|
+
end
|
407
|
+
end
|
408
|
+
#assert !test(?-, "c.t", "a.t")
|
409
|
+
assert !test_hardlink("c.t", "a.t")
|
410
|
+
assert_file_content "c.t", ""
|
411
|
+
|
412
|
+
capture_std do
|
413
|
+
assert_nothing_raised do
|
414
|
+
@sys.ln_f "a.t", "c.t"
|
415
|
+
end
|
416
|
+
end
|
417
|
+
#assert test(?-, "c.t", "a.t")
|
418
|
+
assert test_hardlink("c.t", "a.t")
|
419
|
+
assert_file_content "c.t", "abc\n"
|
420
|
+
end
|
421
|
+
end
|
422
|
+
def test_ln_s__ln_sf
|
423
|
+
Rant::Sys.write_to_file "a.t", "abc\n"
|
424
|
+
e = nil
|
425
|
+
out, err = capture_std do
|
426
|
+
begin
|
427
|
+
@sys.ln_s "a.t", "b.t"
|
428
|
+
rescue Exception => e
|
429
|
+
puts "\n*** symbolic links not supported ***"
|
430
|
+
# TODO: raises NotImplementedError on WinXP/NTFS/ruby-1.8.2
|
431
|
+
assert(e.kind_of?(SystemCallError) ||
|
432
|
+
e.kind_of?(NotImplementedError),
|
433
|
+
"exception Errno::EOPNOTSUPP " +
|
434
|
+
"expected but #{e.class} risen")
|
435
|
+
end
|
436
|
+
end
|
437
|
+
if e
|
438
|
+
assert !test(?e, "b.t")
|
439
|
+
else
|
440
|
+
assert test(?l, "b.t")
|
441
|
+
assert_file_content "b.t", "abc\n"
|
442
|
+
assert err.empty?
|
443
|
+
lines = out.split(/\n/)
|
444
|
+
assert_equal 1, lines.size
|
445
|
+
assert_match(/ln -s\s+a\.t\s+b\.t/, lines[0])
|
446
|
+
|
447
|
+
# further tests
|
448
|
+
|
449
|
+
Rant::Sys.mkdir "t"
|
450
|
+
out, err = capture_std do
|
451
|
+
assert_nothing_raised do
|
452
|
+
@sys.ln_s File.expand_path("a.t"), "t"
|
453
|
+
end
|
454
|
+
end
|
455
|
+
assert test(?l, "t/a.t")
|
456
|
+
assert_file_content "t/a.t", "abc\n"
|
457
|
+
|
458
|
+
Rant::Sys.touch "c.t"
|
459
|
+
capture_std do
|
460
|
+
assert_raise_kind_of(SystemCallError) do
|
461
|
+
@sys.ln_s "a.t", "c.t"
|
462
|
+
end
|
463
|
+
end
|
464
|
+
assert !test(?l, "c.t")
|
465
|
+
assert_file_content "c.t", ""
|
466
|
+
|
467
|
+
capture_std do
|
468
|
+
assert_nothing_raised do
|
469
|
+
@sys.ln_sf "a.t", "c.t"
|
470
|
+
end
|
471
|
+
end
|
472
|
+
assert test(?l, "c.t")
|
473
|
+
assert_file_content "c.t", "abc\n"
|
474
|
+
end
|
475
|
+
end
|
476
|
+
def test_uptodate?
|
477
|
+
assert !@sys.uptodate?("a.t", [])
|
478
|
+
Rant::Sys.touch "a.t"
|
479
|
+
assert @sys.uptodate?("a.t", [])
|
480
|
+
timeout
|
481
|
+
Rant::Sys.touch "b.t"
|
482
|
+
assert !@sys.uptodate?("a.t", @sys.glob("*.t").exclude("a.t"))
|
483
|
+
Rant::Sys.touch ["a.t", "b.t"]
|
484
|
+
assert !@sys.uptodate?("a.t", ["b.t"])
|
485
|
+
timeout
|
486
|
+
Rant::Sys.touch "a.t"
|
487
|
+
assert @sys.uptodate?("a.t", ["b.t"])
|
488
|
+
Rant::Sys.touch "c.t"
|
489
|
+
assert !@sys.uptodate?("a.t", ["c.t", "b.t"])
|
490
|
+
end
|
491
|
+
def test_install
|
492
|
+
# TODO: more tests, especially option testing
|
493
|
+
Rant::Sys.mkdir "t"
|
494
|
+
Rant::Sys.mkdir ["lib.t", "lib.t/a"]
|
495
|
+
Rant::Sys.touch ["lib.t/a.s", "lib.t/a/b.s"]
|
496
|
+
out, err = capture_std do
|
497
|
+
Rant::Sys.cd "lib.t" do
|
498
|
+
assert_nothing_raised do
|
499
|
+
@sys.install @sys.glob("**/*").no_dir, "#$testDir/t"
|
500
|
+
end
|
501
|
+
end
|
502
|
+
end
|
503
|
+
assert err.empty?
|
504
|
+
assert !out.empty? # TODO: more accurate
|
505
|
+
assert_file_content "t/a.s", ""
|
506
|
+
assert_file_content "t/b.s", ""
|
507
|
+
end
|
508
|
+
def test_mkdir_p
|
509
|
+
out, err = capture_std do
|
510
|
+
assert_nothing_raised do
|
511
|
+
@sys.mkdir_p "t"
|
512
|
+
assert test(?d, "t")
|
513
|
+
@sys.mkdir_p "t/t1/t2/t3"
|
514
|
+
assert test(?d, "t/t1/t2/t3")
|
515
|
+
@sys.mkdir_p ["#$testDir/tt/a", "ttt/a/b/c"]
|
516
|
+
assert test(?d, "tt/a")
|
517
|
+
assert test(?d, "ttt/a/b/c")
|
518
|
+
end
|
519
|
+
end
|
520
|
+
assert err.empty?
|
521
|
+
lines = out.split(/\n/)
|
522
|
+
assert_equal 3, lines.size
|
523
|
+
assert_match(/mkdir -p\s+t/, lines[0])
|
524
|
+
ensure
|
525
|
+
Rant::Sys.rm_rf ["tt", "ttt"]
|
526
|
+
end
|
527
|
+
def test_chmod
|
528
|
+
# TODO
|
529
|
+
Rant::Sys.touch "a.t"
|
530
|
+
out, err = capture_std do
|
531
|
+
assert_nothing_raised do
|
532
|
+
@sys.chmod 0755, "a.t"
|
533
|
+
end
|
534
|
+
end
|
535
|
+
assert err.empty?
|
536
|
+
lines = out.split(/\n/)
|
537
|
+
assert_equal 1, lines.size
|
538
|
+
assert_match(/chmod 0?755 a\.t/, lines[0])
|
539
|
+
s = File.stat("a.t")
|
540
|
+
unless (s.mode & 0777) == 0755
|
541
|
+
puts "\n***chmod 0755 not fully functional (actual: #{s.mode.to_s(8)}) ***"
|
542
|
+
end
|
543
|
+
end
|
544
|
+
def test_write_to_file
|
545
|
+
@cx.import "sys/more"
|
546
|
+
capture_std do
|
547
|
+
# TODO: specialize exception class
|
548
|
+
assert_raise_kind_of(StandardError) do
|
549
|
+
@sys.write_to_file "a.t", Object.new
|
550
|
+
end
|
551
|
+
end
|
552
|
+
assert !test(?e, "a.t")
|
553
|
+
out, err = capture_std do
|
554
|
+
@sys.write_to_file "a.t", "hello\n"
|
555
|
+
end
|
556
|
+
assert_file_content "a.t", "hello\n"
|
557
|
+
end
|
558
|
+
end
|
data/test/test_var.rb
CHANGED
@@ -275,4 +275,14 @@ class TestVar < Test::Unit::TestCase
|
|
275
275
|
ensure
|
276
276
|
assert_equal(0, Rant::RantApp.new.run("-fvar.rf", "clean", "-q"))
|
277
277
|
end
|
278
|
+
def test_rant_import
|
279
|
+
@rac.args.replace %w(-fvar.rf show_num)
|
280
|
+
run_import "-q", "ant.t"
|
281
|
+
assert_exit
|
282
|
+
out = run_ruby("ant.t", "-fvar.rf", "show_num")
|
283
|
+
assert_exit
|
284
|
+
assert_match(/num 1.1/, out)
|
285
|
+
ensure
|
286
|
+
Rant::Sys.rm_f "ant.t"
|
287
|
+
end
|
278
288
|
end
|
data/test/tutil.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
|
2
2
|
# This file contains methods that aid in testing Rant.
|
3
3
|
|
4
|
+
$-w = true
|
5
|
+
|
4
6
|
require 'rant/rantlib'
|
5
7
|
require 'rant/import/sys/tgz'
|
6
8
|
require 'rant/import/sys/zip'
|
@@ -13,6 +15,8 @@ module Test
|
|
13
15
|
res = 0
|
14
16
|
capture = true
|
15
17
|
newproc = false
|
18
|
+
tmax_1 = false
|
19
|
+
out, err = nil, nil
|
16
20
|
args.flatten!
|
17
21
|
args.reject! { |arg|
|
18
22
|
if Symbol === arg
|
@@ -21,6 +25,7 @@ module Test
|
|
21
25
|
when :v: capture = false
|
22
26
|
when :verbose: capture = false
|
23
27
|
when :x: newproc = true
|
28
|
+
when :tmax_1: tmax_1 = true
|
24
29
|
else
|
25
30
|
raise "No such option -- #{arg}"
|
26
31
|
end
|
@@ -40,16 +45,30 @@ module Test
|
|
40
45
|
end
|
41
46
|
assert_equal(res, $?.exitstatus)
|
42
47
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
action = lambda {
|
49
|
+
if capture
|
50
|
+
out, err = capture_std do
|
51
|
+
assert_equal(res, ::Rant::RantApp.new.run(*args))
|
52
|
+
end
|
53
|
+
else
|
54
|
+
assert_equal(res, ::Rant::RantApp.new.run(*args))
|
55
|
+
end
|
56
|
+
}
|
57
|
+
if tmax_1
|
58
|
+
th = Thread.new(&action)
|
59
|
+
unless th.join(1)
|
60
|
+
th.kill
|
61
|
+
assert(false,
|
62
|
+
"execution aborted after 1 second")
|
63
|
+
end
|
64
|
+
else
|
65
|
+
action.call
|
66
|
+
end
|
67
|
+
return out, err
|
50
68
|
end
|
51
69
|
def assert_exit(status = 0)
|
52
|
-
assert_equal(status, $?.exitstatus
|
70
|
+
assert_equal(status, $?.exitstatus,
|
71
|
+
"exit status expected to be #{status} but is #{$?.exitstatus}")
|
53
72
|
end
|
54
73
|
def assert_file_content(fn, content, *opts)
|
55
74
|
assert(test(?f, fn), "`#{fn}' doesn't exist")
|
@@ -64,6 +83,21 @@ module Test
|
|
64
83
|
assert_raises(*args, &block)
|
65
84
|
end
|
66
85
|
end
|
86
|
+
def assert_raise_kind_of(klass)
|
87
|
+
e = nil
|
88
|
+
begin
|
89
|
+
yield
|
90
|
+
rescue Exception => e
|
91
|
+
end
|
92
|
+
if e.nil?
|
93
|
+
flunk("Exception `#{klass}' expected but non risen.")
|
94
|
+
else
|
95
|
+
unless e.kind_of? klass
|
96
|
+
flunk("Exception `#{klass}' expected " +
|
97
|
+
"but `#{e.class}' thrown")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
67
101
|
end # class TestCase
|
68
102
|
end # module Unit
|
69
103
|
end # module Test
|
@@ -221,6 +255,7 @@ def extract_requires(script, dynamic_requires = [])
|
|
221
255
|
end
|
222
256
|
|
223
257
|
module Rant::TestUtil
|
258
|
+
TEST_HARDLINK_BROKEN = Rant::Env.on_windows? && RUBY_VERSION < "1.8.4"
|
224
259
|
def in_local_temp_dir(dirname = "t")
|
225
260
|
dirname = dirname.dup
|
226
261
|
base_dir = Dir.pwd
|
@@ -237,5 +272,43 @@ module Rant::TestUtil
|
|
237
272
|
f.write content
|
238
273
|
end
|
239
274
|
end
|
275
|
+
# replacement for core <tt>test(?-, a, b)</tt> which is eventually
|
276
|
+
# corrupted
|
277
|
+
if TEST_HARDLINK_BROKEN
|
278
|
+
def test_hardlink(a, b, opts = {})
|
279
|
+
# test(?-, a, b) corrupt in ruby < 1.8.4 (final)
|
280
|
+
# on Windows
|
281
|
+
|
282
|
+
unless defined? @@corrupt_test_hardlink_msg
|
283
|
+
@@corrupt_test_hardlink_msg = true
|
284
|
+
puts "\n*** Ruby core test for hardlinks " +
|
285
|
+
"[test(?-, file1, file2)] considered broken. Using heuristics for unit tests. ***"
|
286
|
+
end
|
287
|
+
|
288
|
+
# Use some heuristic instead.
|
289
|
+
if test(?l, a)
|
290
|
+
return test(?l, b) &&
|
291
|
+
File.readlink(a) == File.readlink(b)
|
292
|
+
else
|
293
|
+
return false if test(?l, b)
|
294
|
+
end
|
295
|
+
content = File.read(a)
|
296
|
+
return false unless File.read(b) == content
|
297
|
+
if opts[:allow_write]
|
298
|
+
if content.size > 1
|
299
|
+
Rant::TestUtil.write_to_file(a, content[0])
|
300
|
+
else
|
301
|
+
Rant::TestUtil.write_to_file(a, "hardlink test\n")
|
302
|
+
end
|
303
|
+
File.read(a) == File.read(b)
|
304
|
+
else
|
305
|
+
true
|
306
|
+
end
|
307
|
+
end
|
308
|
+
else
|
309
|
+
def test_hardlink(a, b, opts = {})
|
310
|
+
test(?-, a, b)
|
311
|
+
end
|
312
|
+
end
|
240
313
|
extend self
|
241
314
|
end
|