ruby_ex 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +51 -0
- data/ChangeLog +1763 -0
- data/NEWS +3 -0
- data/README +1 -0
- data/Rakefile +8 -0
- data/SPEC.dyn.yml +10 -0
- data/SPEC.gem.yml +269 -0
- data/SPEC.yml +36 -0
- data/src/abstract.rb +253 -0
- data/src/abstract_node.rb +85 -0
- data/src/algorithms.rb +12 -0
- data/src/algorithms/simulated_annealing.rb +142 -0
- data/src/ask.rb +100 -0
- data/src/attributed_class.rb +303 -0
- data/src/cache.rb +350 -0
- data/src/checkout.rb +12 -0
- data/src/choose.rb +271 -0
- data/src/commands.rb +20 -0
- data/src/commands/command.rb +492 -0
- data/src/commands/datas.rb +16 -0
- data/src/commands/datas/composite.rb +31 -0
- data/src/commands/datas/data.rb +65 -0
- data/src/commands/datas/factory.rb +69 -0
- data/src/commands/datas/temp.rb +26 -0
- data/src/commands/factory.rb +67 -0
- data/src/commands/helpers.rb +81 -0
- data/src/commands/pipe.rb +66 -0
- data/src/commands/runners.rb +16 -0
- data/src/commands/runners/exec.rb +50 -0
- data/src/commands/runners/fork.rb +130 -0
- data/src/commands/runners/runner.rb +140 -0
- data/src/commands/runners/system.rb +57 -0
- data/src/commands/seq.rb +32 -0
- data/src/config_file.rb +95 -0
- data/src/const_regexp.rb +57 -0
- data/src/daemon.rb +135 -0
- data/src/diff.rb +665 -0
- data/src/dlogger.rb +62 -0
- data/src/drb/drb_observable.rb +95 -0
- data/src/drb/drb_observable_pool.rb +27 -0
- data/src/drb/drb_service.rb +44 -0
- data/src/drb/drb_undumped_attributes.rb +56 -0
- data/src/drb/drb_undumped_indexed_object.rb +55 -0
- data/src/drb/insecure_protected_methods.rb +101 -0
- data/src/drb_ex.rb +12 -0
- data/src/dumpable_proc.rb +57 -0
- data/src/filetype.rb +229 -0
- data/src/generate_id.rb +44 -0
- data/src/histogram.rb +222 -0
- data/src/hookable.rb +283 -0
- data/src/hooker.rb +54 -0
- data/src/indexed_node.rb +65 -0
- data/src/io_marshal.rb +99 -0
- data/src/ioo.rb +193 -0
- data/src/labeled_node.rb +62 -0
- data/src/logger_observer.rb +24 -0
- data/src/md5sum.rb +70 -0
- data/src/module/autoload_tree.rb +65 -0
- data/src/module/hierarchy.rb +334 -0
- data/src/module/instance_method_visibility.rb +71 -0
- data/src/node.rb +81 -0
- data/src/object_monitor.rb +143 -0
- data/src/object_monitor_activity.rb +34 -0
- data/src/observable.rb +138 -0
- data/src/observable_pool.rb +291 -0
- data/src/orderedhash.rb +252 -0
- data/src/pp_hierarchy.rb +30 -0
- data/src/random_generators.rb +29 -0
- data/src/random_generators/random_generator.rb +33 -0
- data/src/random_generators/ruby.rb +25 -0
- data/src/ruby_ex.rb +124 -0
- data/src/safe_eval.rb +346 -0
- data/src/sendmail.rb +214 -0
- data/src/service_manager.rb +122 -0
- data/src/shuffle.rb +30 -0
- data/src/spring.rb +134 -0
- data/src/spring_set.rb +134 -0
- data/src/symtbl.rb +108 -0
- data/src/synflow.rb +474 -0
- data/src/thread_mutex.rb +11 -0
- data/src/timeout_ex.rb +79 -0
- data/src/trace.rb +26 -0
- data/src/uri/druby.rb +78 -0
- data/src/uri/file.rb +63 -0
- data/src/uri/ftp_ex.rb +36 -0
- data/src/uri/http_ex.rb +41 -0
- data/src/uri/pgsql.rb +136 -0
- data/src/uri/ssh.rb +87 -0
- data/src/uri/svn.rb +113 -0
- data/src/uri_ex.rb +71 -0
- data/src/verbose_object.rb +70 -0
- data/src/yaml/basenode_ext.rb +63 -0
- data/src/yaml/chop_header.rb +24 -0
- data/src/yaml/transform.rb +450 -0
- data/src/yaml/yregexpath.rb +76 -0
- data/test/algorithms/simulated_annealing_test.rb +102 -0
- data/test/check-pkg-ruby_ex.yml +15 -0
- data/test/check-ruby_ex.yml +12 -0
- data/test/resources/autoload_tree/A.rb +11 -0
- data/test/resources/autoload_tree/B.rb +10 -0
- data/test/resources/autoload_tree/foo/C.rb +18 -0
- data/test/resources/foo.txt +6 -0
- data/test/sanity-suite.yml +12 -0
- data/test/sanity/multiple-requires.yml +20 -0
- data/test/sanity/single-requires.yml +24 -0
- data/test/test-unit-setup.rb +6 -0
- data/test/unit-suite.yml +14 -0
- metadata +269 -0
data/src/commands.rb
ADDED
@@ -0,0 +1,20 @@
|
|
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: commands.rb 266 2005-06-01 14:27:18Z ertai $
|
5
|
+
|
6
|
+
require 'ruby_ex'
|
7
|
+
require 'module/autoload_tree'
|
8
|
+
require 'abstract'
|
9
|
+
require 'hookable'
|
10
|
+
require 'hooker'
|
11
|
+
require 'commands/helpers'
|
12
|
+
require 'commands/datas'
|
13
|
+
require 'commands/runners'
|
14
|
+
|
15
|
+
|
16
|
+
module Commands
|
17
|
+
|
18
|
+
autoloaded_module(__FILE__, false)
|
19
|
+
|
20
|
+
end # module Commands
|
@@ -0,0 +1,492 @@
|
|
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: command.rb 255 2005-06-01 00:08:46Z ertai $
|
5
|
+
|
6
|
+
require 'commands'
|
7
|
+
|
8
|
+
module Commands
|
9
|
+
|
10
|
+
class Command
|
11
|
+
|
12
|
+
attr_accessor :command
|
13
|
+
attr_accessor :dir
|
14
|
+
attr_accessor :input
|
15
|
+
attr_accessor :output
|
16
|
+
attr_accessor :error
|
17
|
+
attr_accessor :args
|
18
|
+
|
19
|
+
#
|
20
|
+
# Construction methods.
|
21
|
+
#
|
22
|
+
|
23
|
+
def initialize ( command_name, *args )
|
24
|
+
@command = command_name
|
25
|
+
@args = args.dup
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Command['wc -l'].sh
|
30
|
+
#
|
31
|
+
def self.[] ( *args )
|
32
|
+
new(*args)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
#
|
38
|
+
# Running methods.
|
39
|
+
#
|
40
|
+
|
41
|
+
# Simulate Kernel#system() to run the command (No shell expansion).
|
42
|
+
def system
|
43
|
+
unless defined? @@system_runner
|
44
|
+
@@system_runner = Runners::System.new
|
45
|
+
end
|
46
|
+
run(@@system_runner)
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
# Use the ExecRunner.
|
51
|
+
def exec
|
52
|
+
unless defined? @@exec_runner
|
53
|
+
@@exec_runner = Runners::Exec.new
|
54
|
+
end
|
55
|
+
run(@@exec_runner)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
# FIXME test me
|
60
|
+
def sys
|
61
|
+
unless defined? @@sys_runner
|
62
|
+
@@sys_runner = Runners::System.new.make_verbose.raise_on_failures
|
63
|
+
end
|
64
|
+
run(@@sys_runner)
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
# Use Kernel#system() but with a string to have the shell expansion.
|
69
|
+
def sh
|
70
|
+
Kernel.system(to_sh)
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
# Use Kernel#exec() but with a string to have the shell expansion.
|
75
|
+
def sh!
|
76
|
+
Kernel.exec(to_sh)
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
# Use Kernel#` and return the resulting string.
|
81
|
+
def expand
|
82
|
+
`#{to_sh}`
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
def popen
|
87
|
+
unless defined? @@fork_runner
|
88
|
+
@@fork_runner = Runners::Fork.new
|
89
|
+
end
|
90
|
+
run(@@fork_runner)
|
91
|
+
end
|
92
|
+
alias :fork :popen
|
93
|
+
|
94
|
+
|
95
|
+
# FIXME design me!
|
96
|
+
def ruby
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
# Use a Commands::Runners::Runner and return a Commands::Datas::Data.
|
101
|
+
def run ( runner=@runner )
|
102
|
+
runner.run(self)
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
#
|
108
|
+
# Operators.
|
109
|
+
#
|
110
|
+
|
111
|
+
|
112
|
+
# Pipe two commands.
|
113
|
+
def | ( rhs )
|
114
|
+
Pipe.new(self, rhs)
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
# Supply return a new commands with these arguments added.
|
119
|
+
def [] ( *args )
|
120
|
+
cmd = dup
|
121
|
+
cmd.args += args.flatten
|
122
|
+
cmd
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
# Chain two commands (like a `;' in shell), and return a new one.
|
127
|
+
def + ( rhs )
|
128
|
+
case rhs
|
129
|
+
when Command
|
130
|
+
Seq.new(self, rhs)
|
131
|
+
else
|
132
|
+
self[rhs]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
# Return a new command with the given command input.
|
138
|
+
def < ( arg )
|
139
|
+
cmd = dup
|
140
|
+
cmd.input = arg
|
141
|
+
cmd
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
def add_outputs ( out, err, mode )
|
146
|
+
cmd = dup
|
147
|
+
cmd.output = out.dup
|
148
|
+
cmd.output.open_mode = mode if cmd.output.is_a? Pathname
|
149
|
+
if err
|
150
|
+
cmd.error = err.dup
|
151
|
+
cmd.error.open_mode = mode if cmd.error.is_a? Pathname
|
152
|
+
end
|
153
|
+
cmd
|
154
|
+
end
|
155
|
+
protected :add_outputs
|
156
|
+
|
157
|
+
|
158
|
+
# Return a new command with the given command output.
|
159
|
+
def > ( arg )
|
160
|
+
out, err = (arg.is_a?(Array))? arg : [arg, nil]
|
161
|
+
add_outputs(out, err, 'w')
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
# Like > but open the output in append mode.
|
166
|
+
def >> ( arg )
|
167
|
+
out, err = (arg.is_a?(Array))? arg : [arg, nil]
|
168
|
+
add_outputs(out, err, 'a')
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
# Add an argument to a command.
|
173
|
+
# cmd = Command.new('ls')
|
174
|
+
# cmd << '-la'
|
175
|
+
# cmd.sh
|
176
|
+
def << ( arg )
|
177
|
+
@args << arg
|
178
|
+
self
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
#
|
184
|
+
# Misc
|
185
|
+
#
|
186
|
+
|
187
|
+
def arg_string
|
188
|
+
@args.map { |arg| arg.to_s.dump }.join(' ')
|
189
|
+
end
|
190
|
+
|
191
|
+
def whereis ( path=ENV['PATH'] )
|
192
|
+
# FIXME
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
#
|
197
|
+
# Conversion methods
|
198
|
+
#
|
199
|
+
|
200
|
+
def to_s
|
201
|
+
str = @command.dump
|
202
|
+
arg_str = arg_string
|
203
|
+
str += ' ' + arg_str unless arg_str.empty?
|
204
|
+
str
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
def to_sh
|
209
|
+
"#{to_s}#{sh_args}"
|
210
|
+
end
|
211
|
+
|
212
|
+
|
213
|
+
def sh_args
|
214
|
+
args = ''
|
215
|
+
args += " < #{@input.to_s.dump}" if @input
|
216
|
+
args += " > #{@output.to_s.dump}" if @output
|
217
|
+
args += " 2> #{@error.to_s.dump}" if @error
|
218
|
+
args
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
def to_a
|
223
|
+
[@command.dup, *@args.map { |arg| arg.to_s }]
|
224
|
+
end
|
225
|
+
|
226
|
+
def to_cmd
|
227
|
+
self
|
228
|
+
end
|
229
|
+
|
230
|
+
end # class Command
|
231
|
+
|
232
|
+
test_section __FILE__ do
|
233
|
+
|
234
|
+
class CommandTest < Test::Unit::TestCase
|
235
|
+
|
236
|
+
def setup
|
237
|
+
@file = TempPath.new
|
238
|
+
@tmp = TempPath.new
|
239
|
+
@tmp2 = TempPath.new
|
240
|
+
@file.open('w') { |f| f.puts "bla bla\n foo bar"}
|
241
|
+
ENV['TEST_FILE'] = @file.to_s
|
242
|
+
@touch = Command.new('touch')
|
243
|
+
@cp = Command.new('cp')
|
244
|
+
@cat = Command.new('cat')
|
245
|
+
@wc = Command.new('wc')
|
246
|
+
@sleep = Command.new('sleep')
|
247
|
+
@dne = Command.new('ThisCommandDoesNotExist')
|
248
|
+
@dev_null = Pathname.new('/dev/null')
|
249
|
+
end
|
250
|
+
|
251
|
+
def tear_down
|
252
|
+
[@file, @tmp, @tmp2].each { |t| t.clean }
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_0_initialize
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_self_hook # test_self.[]
|
259
|
+
@cat << 'foo' << 'bar'
|
260
|
+
assert_equal(@cat.to_a, Command[*%w[cat foo bar]].to_a)
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_system_dne
|
264
|
+
@dne.system
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_system
|
268
|
+
@touch << @tmp.to_s
|
269
|
+
@touch.system
|
270
|
+
assert_equal(0, $?)
|
271
|
+
assert(@tmp.exist?)
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_sh_and_pipe
|
275
|
+
((@cat | @wc) < @file > @tmp).sh
|
276
|
+
assert_equal(0, $?)
|
277
|
+
assert(@tmp.exist?)
|
278
|
+
assert_match(/\s*2\s*4\s*17\s+/, @tmp.read)
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_system_and_pipe
|
282
|
+
((@cat | @wc) < @file.open('r+') > @tmp).system
|
283
|
+
assert_equal(0, $?)
|
284
|
+
assert(@tmp.exist?)
|
285
|
+
assert_match(/\s*2\s*4\s*17\s+/, @tmp.read)
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_system_is_not_sh
|
289
|
+
@cat << '$TEST_FILE'
|
290
|
+
@cat.error = @dev_null
|
291
|
+
(@cat > @tmp).system
|
292
|
+
assert_not_equal(0, $?)
|
293
|
+
assert(!@tmp.exist? || @tmp.zero?)
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_exec
|
297
|
+
@cp << @file << @tmp
|
298
|
+
pid = fork do
|
299
|
+
@cp.exec
|
300
|
+
end
|
301
|
+
Process.waitpid pid
|
302
|
+
assert_equal(0, $?)
|
303
|
+
assert(@tmp.exist?)
|
304
|
+
assert_equal(@file.read, @tmp.read)
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_exec_not_sh!
|
308
|
+
@cat << '$TEST_FILE'
|
309
|
+
@cat.error = @dev_null
|
310
|
+
pid = fork do
|
311
|
+
(@cat > @tmp).exec
|
312
|
+
end
|
313
|
+
Process.waitpid pid
|
314
|
+
assert_not_equal(0, $?)
|
315
|
+
assert(!@tmp.exist? || @tmp.size.zero?)
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_sh
|
319
|
+
@cat << '$TEST_FILE'
|
320
|
+
(@cat > @tmp).sh
|
321
|
+
assert_equal(0, $?)
|
322
|
+
assert(@tmp.exist?)
|
323
|
+
assert_equal(@file.read, @tmp.read)
|
324
|
+
end
|
325
|
+
|
326
|
+
def test_sh2
|
327
|
+
((@cat | @wc) < @file > @tmp).sh
|
328
|
+
assert_equal(0, $?)
|
329
|
+
assert(@tmp.exist?)
|
330
|
+
assert_match(/\s*2\s*4\s*17\s+/, @tmp.read)
|
331
|
+
end
|
332
|
+
|
333
|
+
def test_sh!
|
334
|
+
@cat << '$TEST_FILE'
|
335
|
+
pid = fork do
|
336
|
+
(@cat > @tmp).sh!
|
337
|
+
end
|
338
|
+
Process.waitpid pid
|
339
|
+
assert_equal(0, $?)
|
340
|
+
assert(@tmp.exist?)
|
341
|
+
assert_equal(@file.read, @tmp.read)
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_expand
|
345
|
+
@cat << '$TEST_FILE'
|
346
|
+
str = (@cat).expand
|
347
|
+
assert_equal(0, $?)
|
348
|
+
assert_equal(@file.read, str)
|
349
|
+
|
350
|
+
str = ((@cat | @wc) < @file).expand
|
351
|
+
assert_equal(0, $?)
|
352
|
+
assert_match(/\s*2\s*4\s*17\s+/, str)
|
353
|
+
end
|
354
|
+
|
355
|
+
def test_popen
|
356
|
+
cmd = (@touch + @tmp) + (@sleep + 1)
|
357
|
+
diff = DTime.diff { @data = cmd.popen }
|
358
|
+
assert(@tmp.exist?)
|
359
|
+
@data.waitpid
|
360
|
+
assert(@tmp.exist?)
|
361
|
+
assert(diff.to_f < 1)
|
362
|
+
end
|
363
|
+
|
364
|
+
def test_fork
|
365
|
+
cmd = (@touch + @tmp) + (@sleep + 1)
|
366
|
+
diff = DTime.diff { @data = cmd.fork }
|
367
|
+
assert(@tmp.exist?)
|
368
|
+
@data.waitpid
|
369
|
+
assert(@tmp.exist?)
|
370
|
+
assert(diff.to_f < 1)
|
371
|
+
end
|
372
|
+
|
373
|
+
def test_ruby
|
374
|
+
# FIXME
|
375
|
+
end
|
376
|
+
|
377
|
+
def test_pipe # test_|
|
378
|
+
assert_kind_of(Pipe, (@cat | @wc) < @file)
|
379
|
+
end
|
380
|
+
|
381
|
+
def test_subscript # test_[]
|
382
|
+
assert_equal(['a', 'b'], @cat['a', 'b'].args)
|
383
|
+
assert_equal(['a'], @cat['a'].args)
|
384
|
+
assert_equal([], @cat[].args)
|
385
|
+
assert_equal(['a', 'b', 'c'], @cat[[['a'], 'b', ['c']]].args)
|
386
|
+
end
|
387
|
+
|
388
|
+
def test_chain # test_+
|
389
|
+
assert_kind_of(Seq, (@cat + @wc) < @file)
|
390
|
+
cmd = @cat + @file.to_s
|
391
|
+
assert_kind_of(Command, cmd)
|
392
|
+
assert_equal([@file.to_s], cmd.args)
|
393
|
+
cmd += ['a', 'b']
|
394
|
+
assert_equal([@file.to_s, 'a', 'b'], cmd.args)
|
395
|
+
cmd += @file.to_s
|
396
|
+
assert_equal([@file.to_s, 'a', 'b', @file.to_s], cmd.args)
|
397
|
+
end
|
398
|
+
|
399
|
+
def test_chain_complex
|
400
|
+
((@cat < @file > @tmp) + (@wc + [@tmp] > @tmp2)).sh
|
401
|
+
assert_equal(0, $?)
|
402
|
+
assert(@tmp.exist?)
|
403
|
+
assert(@tmp2.exist?)
|
404
|
+
assert_equal(@file.read, @tmp.read)
|
405
|
+
assert_match(/\s*2\s*4\s*17\s*#{@tmp}\s+/, @tmp2.read)
|
406
|
+
end
|
407
|
+
|
408
|
+
def test_add_input # test_<
|
409
|
+
@cat.input = 'foo'
|
410
|
+
assert_equal('foo', @cat.input)
|
411
|
+
cmd = @cat < 'bar'
|
412
|
+
assert_equal('bar', cmd.input)
|
413
|
+
assert_not_equal(cmd.object_id, @bar.object_id)
|
414
|
+
end
|
415
|
+
|
416
|
+
def test_add_output # test_>
|
417
|
+
@cat.output = 'foo'
|
418
|
+
assert_equal('foo', @cat.output)
|
419
|
+
cmd = @cat > 'bar'
|
420
|
+
assert_equal('bar', cmd.output)
|
421
|
+
cmd = @cat > @file
|
422
|
+
assert_equal(@file, cmd.output)
|
423
|
+
assert_equal('w', cmd.output.open_mode)
|
424
|
+
assert_not_equal(cmd.object_id, @bar.object_id)
|
425
|
+
cmd = @cat > [ 'outbar', 'errbar' ]
|
426
|
+
assert_equal('outbar', cmd.output)
|
427
|
+
assert_equal('errbar', cmd.error)
|
428
|
+
cmd = @cat > [ @file, @file ]
|
429
|
+
assert_equal('w', cmd.output.open_mode)
|
430
|
+
assert_equal('w', cmd.error.open_mode)
|
431
|
+
end
|
432
|
+
|
433
|
+
def test_append_output # test_>>
|
434
|
+
@cat.output = 'foo'
|
435
|
+
assert_equal('foo', @cat.output)
|
436
|
+
cmd = @cat >> 'bar'
|
437
|
+
assert_equal('bar', cmd.output)
|
438
|
+
assert_not_equal(cmd.object_id, @bar.object_id)
|
439
|
+
cmd = @cat >> @file
|
440
|
+
assert_equal(@file, cmd.output)
|
441
|
+
assert_equal('a', cmd.output.open_mode)
|
442
|
+
cmd = @cat >> [ 'outbar', 'errbar' ]
|
443
|
+
assert_equal('outbar', cmd.output)
|
444
|
+
assert_equal('errbar', cmd.error)
|
445
|
+
cmd = @cat >> [ @file, @file ]
|
446
|
+
assert_equal('a', cmd.output.open_mode)
|
447
|
+
assert_equal('a', cmd.error.open_mode)
|
448
|
+
end
|
449
|
+
|
450
|
+
def test_args
|
451
|
+
assert_equal([], @cp.args)
|
452
|
+
@cat << 'foo bar' << 'baz'
|
453
|
+
assert_equal(['foo bar', 'baz'], @cat.args)
|
454
|
+
end
|
455
|
+
|
456
|
+
def test_arg_string
|
457
|
+
assert_equal('', @cp.arg_string)
|
458
|
+
@cat << 'foo bar' << 'baz'
|
459
|
+
assert_equal('"foo bar" "baz"', @cat.arg_string)
|
460
|
+
end
|
461
|
+
|
462
|
+
def test_to_s
|
463
|
+
assert_equal('"cp"', @cp.to_s)
|
464
|
+
@cat << 'foo bar' << 'baz'
|
465
|
+
assert_equal('"cat" "foo bar" "baz"', @cat.to_s)
|
466
|
+
end
|
467
|
+
|
468
|
+
def test_to_sh
|
469
|
+
assert_equal('"cp" > "ya"', (@cp > 'ya').to_sh)
|
470
|
+
@cat << 'foo > bar' << '< baz'
|
471
|
+
assert_equal(
|
472
|
+
'(("cat" "foo > bar" "< baz" < "yay") | ("cp" > "yoy"))',
|
473
|
+
((@cat | @cp) < 'yay' > 'yoy').to_sh)
|
474
|
+
@wc.error = 'foo'
|
475
|
+
assert_equal('"wc" 2> "foo"', @wc.to_sh)
|
476
|
+
end
|
477
|
+
|
478
|
+
def test_complex
|
479
|
+
ls = 'ls'.to_cmd
|
480
|
+
wc = 'wc'.to_cmd
|
481
|
+
(ls | wc) < @file > @tmp
|
482
|
+
end
|
483
|
+
|
484
|
+
def test_where
|
485
|
+
# FIXME
|
486
|
+
end
|
487
|
+
|
488
|
+
end # class CommandTest
|
489
|
+
|
490
|
+
end
|
491
|
+
|
492
|
+
end # module Commands
|