rubysh 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rubysh/runner.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Rubysh
2
2
  class Runner
3
- attr_accessor :command, :targets
3
+ attr_accessor :command, :targets, :parallel_io
4
4
 
5
5
  def initialize(command)
6
6
  @runner_state = :initialized
@@ -288,11 +288,11 @@ module Rubysh
288
288
  if on_write = command.opts[:on_write]
289
289
  @parallel_io.on_write(on_write)
290
290
  else
291
- @parallel_io.on_write do |target_name, written, remaining|
291
+ @parallel_io.on_write do |target_name, data, remaining|
292
292
  if data == Subprocess::ParallelIO::EOF
293
293
  Rubysh.log.debug("EOF reached on #{target_name.inspect}")
294
294
  else
295
- Rubysh.log.debug("Just wrote #{written.inspect} on #{target_name.inspect}")
295
+ Rubysh.log.debug("Just wrote #{data.inspect} on #{target_name.inspect}")
296
296
  end
297
297
  end
298
298
  end
@@ -15,6 +15,14 @@ class Rubysh::Subprocess
15
15
  @writer_buffers = {}
16
16
  end
17
17
 
18
+ def register_reader(reader, name)
19
+ @readers[reader] = name
20
+ end
21
+
22
+ def register_writer(writer, name)
23
+ @writers[writer] = name
24
+ end
25
+
18
26
  def on_read(method=nil, &blk)
19
27
  raise "Can't provide both method and block" if method && blk
20
28
  @on_read = method || blk
@@ -1,3 +1,3 @@
1
1
  module Rubysh
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.4'
3
3
  end
@@ -30,5 +30,36 @@ module RubyshTest::Functional
30
30
  assert_raises(Rubysh::Error::BaseError) {runner.read}
31
31
  end
32
32
  end
33
+
34
+ describe 'when registering a reader post-hoc' do
35
+ it 'successfully uses both the existing and new reader' do
36
+ buffers = {}
37
+ runner = Rubysh('sh', '-c', '
38
+ echo stdout1
39
+ read _
40
+ echo stdout2
41
+ ',
42
+ Rubysh.>, Rubysh.<,
43
+ :on_read => Proc.new do |name, bytes|
44
+ (buffers[name] ||= '') << bytes
45
+ end
46
+ ).run_async
47
+ reader, writer = IO.pipe
48
+ runner.parallel_io.register_reader(reader, :pipe)
49
+
50
+ # run_once may be triggered by sigchld
51
+ runner.parallel_io.run_once until buffers.length > 0
52
+ assert_equal(nil, buffers[:pipe])
53
+ assert_equal("stdout1\n", buffers[:stdout])
54
+ buffers.clear
55
+
56
+ runner.write("stdin\n")
57
+ writer.write('pipe')
58
+
59
+ runner.parallel_io.run_once until buffers[:stdout]
60
+ assert_equal('pipe', buffers[:pipe])
61
+ assert_equal("stdout2\n", buffers[:stdout])
62
+ end
63
+ end
33
64
  end
34
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-10 00:00:00.000000000 Z
12
+ date: 2014-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -143,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  segments:
145
145
  - 0
146
- hash: -1131101407467327753
146
+ hash: -1239245545634239752
147
147
  required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  none: false
149
149
  requirements:
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  version: '0'
153
153
  segments:
154
154
  - 0
155
- hash: -1131101407467327753
155
+ hash: -1239245545634239752
156
156
  requirements: []
157
157
  rubyforge_project:
158
158
  rubygems_version: 1.8.23