childprocess 0.3.5 → 0.3.6

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.
@@ -90,6 +90,10 @@ module ChildProcess
90
90
  if duplex?
91
91
  stdin = @process.getOutputStream.to_io
92
92
  stdin.sync = true
93
+ stdin.instance_variable_set(:@java_stream, @process.getOutputStream)
94
+ def stdin.__flushit; @java_stream.flush; end #The stream provided is a BufferedeOutputStream, so we have to flush it to make the bytes flow to the process
95
+ def stdin.flush; super; self.__flushit; end
96
+ def stdin.puts(*args); super(*args); self.__flushit; end
93
97
 
94
98
  io._stdin = stdin
95
99
  else
@@ -25,7 +25,7 @@ module ChildProcess
25
25
  def pump
26
26
  buffer = Java.byte[BUFFER_SIZE].new
27
27
 
28
- until @stop
28
+ until @stop && (@input.available == 0)
29
29
  read, avail = 0, 0
30
30
 
31
31
  while read != -1
@@ -1,3 +1,3 @@
1
1
  module ChildProcess
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
@@ -54,6 +54,26 @@ describe ChildProcess do
54
54
  end
55
55
  end
56
56
 
57
+ it "pumps all output" do
58
+ 10.times do |i|
59
+ process = echo
60
+
61
+ out = Tempfile.new("duplex")
62
+
63
+ begin
64
+ process.io.stdout = out
65
+
66
+ process.start
67
+ process.poll_for_exit(exit_timeout)
68
+
69
+ out.rewind
70
+ out.read.should == "hello\n"
71
+ ensure
72
+ out.close
73
+ end
74
+ end
75
+ end
76
+
57
77
  it "can write to stdin if duplex = true" do
58
78
  process = cat
59
79
 
@@ -78,6 +98,40 @@ describe ChildProcess do
78
98
  end
79
99
  end
80
100
 
101
+ it "can write to stdin interactively if duplex = true" do
102
+ process = cat
103
+
104
+ out = Tempfile.new("duplex")
105
+ out.sync = true
106
+
107
+ out_receiver = File.open(out.path, "rb")
108
+ begin
109
+ process.io.stdout = out
110
+ process.io.stderr = out
111
+ process.duplex = true
112
+
113
+ process.start
114
+ process.io.stdin.puts "hello"
115
+ sleep 0.1
116
+ out_receiver.read.should == "hello\n"
117
+ process.io.stdin.puts "new"
118
+ sleep 0.1
119
+ out_receiver.read.should == "new\n"
120
+ process.io.stdin.write "world\n"
121
+ process.io.stdin.flush
122
+ sleep 0.1
123
+ out_receiver.read.should == "world\n"
124
+ process.io.stdin.close
125
+ process.poll_for_exit(exit_timeout)
126
+
127
+ out_receiver.rewind
128
+ out_receiver.read.should == "hello\nnew\nworld\n"
129
+ ensure
130
+ out_receiver.close
131
+ out.close
132
+ end
133
+ end
134
+
81
135
  #
82
136
  # this works on JRuby 1.6.5 on my Mac, but for some reason
83
137
  # hangs on Travis (running 1.6.5.1 + OpenJDK).
@@ -107,6 +107,19 @@ module ChildProcessSpecHelper
107
107
  end
108
108
  end
109
109
 
110
+ def echo
111
+ if ChildProcess.os == :windows
112
+ ruby(<<-CODE)
113
+ STDIN.sync = true
114
+ STDOUT.sync = true
115
+
116
+ puts "hello"
117
+ CODE
118
+ else
119
+ ChildProcess.build("echo", "hello")
120
+ end
121
+ end
122
+
110
123
  def ruby(code)
111
124
  ruby_process(tmp_script(code))
112
125
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: childprocess
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
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: 2012-08-07 00:00:00.000000000 Z
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec