ruby_ex 0.4.6.2 → 0.5.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +17 -0
- data/README +1 -0
- data/SPEC.gemspec +14 -0
- data/SPEC.yml +10 -6
- data/lib/abstract.rb +3 -4
- data/lib/d_logger.rb +3 -3
- data/lib/drb/observable_pool.rb +5 -2
- data/lib/drb_ex.rb +1 -6
- data/lib/exp_mod.rb +48 -0
- data/lib/file_type.rb +82 -97
- data/lib/kill_all.rb +3 -3
- data/lib/{module → module_extensions}/autoload_tree.rb +5 -10
- data/lib/{module → module_extensions}/hierarchy.rb +11 -5
- data/lib/{module → module_extensions}/instance_method_visibility.rb +7 -5
- data/lib/{ordered_hash.rb → o_hash.rb} +8 -13
- data/lib/probability_distributions/gaussian_distribution.rb +34 -0
- data/lib/probability_distributions/probability_distribution.rb +16 -0
- data/lib/probability_distributions/uniform_distribution.rb +12 -0
- data/lib/random_generators.rb +1 -3
- data/lib/ruby_ex.rb +4 -4
- data/lib/sendmail.rb +7 -4
- data/lib/sym_tbl_gsub.rb +48 -17
- data/lib/uri/file.rb +5 -10
- data/lib/uri/ftp_ex.rb +4 -4
- data/lib/uri/generic_ex.rb +11 -7
- data/lib/uri/http_ex.rb +4 -4
- data/lib/uri/mysql.rb +3 -5
- data/lib/uri/pgsql.rb +3 -5
- data/lib/uri/rsync.rb +2 -4
- data/lib/uri/ssh.rb +3 -6
- data/lib/uri/svn.rb +10 -12
- data/lib/{yaml → yaml_extensions}/chop_header.rb +3 -3
- data/lib/{yaml → yaml_extensions}/transform.rb +4 -4
- data/lib/{yaml → yaml_extensions}/yregexpath.rb +3 -3
- metadata +89 -105
- data/lib/commands.rb +0 -27
- data/lib/commands/command.rb +0 -545
- data/lib/commands/datas.rb +0 -11
- data/lib/commands/datas/composite.rb +0 -55
- data/lib/commands/datas/data.rb +0 -160
- data/lib/commands/datas/factory.rb +0 -74
- data/lib/commands/datas/pipe.rb +0 -52
- data/lib/commands/datas/temp.rb +0 -24
- data/lib/commands/factory.rb +0 -65
- data/lib/commands/helpers.rb +0 -76
- data/lib/commands/pipe.rb +0 -114
- data/lib/commands/runners.rb +0 -11
- data/lib/commands/runners/exec.rb +0 -46
- data/lib/commands/runners/fork.rb +0 -104
- data/lib/commands/runners/mockable.rb +0 -63
- data/lib/commands/runners/no_run.rb +0 -44
- data/lib/commands/runners/popen.rb +0 -49
- data/lib/commands/runners/runner.rb +0 -177
- data/lib/commands/runners/system.rb +0 -54
- data/lib/commands/seq.rb +0 -31
- data/lib/hookable.rb +0 -294
- data/lib/hooker.rb +0 -52
data/lib/commands.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
-
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
3
|
-
# License:: GNU General Public License (GPL).
|
4
|
-
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands.rb 8049 2005-12-31T16:01:12.162089Z ertai $
|
5
|
-
|
6
|
-
# Provides an object oriented way to manage, combine and run your commands.
|
7
|
-
#
|
8
|
-
# Example:
|
9
|
-
# require 'rubygems' ; require_gem 'ruby_ex' ; require 'ruby_ex'
|
10
|
-
# Commands.import!
|
11
|
-
# ls, wc, out = 'ls'.to_cmd, 'wc'.to_cmd, 'out'.to_path
|
12
|
-
#
|
13
|
-
# data = ls.system # other runners exist (exec, fork, sh...)
|
14
|
-
#
|
15
|
-
# p data.status
|
16
|
-
# puts data.output.read
|
17
|
-
#
|
18
|
-
# (ls > STDOUT).system
|
19
|
-
#
|
20
|
-
# cmd = ls['*.rb'] | wc['-l'] > out
|
21
|
-
# cmd.system
|
22
|
-
#
|
23
|
-
# puts out.read
|
24
|
-
module Commands
|
25
|
-
end # module Commands
|
26
|
-
|
27
|
-
Commands::Helpers.import!
|
data/lib/commands/command.rb
DELETED
@@ -1,545 +0,0 @@
|
|
1
|
-
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
-
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
3
|
-
# License:: GNU General Public License (GPL).
|
4
|
-
# Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/command.rb 8052 2006-01-01T16:29:27.129829Z ertai $
|
5
|
-
|
6
|
-
module Commands
|
7
|
-
|
8
|
-
class Command
|
9
|
-
|
10
|
-
attr_accessor :command
|
11
|
-
attr_accessor :dir
|
12
|
-
attr_accessor :input
|
13
|
-
attr_accessor :output
|
14
|
-
attr_accessor :error
|
15
|
-
attr_accessor :args
|
16
|
-
attr_accessor :open_mode
|
17
|
-
|
18
|
-
#
|
19
|
-
# Construction methods.
|
20
|
-
#
|
21
|
-
|
22
|
-
def initialize ( command_name, *args )
|
23
|
-
@command = command_name
|
24
|
-
@args = args.dup
|
25
|
-
@open_mode = :w
|
26
|
-
@input, @output, @error = nil, nil, nil
|
27
|
-
end
|
28
|
-
|
29
|
-
#
|
30
|
-
# Command['wc -l'].sh
|
31
|
-
#
|
32
|
-
def self.[] ( *args )
|
33
|
-
new(*args)
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
#
|
39
|
-
# Running methods.
|
40
|
-
#
|
41
|
-
|
42
|
-
@@default_runners = {}
|
43
|
-
@@running_options =
|
44
|
-
{
|
45
|
-
:verbose => :make_verbose,
|
46
|
-
:v => :make_verbose,
|
47
|
-
:raise => :raise_on_failures,
|
48
|
-
:r => :raise_on_failures,
|
49
|
-
:debug => :make_debug,
|
50
|
-
:d => :make_debug,
|
51
|
-
:mock => :make_mock,
|
52
|
-
:m => :make_mock,
|
53
|
-
}
|
54
|
-
def run_with_options ( runner_class, options )
|
55
|
-
if options.empty?
|
56
|
-
runner = @@default_runners[runner_class] ||= runner_class.new
|
57
|
-
else
|
58
|
-
runner = runner_class.new
|
59
|
-
options.each do |k|
|
60
|
-
runner.send(@@running_options[k])
|
61
|
-
end
|
62
|
-
end
|
63
|
-
run(runner)
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
# Simulate Kernel#system() to run the command (No shell expansion).
|
68
|
-
def system ( *options )
|
69
|
-
run_with_options(Runners::System, options.flatten)
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
# Use the ExecRunner.
|
74
|
-
def exec ( *options )
|
75
|
-
run_with_options(Runners::Exec, options.flatten)
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
|
-
# FIXME test me
|
80
|
-
def sys ( *options )
|
81
|
-
run_with_options(Runners::System, [:v, :r] + options.flatten)
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
# Use Kernel#system() but with a string to have the shell expansion.
|
86
|
-
# FIXME make me a runner
|
87
|
-
def sh
|
88
|
-
Kernel.system(to_sh)
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
# Use Kernel#exec() but with a string to have the shell expansion.
|
93
|
-
# FIXME make me a runner
|
94
|
-
def sh!
|
95
|
-
Kernel.exec(to_sh)
|
96
|
-
end
|
97
|
-
|
98
|
-
|
99
|
-
# Use Kernel#` and return the resulting string.
|
100
|
-
# FIXME make me a runner
|
101
|
-
def expand
|
102
|
-
`#{to_sh}`
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
def popen ( *options )
|
107
|
-
run_with_options(Runners::Popen, options.flatten)
|
108
|
-
end
|
109
|
-
|
110
|
-
|
111
|
-
def fork ( *options )
|
112
|
-
run_with_options(Runners::Fork, options.flatten)
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
|
-
# FIXME design me!
|
117
|
-
# FIXME make me a runner
|
118
|
-
def ruby
|
119
|
-
end
|
120
|
-
|
121
|
-
|
122
|
-
# Use a Commands::Runners::Runner and return a Commands::Datas::Data.
|
123
|
-
def run ( runner=@runner )
|
124
|
-
unless runner.respond_to? :run
|
125
|
-
raise ArgumentError, "need a runner not: #{runner.inspect}"
|
126
|
-
end
|
127
|
-
runner.run(self)
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
#
|
133
|
-
# Operators.
|
134
|
-
#
|
135
|
-
|
136
|
-
|
137
|
-
# Pipe two commands.
|
138
|
-
def | ( rhs )
|
139
|
-
Commands::Pipe.new(self, rhs)
|
140
|
-
end
|
141
|
-
|
142
|
-
|
143
|
-
# Supply return a new commands with these arguments added.
|
144
|
-
def [] ( *args )
|
145
|
-
cmd = dup
|
146
|
-
cmd.args += args.flatten
|
147
|
-
cmd
|
148
|
-
end
|
149
|
-
|
150
|
-
|
151
|
-
# Chain two commands (like a `;' in shell), and return a new one.
|
152
|
-
def + ( rhs )
|
153
|
-
case rhs
|
154
|
-
when Command
|
155
|
-
Seq.new(self, rhs)
|
156
|
-
else
|
157
|
-
self[rhs]
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
|
162
|
-
# Return a new command with the given command input.
|
163
|
-
def < ( arg )
|
164
|
-
cmd = dup
|
165
|
-
cmd.input = arg
|
166
|
-
cmd
|
167
|
-
end
|
168
|
-
|
169
|
-
|
170
|
-
def add_outputs ( out, err )
|
171
|
-
cmd = dup
|
172
|
-
cmd.output = out.dup if out
|
173
|
-
cmd.error = err.dup if err
|
174
|
-
cmd
|
175
|
-
end
|
176
|
-
protected :add_outputs
|
177
|
-
|
178
|
-
|
179
|
-
# Return a new command with the given command output.
|
180
|
-
def > ( arg )
|
181
|
-
out, err = (arg.is_a?(Array))? arg : [arg, nil]
|
182
|
-
add_outputs(out, err)
|
183
|
-
end
|
184
|
-
|
185
|
-
|
186
|
-
# Like > but open the output in append mode.
|
187
|
-
def >> ( arg )
|
188
|
-
out, err = (arg.is_a?(Array))? arg : [arg, nil]
|
189
|
-
@open_mode = :a
|
190
|
-
add_outputs(out, err)
|
191
|
-
end
|
192
|
-
|
193
|
-
|
194
|
-
# Add an argument to a command.
|
195
|
-
# cmd = Command.new('ls')
|
196
|
-
# cmd << '-la'
|
197
|
-
# cmd.sh
|
198
|
-
def << ( arg )
|
199
|
-
@args << arg
|
200
|
-
self
|
201
|
-
end
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
#
|
206
|
-
# Misc
|
207
|
-
#
|
208
|
-
|
209
|
-
def arg_string
|
210
|
-
@args.map { |arg| arg.to_s.dump }.join(' ')
|
211
|
-
end
|
212
|
-
|
213
|
-
def whereis ( path=ENV['PATH'] )
|
214
|
-
# FIXME
|
215
|
-
end
|
216
|
-
|
217
|
-
|
218
|
-
#
|
219
|
-
# Conversion methods
|
220
|
-
#
|
221
|
-
|
222
|
-
def to_s
|
223
|
-
str = @command.dump
|
224
|
-
arg_str = arg_string
|
225
|
-
str += ' ' + arg_str unless arg_str.empty?
|
226
|
-
str
|
227
|
-
end
|
228
|
-
|
229
|
-
|
230
|
-
def to_sh
|
231
|
-
cmd = instanciate_args
|
232
|
-
"#{cmd.to_s}#{cmd.sh_args}"
|
233
|
-
end
|
234
|
-
|
235
|
-
def instanciate_args!
|
236
|
-
if defined? @input and @input and @args.include? '%i'
|
237
|
-
@args.map! { |a| (a == '%i')? @input : a }
|
238
|
-
@input = nil
|
239
|
-
end
|
240
|
-
if defined? @output and @output and @args.include? '%o'
|
241
|
-
@args.map! { |a| (a == '%o')? @output : a }
|
242
|
-
@output = nil
|
243
|
-
end
|
244
|
-
if defined? @error and @error and @args.include? '%e'
|
245
|
-
@args.map! { |a| (a == '%e')? @error : a }
|
246
|
-
@error = nil
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
def instanciate_args
|
251
|
-
copy = dup
|
252
|
-
copy.instanciate_args!
|
253
|
-
copy
|
254
|
-
end
|
255
|
-
|
256
|
-
def sh_args
|
257
|
-
args = ''
|
258
|
-
[ ['<', input], ['>', output], ['2>', error] ].each do |str, io|
|
259
|
-
args += " #{str} #{io.to_s.dump}" if io and not (io.respond_to? :pipe? and io.pipe?)
|
260
|
-
end
|
261
|
-
args
|
262
|
-
end
|
263
|
-
|
264
|
-
|
265
|
-
def to_a
|
266
|
-
[@command.dup, *@args.map { |arg| arg.to_s }]
|
267
|
-
end
|
268
|
-
|
269
|
-
def to_cmd
|
270
|
-
self
|
271
|
-
end
|
272
|
-
|
273
|
-
end # class Command
|
274
|
-
|
275
|
-
Commands::Helpers.import!
|
276
|
-
|
277
|
-
test_section __FILE__ do
|
278
|
-
|
279
|
-
class CommandTest < Test::Unit::TestCase
|
280
|
-
|
281
|
-
def setup
|
282
|
-
@file = TempPath.new
|
283
|
-
@tmp = TempPath.new
|
284
|
-
@tmp2 = TempPath.new
|
285
|
-
@file.open('w') { |f| f.puts "bla bla\n foo bar"}
|
286
|
-
ENV['TEST_FILE'] = @file.to_s
|
287
|
-
@touch = Command.new('touch')
|
288
|
-
@cp = Command.new('cp')
|
289
|
-
@cat = Command.new('cat')
|
290
|
-
@wc = Command.new('wc')
|
291
|
-
@sleep = Command.new('sleep')
|
292
|
-
@dne = Command.new('ThisCommandDoesNotExist')
|
293
|
-
@dev_null = Pathname.new('/dev/null')
|
294
|
-
end
|
295
|
-
|
296
|
-
def tear_down
|
297
|
-
[@file, @tmp, @tmp2].each { |t| t.clean }
|
298
|
-
end
|
299
|
-
|
300
|
-
def test_0_initialize
|
301
|
-
end
|
302
|
-
|
303
|
-
def test_self_hook # test_self.[]
|
304
|
-
@cat << 'foo' << 'bar'
|
305
|
-
assert_equal(@cat.to_a, Command[*%w[cat foo bar]].to_a)
|
306
|
-
end
|
307
|
-
|
308
|
-
def test_system_dne
|
309
|
-
@dne.system
|
310
|
-
assert_equal(127, $?.exitstatus)
|
311
|
-
end
|
312
|
-
|
313
|
-
def test_system
|
314
|
-
@touch << @tmp.to_s
|
315
|
-
@touch.system
|
316
|
-
assert_equal(0, $?)
|
317
|
-
assert(@tmp.exist?)
|
318
|
-
end
|
319
|
-
|
320
|
-
def test_system_raise_on_failures
|
321
|
-
assert_raise(Runners::Runner::FailureHooker::Error) do
|
322
|
-
'false'.to_cmd.system(:r)
|
323
|
-
end
|
324
|
-
assert_not_equal(0, $?)
|
325
|
-
end
|
326
|
-
|
327
|
-
def test_sh_and_pipe
|
328
|
-
((@cat | @wc) < @file > @tmp).sh
|
329
|
-
assert_equal(0, $?)
|
330
|
-
assert(@tmp.exist?)
|
331
|
-
assert_match(/\s*2\s*4\s*17\s+/, @tmp.read)
|
332
|
-
end
|
333
|
-
|
334
|
-
def test_system_and_pipe
|
335
|
-
((@cat | @wc) < @file.open('r+') > @tmp).system
|
336
|
-
assert_equal(0, $?)
|
337
|
-
assert(@tmp.exist?)
|
338
|
-
assert_match(/\s*2\s*4\s*17\s+/, @tmp.read)
|
339
|
-
end
|
340
|
-
|
341
|
-
def test_system_is_not_sh
|
342
|
-
@cat << '$TEST_FILE'
|
343
|
-
@cat.error = @dev_null
|
344
|
-
(@cat > @tmp).system
|
345
|
-
assert_not_equal(0, $?)
|
346
|
-
assert(!@tmp.exist? || @tmp.zero?)
|
347
|
-
end
|
348
|
-
|
349
|
-
def test_exec
|
350
|
-
@cp << @file << @tmp
|
351
|
-
pid = fork do
|
352
|
-
@cp.exec
|
353
|
-
end
|
354
|
-
Process.waitpid pid
|
355
|
-
assert_equal(0, $?)
|
356
|
-
assert(@tmp.exist?)
|
357
|
-
assert_equal(@file.read, @tmp.read)
|
358
|
-
end
|
359
|
-
|
360
|
-
def test_exec_not_sh!
|
361
|
-
@cat << '$TEST_FILE'
|
362
|
-
@cat.error = @dev_null
|
363
|
-
pid = fork do
|
364
|
-
(@cat > @tmp).exec
|
365
|
-
end
|
366
|
-
Process.waitpid pid
|
367
|
-
assert_not_equal(0, $?)
|
368
|
-
assert(!@tmp.exist? || @tmp.size.zero?)
|
369
|
-
end
|
370
|
-
|
371
|
-
def test_sh
|
372
|
-
@cat << '$TEST_FILE'
|
373
|
-
(@cat > @tmp).sh
|
374
|
-
assert_equal(0, $?)
|
375
|
-
assert(@tmp.exist?)
|
376
|
-
assert_equal(@file.read, @tmp.read)
|
377
|
-
end
|
378
|
-
|
379
|
-
def test_sh2
|
380
|
-
((@cat | @wc) < @file > @tmp).sh
|
381
|
-
assert_equal(0, $?)
|
382
|
-
assert(@tmp.exist?)
|
383
|
-
assert_match(/\s*2\s*4\s*17\s+/, @tmp.read)
|
384
|
-
end
|
385
|
-
|
386
|
-
def test_sh!
|
387
|
-
@cat << '$TEST_FILE'
|
388
|
-
pid = fork do
|
389
|
-
(@cat > @tmp).sh!
|
390
|
-
end
|
391
|
-
Process.waitpid pid
|
392
|
-
assert_equal(0, $?)
|
393
|
-
assert(@tmp.exist?)
|
394
|
-
assert_equal(@file.read, @tmp.read)
|
395
|
-
end
|
396
|
-
|
397
|
-
def test_expand
|
398
|
-
@cat << '$TEST_FILE'
|
399
|
-
str = (@cat).expand
|
400
|
-
assert_equal(0, $?)
|
401
|
-
assert_equal(@file.read, str)
|
402
|
-
|
403
|
-
str = ((@cat | @wc) < @file).expand
|
404
|
-
assert_equal(0, $?)
|
405
|
-
assert_match(/\s*2\s*4\s*17\s+/, str)
|
406
|
-
end
|
407
|
-
|
408
|
-
# FIXME
|
409
|
-
def test_popen
|
410
|
-
cmd = (@touch + @tmp) + (@sleep + 1)
|
411
|
-
diff = DTime.diff { @data = cmd.popen }
|
412
|
-
assert(@tmp.exist?)
|
413
|
-
@data.waitpid
|
414
|
-
assert(@tmp.exist?)
|
415
|
-
assert(diff.to_f < 1)
|
416
|
-
end
|
417
|
-
|
418
|
-
def test_fork
|
419
|
-
sleep_arg = 2
|
420
|
-
cmd = (@touch + @tmp) + (@sleep + sleep_arg)
|
421
|
-
diff = DTime.diff { @data = cmd.fork }
|
422
|
-
assert(@tmp.exist?)
|
423
|
-
@data.waitpid
|
424
|
-
assert(@tmp.exist?)
|
425
|
-
assert(diff.to_f < sleep_arg, "#{diff} should be < #{sleep_arg}")
|
426
|
-
end
|
427
|
-
|
428
|
-
def test_ruby
|
429
|
-
# FIXME
|
430
|
-
end
|
431
|
-
|
432
|
-
def test_pipe # test_|
|
433
|
-
assert_kind_of(Pipe, (@cat | @wc) < @file)
|
434
|
-
end
|
435
|
-
|
436
|
-
def test_subscript # test_[]
|
437
|
-
assert_equal(['a', 'b'], @cat['a', 'b'].args)
|
438
|
-
assert_equal(['a'], @cat['a'].args)
|
439
|
-
assert_equal([], @cat[].args)
|
440
|
-
assert_equal(['a', 'b', 'c'], @cat[[['a'], 'b', ['c']]].args)
|
441
|
-
end
|
442
|
-
|
443
|
-
def test_chain # test_+
|
444
|
-
assert_kind_of(Seq, (@cat + @wc) < @file)
|
445
|
-
cmd = @cat + @file.to_s
|
446
|
-
assert_kind_of(Command, cmd)
|
447
|
-
assert_equal([@file.to_s], cmd.args)
|
448
|
-
cmd += ['a', 'b']
|
449
|
-
assert_equal([@file.to_s, 'a', 'b'], cmd.args)
|
450
|
-
cmd += @file.to_s
|
451
|
-
assert_equal([@file.to_s, 'a', 'b', @file.to_s], cmd.args)
|
452
|
-
end
|
453
|
-
|
454
|
-
def test_chain_complex
|
455
|
-
((@cat < @file > @tmp) + (@wc + [@tmp] > @tmp2)).sh
|
456
|
-
assert_equal(0, $?)
|
457
|
-
assert(@tmp.exist?)
|
458
|
-
assert(@tmp2.exist?)
|
459
|
-
assert_equal(@file.read, @tmp.read)
|
460
|
-
assert_match(/\s*2\s*4\s*17\s*#{@tmp}\s+/, @tmp2.read)
|
461
|
-
end
|
462
|
-
|
463
|
-
def test_add_input # test_<
|
464
|
-
@cat.input = 'foo'
|
465
|
-
assert_equal('foo', @cat.input)
|
466
|
-
cmd = @cat < 'bar'
|
467
|
-
assert_equal('bar', cmd.input)
|
468
|
-
assert_not_equal(cmd.object_id, @cat.object_id)
|
469
|
-
end
|
470
|
-
|
471
|
-
def test_add_output # test_>
|
472
|
-
@cat.output = 'foo'
|
473
|
-
assert_equal('foo', @cat.output)
|
474
|
-
cmd = @cat > 'bar'
|
475
|
-
assert_equal('bar', cmd.output)
|
476
|
-
cmd = @cat > @file
|
477
|
-
assert_equal(@file, cmd.output)
|
478
|
-
assert_equal(:w, cmd.open_mode)
|
479
|
-
assert_not_equal(cmd.object_id, @cat.object_id)
|
480
|
-
cmd = @cat > [ 'outbar', 'errbar' ]
|
481
|
-
assert_equal('outbar', cmd.output)
|
482
|
-
assert_equal('errbar', cmd.error)
|
483
|
-
cmd = @cat > [ @file, @file ]
|
484
|
-
assert_equal(:w, cmd.open_mode)
|
485
|
-
end
|
486
|
-
|
487
|
-
def test_append_output # test_>>
|
488
|
-
@cat.output = 'foo'
|
489
|
-
assert_equal('foo', @cat.output)
|
490
|
-
cmd = @cat >> 'bar'
|
491
|
-
assert_equal('bar', cmd.output)
|
492
|
-
assert_not_equal(cmd.object_id, @cat.object_id)
|
493
|
-
cmd = @cat >> @file
|
494
|
-
assert_equal(@file, cmd.output)
|
495
|
-
assert_equal(:a, cmd.open_mode)
|
496
|
-
cmd = @cat >> [ 'outbar', 'errbar' ]
|
497
|
-
assert_equal('outbar', cmd.output)
|
498
|
-
assert_equal('errbar', cmd.error)
|
499
|
-
cmd = @cat >> [ @file, @file ]
|
500
|
-
assert_equal(:a, cmd.open_mode)
|
501
|
-
end
|
502
|
-
|
503
|
-
def test_args
|
504
|
-
assert_equal([], @cp.args)
|
505
|
-
@cat << 'foo bar' << 'baz'
|
506
|
-
assert_equal(['foo bar', 'baz'], @cat.args)
|
507
|
-
end
|
508
|
-
|
509
|
-
def test_arg_string
|
510
|
-
assert_equal('', @cp.arg_string)
|
511
|
-
@cat << 'foo bar' << 'baz'
|
512
|
-
assert_equal('"foo bar" "baz"', @cat.arg_string)
|
513
|
-
end
|
514
|
-
|
515
|
-
def test_to_s
|
516
|
-
assert_equal('"cp"', @cp.to_s)
|
517
|
-
@cat << 'foo bar' << 'baz'
|
518
|
-
assert_equal('"cat" "foo bar" "baz"', @cat.to_s)
|
519
|
-
end
|
520
|
-
|
521
|
-
def test_to_sh
|
522
|
-
assert_equal('"cp" > "ya"', (@cp > 'ya').to_sh)
|
523
|
-
@cat << 'foo > bar' << '< baz'
|
524
|
-
assert_equal(
|
525
|
-
'("cat" "foo > bar" "< baz" < "yay") | ("cp" > "yoy")',
|
526
|
-
((@cat | @cp) < 'yay' > 'yoy').to_sh)
|
527
|
-
@wc.error = 'foo'
|
528
|
-
assert_equal('"wc" 2> "foo"', @wc.to_sh)
|
529
|
-
end
|
530
|
-
|
531
|
-
def test_complex
|
532
|
-
ls = 'ls'.to_cmd
|
533
|
-
wc = 'wc'.to_cmd
|
534
|
-
(ls | wc) < @file > @tmp
|
535
|
-
end
|
536
|
-
|
537
|
-
def test_where
|
538
|
-
# FIXME
|
539
|
-
end
|
540
|
-
|
541
|
-
end # class CommandTest
|
542
|
-
|
543
|
-
end
|
544
|
-
|
545
|
-
end # module Commands
|