ruby_ex 0.3.0 → 0.4.1.2

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 (115) hide show
  1. data/ChangeLog +324 -0
  2. data/NEWS +17 -0
  3. data/README +1 -1
  4. data/SPEC.yml +9 -9
  5. data/lib/abstract.rb +3 -38
  6. data/lib/abstract_node.rb +2 -4
  7. data/lib/algorithms/simulated_annealing.rb +26 -3
  8. data/lib/attributed_class.rb +2 -2
  9. data/lib/auto_object.rb +2 -6
  10. data/lib/blank_slate.rb +1 -1
  11. data/lib/cache.rb +4 -4
  12. data/lib/choose.rb +3 -5
  13. data/lib/commands/command.rb +53 -27
  14. data/lib/commands/datas/composite.rb +2 -4
  15. data/lib/commands/datas/data.rb +13 -16
  16. data/lib/commands/datas/factory.rb +2 -4
  17. data/lib/commands/datas/pipe.rb +52 -0
  18. data/lib/commands/datas/temp.rb +2 -2
  19. data/lib/commands/datas.rb +1 -6
  20. data/lib/commands/factory.rb +1 -3
  21. data/lib/commands/helpers.rb +6 -11
  22. data/lib/commands/pipe.rb +4 -6
  23. data/lib/commands/runners/exec.rb +2 -6
  24. data/lib/commands/runners/fork.rb +3 -20
  25. data/lib/commands/runners/mockable.rb +4 -7
  26. data/lib/commands/runners/no_run.rb +44 -0
  27. data/lib/commands/runners/popen.rb +49 -0
  28. data/lib/commands/runners/runner.rb +29 -6
  29. data/lib/commands/runners/system.rb +1 -4
  30. data/lib/commands/runners.rb +1 -6
  31. data/lib/commands/seq.rb +1 -3
  32. data/lib/commands.rb +3 -13
  33. data/lib/concrete.rb +38 -0
  34. data/lib/config_file.rb +2 -3
  35. data/lib/const_regexp.rb +1 -1
  36. data/lib/d_logger.rb +1 -1
  37. data/lib/daemon.rb +2 -3
  38. data/lib/diff.rb +1 -1
  39. data/lib/diff_tools.rb +1 -3
  40. data/lib/drb/drb_observable.rb +1 -1
  41. data/lib/drb/drb_observable_pool.rb +1 -1
  42. data/lib/drb/drb_service.rb +1 -1
  43. data/lib/drb/drb_undumped_attributes.rb +1 -1
  44. data/lib/drb/drb_undumped_indexed_object.rb +1 -1
  45. data/lib/drb/insecure_protected_methods.rb +1 -1
  46. data/lib/drb_ex.rb +1 -1
  47. data/lib/file_type.rb +2 -2
  48. data/lib/generate_id.rb +1 -1
  49. data/lib/genpasswd.rb +1 -1
  50. data/lib/hash_eval.rb +1 -1
  51. data/lib/histogram.rb +1 -1
  52. data/lib/hookable.rb +1 -4
  53. data/lib/hooker.rb +1 -1
  54. data/lib/html_encode.rb +1 -1
  55. data/lib/indexed_node.rb +0 -3
  56. data/lib/io_marshal.rb +1 -1
  57. data/lib/ioo.rb +1 -1
  58. data/lib/kill_all.rb +2 -2
  59. data/lib/labeled_node.rb +0 -3
  60. data/lib/logger_observer.rb +1 -1
  61. data/lib/md5sum.rb +1 -1
  62. data/lib/meta_factory.rb +1 -1
  63. data/lib/method_call.rb +1 -1
  64. data/lib/mocks/assertions.rb +1 -1
  65. data/lib/mocks/method_logger.rb +1 -3
  66. data/lib/mocks/mock.rb +2 -4
  67. data/lib/mocks/object.rb +1 -4
  68. data/lib/mocks/observer.rb +1 -3
  69. data/lib/mocks.rb +1 -6
  70. data/lib/module/autoload_tree.rb +1 -1
  71. data/lib/module/hierarchy.rb +1 -1
  72. data/lib/module/instance_method_visibility.rb +17 -16
  73. data/lib/object_monitor.rb +1 -1
  74. data/lib/object_monitor_activity.rb +1 -1
  75. data/lib/observable.rb +1 -1
  76. data/lib/observable_pool.rb +1 -1
  77. data/lib/ordered_hash.rb +1 -1
  78. data/lib/r_path.rb +44 -23
  79. data/lib/random_generators/random_generator.rb +1 -1
  80. data/lib/random_generators/ruby.rb +1 -5
  81. data/lib/random_generators.rb +20 -5
  82. data/lib/regex_list.rb +2 -5
  83. data/lib/regex_path.rb +64 -23
  84. data/lib/ruby_ex.rb +11 -2
  85. data/lib/safe_eval.rb +6 -15
  86. data/lib/sendmail.rb +41 -17
  87. data/lib/service_manager.rb +1 -1
  88. data/lib/shuffle.rb +3 -1
  89. data/lib/spring.rb +1 -1
  90. data/lib/spring_set.rb +1 -1
  91. data/lib/sym_tbl.rb +14 -8
  92. data/lib/sym_tbl_gsub.rb +88 -23
  93. data/lib/text.rb +1 -1
  94. data/lib/timeout_ex.rb +1 -1
  95. data/lib/trace.rb +1 -1
  96. data/lib/uri/druby.rb +3 -6
  97. data/lib/uri/file.rb +32 -18
  98. data/lib/uri/ftp_ex.rb +8 -3
  99. data/lib/uri/generic_ex.rb +158 -0
  100. data/lib/uri/http_ex.rb +9 -4
  101. data/lib/uri/mysql.rb +7 -15
  102. data/lib/uri/pgsql.rb +6 -14
  103. data/lib/uri/rsync.rb +77 -0
  104. data/lib/uri/ssh.rb +55 -27
  105. data/lib/uri/svn.rb +22 -76
  106. data/lib/verbose_object.rb +1 -5
  107. data/lib/yaml/transform.rb +1 -1
  108. data/lib/yaml/yregexpath.rb +1 -1
  109. data/test/algorithms/simulated_annealing_test.rb +79 -80
  110. data/test/unit-suite.yml +5 -3
  111. metadata +179 -172
  112. data/SPEC.dyn.yml +0 -10
  113. data/SPEC.gemspec +0 -14
  114. data/lib/uri_ex.rb +0 -110
  115. data/test/test-unit-setup.rb +0 -10
@@ -1,9 +1,7 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
3
  # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: command.rb 365 2005-09-24 17:24:01Z ertai $
5
-
6
- require 'commands'
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/command.rb 8052 2006-01-01T16:29:27.129829Z ertai $
7
5
 
8
6
  module Commands
9
7
 
@@ -41,30 +39,46 @@ module Commands
41
39
  # Running methods.
42
40
  #
43
41
 
44
- # Simulate Kernel#system() to run the command (No shell expansion).
45
- def system
46
- unless defined? @@system_runner
47
- @@system_runner = Runners::System.new
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
48
62
  end
49
- run(@@system_runner)
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)
50
70
  end
51
71
 
52
72
 
53
73
  # Use the ExecRunner.
54
- def exec
55
- unless defined? @@exec_runner
56
- @@exec_runner = Runners::Exec.new
57
- end
58
- run(@@exec_runner)
74
+ def exec ( *options )
75
+ run_with_options(Runners::Exec, options.flatten)
59
76
  end
60
77
 
61
78
 
62
79
  # FIXME test me
63
- def sys
64
- unless defined? @@sys_runner
65
- @@sys_runner = Runners::System.new.make_verbose.raise_on_failures
66
- end
67
- run(@@sys_runner)
80
+ def sys ( *options )
81
+ run_with_options(Runners::System, [:v, :r] + options.flatten)
68
82
  end
69
83
 
70
84
 
@@ -89,13 +103,14 @@ module Commands
89
103
  end
90
104
 
91
105
 
92
- def popen
93
- unless defined? @@fork_runner
94
- @@fork_runner = Runners::Fork.new
95
- end
96
- run(@@fork_runner)
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)
97
113
  end
98
- alias :fork :popen
99
114
 
100
115
 
101
116
  # FIXME design me!
@@ -121,7 +136,7 @@ module Commands
121
136
 
122
137
  # Pipe two commands.
123
138
  def | ( rhs )
124
- Pipe.new(self, rhs)
139
+ Commands::Pipe.new(self, rhs)
125
140
  end
126
141
 
127
142
 
@@ -257,6 +272,8 @@ module Commands
257
272
 
258
273
  end # class Command
259
274
 
275
+ Commands::Helpers.import!
276
+
260
277
  test_section __FILE__ do
261
278
 
262
279
  class CommandTest < Test::Unit::TestCase
@@ -300,6 +317,13 @@ module Commands
300
317
  assert(@tmp.exist?)
301
318
  end
302
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
+
303
327
  def test_sh_and_pipe
304
328
  ((@cat | @wc) < @file > @tmp).sh
305
329
  assert_equal(0, $?)
@@ -381,6 +405,7 @@ module Commands
381
405
  assert_match(/\s*2\s*4\s*17\s+/, str)
382
406
  end
383
407
 
408
+ # FIXME
384
409
  def test_popen
385
410
  cmd = (@touch + @tmp) + (@sleep + 1)
386
411
  diff = DTime.diff { @data = cmd.popen }
@@ -391,12 +416,13 @@ module Commands
391
416
  end
392
417
 
393
418
  def test_fork
394
- cmd = (@touch + @tmp) + (@sleep + 1)
419
+ sleep_arg = 2
420
+ cmd = (@touch + @tmp) + (@sleep + sleep_arg)
395
421
  diff = DTime.diff { @data = cmd.fork }
396
422
  assert(@tmp.exist?)
397
423
  @data.waitpid
398
424
  assert(@tmp.exist?)
399
- assert(diff.to_f < 1)
425
+ assert(diff.to_f < sleep_arg, "#{diff} should be < #{sleep_arg}")
400
426
  end
401
427
 
402
428
  def test_ruby
@@ -1,15 +1,13 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
3
  # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: composite.rb 365 2005-09-24 17:24:01Z ertai $
5
-
6
- require 'commands'
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/datas/composite.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
7
5
 
8
6
  module Commands
9
7
 
10
8
  module Datas
11
9
 
12
- class Composite < Data
10
+ class Composite < self::Data
13
11
 
14
12
  attr_accessor :contents
15
13
 
@@ -1,9 +1,7 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
3
  # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: data.rb 365 2005-09-24 17:24:01Z ertai $
5
-
6
- require 'commands'
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/datas/data.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
7
5
 
8
6
  module Commands
9
7
 
@@ -108,26 +106,22 @@ module Commands
108
106
  have YamlExtension, :'commands::data'
109
107
 
110
108
  def to_yaml_string
111
- out = output.read
112
- err = error.read
109
+ suppress(IOError) { out = output.read }
110
+ suppress(IOError) { err = error.read }
113
111
  out ||= ''
114
112
  err ||= ''
115
113
 
116
114
  msg = []
117
115
  msg << "exit: #{status.exitstatus}" unless status.nil?
118
- if out.empty?
119
- msg << 'output: ""'
120
- else
116
+ unless out.empty?
121
117
  out.gsub!(/^/, ' ')
122
118
  msg << "output: |\n #{out}"
123
119
  end
124
- if err.empty?
125
- msg << 'error: ""'
126
- else
120
+ unless err.empty?
127
121
  err.gsub!(/^/, ' ')
128
122
  msg << "error: |\n #{err}"
129
123
  end
130
- msg.join("\n")
124
+ "\n" + msg.join("\n")
131
125
  end
132
126
 
133
127
  def kill ( sig='KILL' )
@@ -141,12 +135,15 @@ module Commands
141
135
  next if stream.nil? or stream.is_a? IO
142
136
  if stream.is_a? File
143
137
  stream.close
144
- stream = stream.path.to_path
138
+ stream = stream.path.to_path
145
139
  end
146
- unless stream.is_a? Pathname
147
- raise ArgumentError, "need a pathname not #{stream}"
140
+ if stream.is_a? Pathname
141
+ stream.unlink if stream.exist? and stream.temp?
142
+ elsif stream.respond_to? :clean
143
+ stream.clean
144
+ else
145
+ raise ArgumentError, "must at least respond to :clean (#{stream})"
148
146
  end
149
- stream.unlink if stream.exist? and stream.temp?
150
147
  end
151
148
  end
152
149
 
@@ -1,15 +1,13 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
3
  # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: factory.rb 344 2005-09-08 01:44:18Z ertai $
5
-
6
- Commands.import!
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/datas/factory.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
7
5
 
8
6
  module Commands
9
7
 
10
8
  module Datas
11
9
 
12
- class Factory < Data
10
+ class Factory < self::Data
13
11
 
14
12
  attr_accessor :command_data_class
15
13
 
@@ -0,0 +1,52 @@
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/datas/pipe.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
+
6
+ class IOPipe
7
+ attr_accessor :reader, :writer, :open_mode
8
+ def initialize
9
+ @reader, @writer = IO.pipe
10
+ @open_mode = :w
11
+ end
12
+ def open ( mode=:r )
13
+ case mode.to_sym
14
+ when :r
15
+ @writer.close
16
+ @reader
17
+ when :w
18
+ @reader.close
19
+ @writer
20
+ else raise ArgumentError, "Bad open mode: #{mode.inspect}"
21
+ end
22
+ end
23
+ def close
24
+ @reader.close
25
+ @writer.close
26
+ end
27
+ alias_method :clean, :close
28
+ def to_io_for_commands
29
+ open(open_mode)
30
+ end
31
+ def read
32
+ open.read
33
+ end
34
+ end
35
+
36
+ module Commands
37
+
38
+ module Datas
39
+
40
+ class Pipe < self::Data
41
+
42
+ def initialize ( *a, &b )
43
+ super
44
+ @output = IOPipe.new
45
+ @error = IOPipe.new
46
+ end
47
+
48
+ end # class Pipe
49
+
50
+ end # module Datas
51
+
52
+ end # module Commands
@@ -1,13 +1,13 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
3
  # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: temp.rb 343 2005-09-08 01:32:57Z ertai $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/datas/temp.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
5
 
6
6
  module Commands
7
7
 
8
8
  module Datas
9
9
 
10
- class Temp < Data
10
+ class Temp < self::Data
11
11
 
12
12
  def initialize ( *a, &b )
13
13
  super
@@ -1,16 +1,11 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
3
  # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: datas.rb 255 2005-06-01 00:08:46Z ertai $
5
-
6
- require 'commands'
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/datas.rb 8049 2005-12-31T16:01:12.162089Z ertai $
7
5
 
8
6
  module Commands
9
7
 
10
8
  module Datas
11
-
12
- autoloaded_module(__FILE__, false)
13
-
14
9
  end # module Datas
15
10
 
16
11
  end # module Commands
@@ -1,9 +1,7 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
3
  # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: factory.rb 255 2005-06-01 00:08:46Z ertai $
5
-
6
- require 'commands'
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/factory.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
7
5
 
8
6
  module Commands
9
7
 
@@ -1,9 +1,9 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
3
  # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: helpers.rb 255 2005-06-01 00:08:46Z ertai $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/helpers.rb 8049 2005-12-31T16:01:12.162089Z ertai $
5
5
 
6
- require 'commands'
6
+ require 'shellwords'
7
7
 
8
8
  module Commands
9
9
 
@@ -22,15 +22,10 @@ module Commands
22
22
  #
23
23
  # Make a command from a String.
24
24
  #
25
- # Split your command when no quotations are used.
25
+ # Split your command using the Shellwords module.
26
26
  #
27
- # Do not touch the String and give as one argument.
28
27
  def to_cmd
29
- if self =~ /['"`]/
30
- Command.new(self)
31
- else
32
- Command.new(*split(/\s+/))
33
- end
28
+ Shellwords.shellwords(self).to_cmd
34
29
  end
35
30
 
36
31
  def to_io_for_commands
@@ -46,7 +41,7 @@ module Commands
46
41
  class ::Array
47
42
 
48
43
  def to_cmd
49
- Command.new(*self)
44
+ Commands::Command.new(*self)
50
45
  end
51
46
 
52
47
  end # class ::Array
@@ -66,7 +61,7 @@ module Commands
66
61
  "foo b/ar \t \n qu44x32".to_cmd.to_a)
67
62
 
68
63
  s = "foo 'b/ar \t' \n qu44x32"
69
- assert_equal([s], s.to_cmd.to_a)
64
+ assert_equal(["foo", "b/ar \t", "qu44x32"], s.to_cmd.to_a)
70
65
  end
71
66
 
72
67
  def test_array_to_cmd
data/lib/commands/pipe.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
3
  # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: pipe.rb 365 2005-09-24 17:24:01Z ertai $
5
-
6
- require 'commands'
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/pipe.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
7
5
 
8
6
  class IO
9
7
 
@@ -13,7 +11,7 @@ class IO
13
11
 
14
12
  class << self
15
13
 
16
- alias_method :pipe_without_pipe?, :pipe
14
+ alias_method :pipe_without_pipe?, :pipe unless method_defined? :pipe_without_pipe?
17
15
 
18
16
  def pipe
19
17
  ios = pipe_without_pipe?
@@ -35,7 +33,7 @@ module Commands
35
33
  @cmds = cmds.flatten.map { |x| x.dup }
36
34
  end
37
35
 
38
- def run ( runner=@runner )
36
+ def run ( runner=@runner, *a )
39
37
  datas = Datas::Composite.new
40
38
  runner = runner.dup
41
39
  runner.hook_trigger :display_command, self
@@ -53,7 +51,7 @@ module Commands
53
51
  wr.close
54
52
  end
55
53
  runner = runner.dup
56
- datas << @cmds.last.run(runner)
54
+ datas << @cmds.last.run(runner, *a)
57
55
  datas.waitpid if runner.is_a? Runners::System
58
56
  datas
59
57
  end
@@ -1,16 +1,14 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
3
  # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: exec.rb 255 2005-06-01 00:08:46Z ertai $
5
-
6
- require 'commands'
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/runners/exec.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
7
5
 
8
6
  module Commands
9
7
 
10
8
  module Runners
11
9
 
12
10
  class Exec < Runner
13
- concrete
11
+ include Concrete
14
12
 
15
13
  def exec ( aCommand, data )
16
14
  Kernel.exec(*aCommand.to_a)
@@ -18,8 +16,6 @@ module Commands
18
16
 
19
17
  end # class Exec
20
18
 
21
-
22
-
23
19
  test_section __FILE__ do
24
20
 
25
21
  class ExecTest < Test::Unit::TestCase
@@ -1,16 +1,14 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
3
  # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: fork.rb 374 2005-09-29 19:25:47Z ertai $
5
-
6
- require 'commands'
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/runners/fork.rb 8049 2005-12-31T16:01:12.162089Z ertai $
7
5
 
8
6
  module Commands
9
7
 
10
8
  module Runners
11
9
 
12
10
  class Fork < Exec
13
- concrete
11
+ include Concrete
14
12
 
15
13
  #
16
14
  # Hooks declaration
@@ -19,7 +17,6 @@ module Commands
19
17
  hook_declare :exception_raised_during_exec
20
18
  hook_declare :already_killed
21
19
  hook_declare :waitpid
22
- hook_declare :failure
23
20
  hook_declare :son
24
21
  hook_declare :kill
25
22
 
@@ -39,7 +36,7 @@ module Commands
39
36
  end
40
37
  hook_trigger :waitpid, data
41
38
  if data.status.nil? or not data.status.exitstatus.zero?
42
- hook_trigger :failure, data
39
+ hook_trigger :failure, aCommand, data
43
40
  end
44
41
  end
45
42
 
@@ -69,11 +66,6 @@ module Commands
69
66
  end
70
67
 
71
68
 
72
- def raise_on_failures
73
- hooker_subscribe FailureHooker.new
74
- self
75
- end
76
-
77
69
  def before_exec ( command, data )
78
70
  TempPath.clean
79
71
  end
@@ -81,15 +73,6 @@ module Commands
81
73
  end # class Fork
82
74
 
83
75
 
84
- class FailureHooker
85
- class Error < Exception
86
- end
87
- def failure ( data )
88
- raise Error, { 'Command failed' => data }.to_yaml
89
- end
90
- end
91
-
92
-
93
76
  test_section __FILE__ do
94
77
 
95
78
  class ForkTest < Test::Unit::TestCase
@@ -1,9 +1,7 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
2
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
3
3
  # License:: GNU General Public License (GPL).
4
- # Revision:: $Id: mockable.rb 365 2005-09-24 17:24:01Z ertai $
5
-
6
- require 'commands'
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/lib/commands/runners/mockable.rb 8049 2005-12-31T16:01:12.162089Z ertai $
7
5
 
8
6
  module Commands
9
7
 
@@ -31,13 +29,12 @@ module Commands
31
29
  self
32
30
  end
33
31
 
34
- end # module Mock
32
+ end # module Mockable
35
33
 
36
- class Runner
37
- include Mockable
38
- end
34
+ Runner.include Mockable
39
35
 
40
36
  test_section __FILE__ do
37
+ Commands::Helpers.import!
41
38
 
42
39
  class MockTest < Test::Unit::TestCase
43
40
 
@@ -0,0 +1,44 @@
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/runners/no_run.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
+
6
+ module Commands
7
+
8
+ module Runners
9
+
10
+ # This very particular runner returns it's command instead of running it.
11
+ class NoRun < Runner
12
+ include Concrete
13
+
14
+ def run ( aCommand )
15
+ aCommand
16
+ end
17
+
18
+ end # class NoRun
19
+
20
+
21
+
22
+ test_section __FILE__ do
23
+
24
+ class NoRunTest < Test::Unit::TestCase
25
+
26
+ def setup
27
+ assert_nothing_raised { @runner = NoRun.new }
28
+ end
29
+
30
+ def test_0_initialize
31
+ end
32
+
33
+ def test_simple
34
+ cmd = 'sleep'.to_cmd[10]
35
+ assert_kind_of Command, cmd.run(@runner)
36
+ end
37
+
38
+ end # class NoRunTest
39
+
40
+ end
41
+
42
+ end # module Runners
43
+
44
+ end # module Commands
@@ -0,0 +1,49 @@
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/runners/popen.rb 21865 2006-02-18T17:13:28.680350Z pouillar $
5
+
6
+ module Commands
7
+
8
+ module Runners
9
+
10
+ class Popen < Fork
11
+ make Concrete
12
+
13
+ def initialize ( *a, &b )
14
+ super
15
+ @command_data_factory.command_data_class = Datas::Pipe
16
+ end
17
+
18
+ end # class Popen
19
+
20
+
21
+
22
+ test_section __FILE__ do
23
+
24
+ class PopenTest < Test::Unit::TestCase
25
+
26
+ def setup
27
+ assert_nothing_raised { @runner = Popen.new }
28
+ end
29
+
30
+ def test_0_initialize
31
+ end
32
+
33
+ # FIXME
34
+ def test_simple
35
+ # TempPath.new do |tmp|
36
+ # cmd = %Q[ruby -e "sleep 0.5
37
+ # File.open('#{tmp}', 'w') { |f| f.puts :foo }"]
38
+ # @runner.run(cmd.to_cmd)
39
+ # assert(tmp.exist?)
40
+ # end
41
+ end
42
+
43
+ end # class PopenTest
44
+
45
+ end
46
+
47
+ end # module Runners
48
+
49
+ end # module Commands