right_popen 1.0.9-x86-mswin32-60 → 1.0.11-x86-mswin32-60
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.
- data/README.rdoc +7 -0
- data/lib/right_popen.rb +3 -2
- data/lib/win32/right_popen.rb +23 -4
- data/lib/win32/right_popen.so +0 -0
- data/right_popen.gemspec +2 -2
- data/spec/right_popen_spec.rb +182 -105
- data/spec/spec_helper.rb +16 -0
- metadata +14 -30
data/README.rdoc
CHANGED
@@ -26,6 +26,11 @@ to report issues.
|
|
26
26
|
@stdout_text = ""
|
27
27
|
@stderr_text = ""
|
28
28
|
@exit_status = nil
|
29
|
+
@pid = nil
|
30
|
+
|
31
|
+
def on_pid(pid)
|
32
|
+
@pid = pid
|
33
|
+
end
|
29
34
|
|
30
35
|
def on_read_stdout(data)
|
31
36
|
@stdout_text << data
|
@@ -45,6 +50,7 @@ to report issues.
|
|
45
50
|
RightScale.popen3(:command => command,
|
46
51
|
:target => self,
|
47
52
|
:environment => nil,
|
53
|
+
:pid_handler => :on_pid,
|
48
54
|
:stdout_handler => :on_read_stdout,
|
49
55
|
:stderr_handler => :on_read_stderr,
|
50
56
|
:exit_handler => :on_exit)
|
@@ -60,6 +66,7 @@ to report issues.
|
|
60
66
|
puts "@stdout_text = #{@stdout_text}"
|
61
67
|
puts "@stderr_text = #{@stderr_text}"
|
62
68
|
puts "@exit_status.exitstatus = #{@exit_status.exitstatus}"
|
69
|
+
puts "@pid = #{@pid}"
|
63
70
|
|
64
71
|
|
65
72
|
== INSTALLATION
|
data/lib/right_popen.rb
CHANGED
@@ -45,10 +45,11 @@ module RightScale
|
|
45
45
|
# All handlers must be methods exposed by the given target.
|
46
46
|
#
|
47
47
|
# === Parameters
|
48
|
-
# options[:command](String):: Command to execute, including any arguments
|
48
|
+
# options[:command](String or Array):: Command to execute, including any arguments as a single string or an array of command and arguments
|
49
49
|
# options[:environment](Hash):: Hash of environment variables values keyed by name
|
50
50
|
# options[:input](String):: Input string that will get streamed into child's process stdin
|
51
51
|
# options[:target](Object):: object defining handler methods to be called, optional (no handlers can be defined if not specified)
|
52
|
+
# options[:pid_handler](String):: PID notification handler method name, optional
|
52
53
|
# options[:stdout_handler](String):: Stdout handler method name, optional
|
53
54
|
# options[:stderr_handler](String):: Stderr handler method name, optional
|
54
55
|
# options[:exit_handler](String):: Exit handler method name, optional
|
@@ -58,7 +59,7 @@ module RightScale
|
|
58
59
|
def self.popen3(options)
|
59
60
|
raise "EventMachine reactor must be started" unless EM.reactor_running?
|
60
61
|
raise "Missing command" unless options[:command]
|
61
|
-
raise "Missing target" unless options[:target] || !options[:stdout_handler] && !options[:stderr_handler] && !options[:exit_handler]
|
62
|
+
raise "Missing target" unless options[:target] || !options[:stdout_handler] && !options[:stderr_handler] && !options[:exit_handler] && !options[:pid_handler]
|
62
63
|
RightScale.popen3_imp(options)
|
63
64
|
true
|
64
65
|
end
|
data/lib/win32/right_popen.rb
CHANGED
@@ -53,7 +53,7 @@ module RightScale
|
|
53
53
|
end
|
54
54
|
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
# Provides an eventmachine callback handler for the stdout stream.
|
58
58
|
module StdOutHandler
|
59
59
|
|
@@ -70,7 +70,7 @@ module RightScale
|
|
70
70
|
|
71
71
|
# === Parameters
|
72
72
|
# pid(Integer):: Process ID.
|
73
|
-
#
|
73
|
+
#
|
74
74
|
# exitstatus(Integer):: Process exit code
|
75
75
|
def initialize(pid, exitstatus)
|
76
76
|
@pid = pid
|
@@ -200,15 +200,31 @@ module RightScale
|
|
200
200
|
def self.popen3_imp(options)
|
201
201
|
raise "EventMachine reactor must be started" unless EM.reactor_running?
|
202
202
|
|
203
|
+
# merge command string
|
204
|
+
unless options[:command].instance_of?(String)
|
205
|
+
options[:command] = options[:command].join(' ')
|
206
|
+
end
|
207
|
+
|
203
208
|
# merge and format environment strings, if necessary.
|
204
209
|
environment_hash = options[:environment] || {}
|
205
210
|
environment_strings = RightPopenEx.merge_environment(environment_hash)
|
206
211
|
|
212
|
+
# resolve command string from array, if necessary.
|
213
|
+
cmd = options[:command]
|
214
|
+
if cmd.kind_of?(Array)
|
215
|
+
escaped = []
|
216
|
+
cmd.flatten.each do |arg|
|
217
|
+
value = arg.to_s
|
218
|
+
escaped << (value.index(' ') ? "\"#{value}\"" : value)
|
219
|
+
end
|
220
|
+
cmd = escaped.join(" ")
|
221
|
+
end
|
222
|
+
|
207
223
|
# launch cmd and request asynchronous output.
|
208
224
|
mode = "t"
|
209
225
|
show_window = false
|
210
226
|
asynchronous_output = true
|
211
|
-
stream_in, stream_out, stream_err, pid = RightPopen.popen4(
|
227
|
+
stream_in, stream_out, stream_err, pid = RightPopen.popen4(cmd, mode, show_window, asynchronous_output, environment_strings)
|
212
228
|
|
213
229
|
# close input immediately.
|
214
230
|
stream_in.close if options[:input].nil?
|
@@ -217,7 +233,10 @@ module RightScale
|
|
217
233
|
# streams aren't used directly by the connectors except that they are closed
|
218
234
|
# on unbind.
|
219
235
|
stderr_eventable = EM.watch(stream_err, StdErrHandler, options, stream_err) { |c| c.notify_readable = true } if options[:stderr_handler]
|
220
|
-
EM.watch(stream_out, StdOutHandler, options, stderr_eventable, stream_out, pid)
|
236
|
+
EM.watch(stream_out, StdOutHandler, options, stderr_eventable, stream_out, pid) do |c|
|
237
|
+
c.notify_readable = true
|
238
|
+
options[:target].method(options[:pid_handler]).call(pid) if options[:pid_handler]
|
239
|
+
end
|
221
240
|
EM.attach(stream_in, StdInHandler, options, stream_in) if options[:input]
|
222
241
|
|
223
242
|
# note that control returns to the caller, but the launched cmd continues
|
data/lib/win32/right_popen.so
CHANGED
Binary file
|
data/right_popen.gemspec
CHANGED
@@ -6,8 +6,8 @@ end
|
|
6
6
|
|
7
7
|
spec = Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'right_popen'
|
9
|
-
spec.version = '1.0.
|
10
|
-
spec.authors = ['Scott Messier', 'Raphael Simon']
|
9
|
+
spec.version = '1.0.11'
|
10
|
+
spec.authors = ['Scott Messier', 'Raphael Simon', 'Graham Hughes']
|
11
11
|
spec.email = 'scott@rightscale.com'
|
12
12
|
spec.homepage = 'https://github.com/rightscale/right_popen'
|
13
13
|
if is_windows?
|
data/spec/right_popen_spec.rb
CHANGED
@@ -1,182 +1,233 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
2
|
|
3
|
-
|
4
|
-
STANDARD_MESSAGE = 'Standard message'
|
5
|
-
ERROR_MESSAGE = 'Error message'
|
6
|
-
EXIT_STATUS = 146
|
3
|
+
describe 'RightScale::popen3' do
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
module RightPopenSpec
|
6
|
+
class Runner
|
7
|
+
class RunnerStatus
|
8
|
+
def initialize(command, block)
|
9
|
+
@output_text = ""
|
10
|
+
@error_text = ""
|
11
|
+
@status = nil
|
12
|
+
@did_timeout = false
|
13
|
+
@callback = block
|
14
|
+
@pid = nil
|
15
|
+
EM.next_tick do
|
16
|
+
@timeout = EM::Timer.new(2) do
|
17
|
+
puts "\n** Failed to run #{command.inspect}: Timeout"
|
18
|
+
@did_timeout = true
|
19
|
+
@callback.call(self)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
11
23
|
|
12
|
-
|
13
|
-
REPEAT_TEST_COUNTER = 256
|
24
|
+
attr_accessor :output_text, :error_text, :status, :did_timeout, :pid
|
14
25
|
|
15
|
-
def
|
16
|
-
|
17
|
-
end
|
26
|
+
def on_read_stdout(data)
|
27
|
+
@output_text << data
|
28
|
+
end
|
18
29
|
|
19
|
-
|
30
|
+
def on_read_stderr(data)
|
31
|
+
@error_text << data
|
32
|
+
end
|
20
33
|
|
21
|
-
|
34
|
+
def on_pid(pid)
|
35
|
+
raise "PID already set!" unless @pid.nil?
|
36
|
+
@pid = pid
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_exit(status)
|
40
|
+
@timeout.cancel if @timeout
|
41
|
+
@status = status
|
42
|
+
@callback.call(self)
|
43
|
+
end
|
44
|
+
end
|
22
45
|
|
23
|
-
class Runner
|
24
46
|
def initialize
|
47
|
+
@count = 0
|
25
48
|
@done = false
|
26
|
-
@output_text = nil
|
27
|
-
@error_text = nil
|
28
|
-
@status = nil
|
29
49
|
@last_exception = nil
|
30
50
|
@last_iteration = 0
|
31
51
|
end
|
32
52
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
@timeout = EM::Timer.new(2) { puts "\n** Failed to run #{command.inspect}: Timeout"; EM.stop }
|
37
|
-
@output_text = ''
|
38
|
-
@error_text = ''
|
39
|
-
@status = nil
|
40
|
-
RightScale.popen3(:command => command,
|
53
|
+
def do_right_popen(command, env=nil, input=nil, &callback)
|
54
|
+
status = RunnerStatus.new(command, callback)
|
55
|
+
RightScale.popen3(:command => command,
|
41
56
|
:input => input,
|
42
|
-
:target =>
|
57
|
+
:target => status,
|
43
58
|
:environment => env,
|
44
|
-
:stdout_handler => :on_read_stdout,
|
45
|
-
:stderr_handler => :on_read_stderr,
|
59
|
+
:stdout_handler => :on_read_stdout,
|
60
|
+
:stderr_handler => :on_read_stderr,
|
61
|
+
:pid_handler => :on_pid,
|
46
62
|
:exit_handler => :on_exit)
|
63
|
+
status
|
47
64
|
end
|
48
65
|
|
49
66
|
def run_right_popen(command, env=nil, input=nil, count=1)
|
50
67
|
begin
|
51
|
-
@
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
68
|
+
@iterations = 0
|
69
|
+
EM.run do
|
70
|
+
EM.next_tick do
|
71
|
+
do_right_popen(command, env, input) do |status|
|
72
|
+
maybe_continue(status)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
@status
|
57
77
|
rescue Exception => e
|
58
78
|
puts "\n** Failed: #{e.message} FROM\n#{e.backtrace.join("\n")}"
|
59
79
|
raise e
|
60
80
|
end
|
61
81
|
end
|
62
82
|
|
63
|
-
def
|
64
|
-
@
|
65
|
-
|
66
|
-
|
67
|
-
def on_read_stderr(data)
|
68
|
-
@error_text << data
|
69
|
-
end
|
70
|
-
|
71
|
-
def on_exit(status)
|
72
|
-
@last_iteration += 1
|
73
|
-
@timeout.cancel if @timeout
|
74
|
-
if @last_iteration < @count
|
75
|
-
EM.next_tick do
|
76
|
-
print '+'
|
77
|
-
STDOUT.flush
|
78
|
-
do_right_popen(@command, @env)
|
79
|
-
end
|
83
|
+
def maybe_continue(status)
|
84
|
+
@iterations += 1
|
85
|
+
if @iterations < @count
|
86
|
+
do_right_popen(command, env, input) {|status| maybe_continue(status)}
|
80
87
|
else
|
81
|
-
|
88
|
+
@status = status
|
82
89
|
EM.stop
|
83
90
|
end
|
84
|
-
@status = status
|
85
91
|
end
|
86
92
|
end
|
93
|
+
end
|
87
94
|
|
95
|
+
def is_windows?
|
96
|
+
return !!(RUBY_PLATFORM =~ /mswin/)
|
88
97
|
end
|
89
98
|
|
90
99
|
it 'should redirect output' do
|
91
100
|
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'produce_output.rb'))}\" \"#{STANDARD_MESSAGE}\" \"#{ERROR_MESSAGE}\""
|
92
101
|
runner = RightPopenSpec::Runner.new
|
93
|
-
runner.run_right_popen(command)
|
94
|
-
|
95
|
-
|
96
|
-
|
102
|
+
status = runner.run_right_popen(command)
|
103
|
+
status.status.exitstatus.should == 0
|
104
|
+
status.output_text.should == STANDARD_MESSAGE + "\n"
|
105
|
+
status.error_text.should == ERROR_MESSAGE + "\n"
|
106
|
+
status.pid.should > 0
|
97
107
|
end
|
98
108
|
|
99
109
|
it 'should return the right status' do
|
100
110
|
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'produce_status.rb'))}\" #{EXIT_STATUS}"
|
101
111
|
runner = RightPopenSpec::Runner.new
|
102
|
-
runner.run_right_popen(command)
|
103
|
-
|
104
|
-
|
105
|
-
|
112
|
+
status = runner.run_right_popen(command)
|
113
|
+
status.status.exitstatus.should == EXIT_STATUS
|
114
|
+
status.output_text.should == ''
|
115
|
+
status.error_text.should == ''
|
116
|
+
status.pid.should > 0
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should correctly handle many small processes' do
|
120
|
+
pending 'Set environment variable TEST_STRESS to enable' unless ENV['TEST_STRESS']
|
121
|
+
TO_RUN = 100
|
122
|
+
command = is_windows? ? "cmd.exe /c exit 0" : "exit 0"
|
123
|
+
runner = RightPopenSpec::Runner.new
|
124
|
+
@completed = 0
|
125
|
+
@started = 0
|
126
|
+
run_cmd = Proc.new do
|
127
|
+
runner.do_right_popen(command) do |status|
|
128
|
+
@completed += 1
|
129
|
+
status.status.exitstatus.should == 0
|
130
|
+
status.output_text.should == ''
|
131
|
+
status.error_text.should == ''
|
132
|
+
status.pid.should > 0
|
133
|
+
end
|
134
|
+
@started += 1
|
135
|
+
if @started < TO_RUN
|
136
|
+
EM.next_tick { run_cmd.call }
|
137
|
+
end
|
138
|
+
end
|
139
|
+
EM.run do
|
140
|
+
EM.next_tick { run_cmd.call }
|
141
|
+
|
142
|
+
EM::PeriodicTimer.new(1) do
|
143
|
+
if @completed >= TO_RUN
|
144
|
+
EM.stop
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
106
148
|
end
|
107
149
|
|
108
150
|
it 'should preserve the integrity of stdout when stderr is unavailable' do
|
109
151
|
count = LARGE_OUTPUT_COUNTER
|
110
152
|
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'produce_stdout_only.rb'))}\" #{count}"
|
111
153
|
runner = RightPopenSpec::Runner.new
|
112
|
-
runner.run_right_popen(command)
|
113
|
-
|
154
|
+
status = runner.run_right_popen(command)
|
155
|
+
status.status.exitstatus.should == 0
|
114
156
|
|
115
157
|
results = ''
|
116
158
|
count.times do |i|
|
117
159
|
results << "stdout #{i}\n"
|
118
160
|
end
|
119
|
-
|
120
|
-
|
161
|
+
status.output_text.should == results
|
162
|
+
status.error_text.should == ''
|
163
|
+
status.pid.should > 0
|
121
164
|
end
|
122
165
|
|
123
166
|
it 'should preserve the integrity of stderr when stdout is unavailable' do
|
124
167
|
count = LARGE_OUTPUT_COUNTER
|
125
168
|
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'produce_stderr_only.rb'))}\" #{count}"
|
126
169
|
runner = RightPopenSpec::Runner.new
|
127
|
-
runner.run_right_popen(command)
|
128
|
-
|
170
|
+
status = runner.run_right_popen(command)
|
171
|
+
status.status.exitstatus.should == 0
|
129
172
|
|
130
173
|
results = ''
|
131
174
|
count.times do |i|
|
132
175
|
results << "stderr #{i}\n"
|
133
176
|
end
|
134
|
-
|
135
|
-
|
177
|
+
status.error_text.should == results
|
178
|
+
status.output_text.should == ''
|
179
|
+
status.pid.should > 0
|
136
180
|
end
|
137
181
|
|
138
182
|
it 'should preserve the integrity of stdout and stderr despite interleaving' do
|
139
183
|
count = LARGE_OUTPUT_COUNTER
|
140
184
|
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'produce_mixed_output.rb'))}\" #{count}"
|
141
185
|
runner = RightPopenSpec::Runner.new
|
142
|
-
runner.run_right_popen(command)
|
143
|
-
|
186
|
+
status = runner.run_right_popen(command)
|
187
|
+
status.status.exitstatus.should == 99
|
144
188
|
|
145
189
|
results = ''
|
146
190
|
count.times do |i|
|
147
191
|
results << "stdout #{i}\n"
|
148
192
|
end
|
149
|
-
|
193
|
+
status.output_text.should == results
|
150
194
|
|
151
195
|
results = ''
|
152
196
|
count.times do |i|
|
153
197
|
(results << "stderr #{i}\n") if 0 == i % 10
|
154
198
|
end
|
155
|
-
|
199
|
+
status.error_text.should == results
|
200
|
+
status.pid.should > 0
|
156
201
|
end
|
157
|
-
|
202
|
+
|
158
203
|
it 'should setup environment variables' do
|
159
204
|
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'print_env.rb'))}\""
|
160
205
|
runner = RightPopenSpec::Runner.new
|
161
|
-
runner.run_right_popen(command)
|
162
|
-
|
163
|
-
|
164
|
-
runner.run_right_popen(command, :__test__ => '42')
|
165
|
-
|
166
|
-
|
206
|
+
status = runner.run_right_popen(command)
|
207
|
+
status.status.exitstatus.should == 0
|
208
|
+
status.output_text.should_not include('_test_')
|
209
|
+
status = runner.run_right_popen(command, :__test__ => '42')
|
210
|
+
status.status.exitstatus.should == 0
|
211
|
+
status.output_text.should match(/^__test__=42$/)
|
212
|
+
status.pid.should > 0
|
167
213
|
end
|
168
214
|
|
169
215
|
it 'should restore environment variables' do
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
216
|
+
begin
|
217
|
+
ENV['__test__'] = '41'
|
218
|
+
old_envs = {}
|
219
|
+
ENV.each { |k, v| old_envs[k] = v }
|
220
|
+
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'print_env.rb'))}\""
|
221
|
+
runner = RightPopenSpec::Runner.new
|
222
|
+
status = runner.run_right_popen(command, :__test__ => '42')
|
223
|
+
status.status.exitstatus.should == 0
|
224
|
+
status.output_text.should match(/^__test__=42$/)
|
225
|
+
ENV.each { |k, v| old_envs[k].should == v }
|
226
|
+
old_envs.each { |k, v| ENV[k].should == v }
|
227
|
+
status.pid.should > 0
|
228
|
+
ensure
|
229
|
+
ENV.delete('__test__')
|
230
|
+
end
|
180
231
|
end
|
181
232
|
|
182
233
|
if is_windows?
|
@@ -185,37 +236,63 @@ describe 'RightScale::popen3' do
|
|
185
236
|
it 'should merge the PATH variable instead of overriding it' do
|
186
237
|
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'print_env.rb'))}\""
|
187
238
|
runner = RightPopenSpec::Runner.new
|
188
|
-
runner.run_right_popen(command, 'PATH' => "c:/bogus\\bin")
|
189
|
-
|
190
|
-
|
239
|
+
status = runner.run_right_popen(command, 'PATH' => "c:/bogus\\bin")
|
240
|
+
status.status.exitstatus.should == 0
|
241
|
+
status.output_text.should include('PATH=c:\\bogus\\bin;')
|
242
|
+
status.pid.should > 0
|
191
243
|
end
|
192
244
|
else
|
193
245
|
it 'should allow running bash command lines starting with a built-in command' do
|
194
246
|
command = "for i in 1 2 3 4 5; do echo $i;done"
|
195
247
|
runner = RightPopenSpec::Runner.new
|
196
|
-
runner.run_right_popen(command)
|
197
|
-
|
198
|
-
|
248
|
+
status = runner.run_right_popen(command)
|
249
|
+
status.status.exitstatus.should == 0
|
250
|
+
status.output_text.should == "1\n2\n3\n4\n5\n"
|
251
|
+
status.pid.should > 0
|
199
252
|
end
|
253
|
+
|
254
|
+
it 'should support running background processes' do
|
255
|
+
command = "(sleep 20)&"
|
256
|
+
now = Time.now
|
257
|
+
runner = RightPopenSpec::Runner.new
|
258
|
+
status = runner.run_right_popen(command)
|
259
|
+
finished = Time.now
|
260
|
+
(finished - now).should < 20
|
261
|
+
status.did_timeout.should be_false
|
262
|
+
status.status.exitstatus.should == 0
|
263
|
+
status.output_text.should == ""
|
264
|
+
status.pid.should > 0
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'should support raw command arguments' do
|
269
|
+
command = is_windows? ? ["cmd.exe", "/c", "echo", "*"] : ["echo", "*"]
|
270
|
+
runner = RightPopenSpec::Runner.new
|
271
|
+
status = runner.run_right_popen(command)
|
272
|
+
status.status.exitstatus.should == 0
|
273
|
+
status.output_text.should == "*\n"
|
274
|
+
status.pid.should > 0
|
200
275
|
end
|
201
276
|
|
202
277
|
it 'should run repeatedly without leaking resources' do
|
203
278
|
pending 'Set environment variable TEST_LEAK to enable' unless ENV['TEST_LEAK']
|
204
279
|
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'produce_output.rb'))}\" \"#{STANDARD_MESSAGE}\" \"#{ERROR_MESSAGE}\""
|
205
280
|
runner = RightPopenSpec::Runner.new
|
206
|
-
runner.run_right_popen(command, nil, nil, REPEAT_TEST_COUNTER)
|
207
|
-
|
208
|
-
|
209
|
-
|
281
|
+
status = runner.run_right_popen(command, nil, nil, REPEAT_TEST_COUNTER)
|
282
|
+
status.status.exitstatus.should == 0
|
283
|
+
status.output_text.should == STANDARD_MESSAGE + "\n"
|
284
|
+
status.error_text.should == ERROR_MESSAGE + "\n"
|
285
|
+
status.pid.should > 0
|
210
286
|
end
|
211
287
|
|
212
288
|
it 'should pass input to child process' do
|
213
289
|
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'increment.rb'))}\""
|
214
290
|
runner = RightPopenSpec::Runner.new
|
215
|
-
runner.run_right_popen(command, nil, "42\n")
|
216
|
-
|
217
|
-
|
218
|
-
|
291
|
+
status = runner.run_right_popen(command, nil, "42\n")
|
292
|
+
status.status.exitstatus.should == 0
|
293
|
+
status.output_text.should == "43\n"
|
294
|
+
status.error_text.should be_empty
|
295
|
+
status.pid.should > 0
|
219
296
|
end
|
220
297
|
|
221
298
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,3 +2,19 @@ require 'rubygems'
|
|
2
2
|
require 'spec'
|
3
3
|
require 'eventmachine'
|
4
4
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'right_popen')
|
5
|
+
|
6
|
+
RUBY_CMD = 'ruby'
|
7
|
+
STANDARD_MESSAGE = 'Standard message'
|
8
|
+
ERROR_MESSAGE = 'Error message'
|
9
|
+
EXIT_STATUS = 146
|
10
|
+
|
11
|
+
# manually bump count up for more aggressive multi-processor testing, lessen
|
12
|
+
# for a quick smoke test
|
13
|
+
LARGE_OUTPUT_COUNTER = 1000
|
14
|
+
|
15
|
+
# bump up count for most exhaustive leak detection.
|
16
|
+
REPEAT_TEST_COUNTER = 256
|
17
|
+
|
18
|
+
def is_windows?
|
19
|
+
return RUBY_PLATFORM =~ /mswin/
|
20
|
+
end
|
metadata
CHANGED
@@ -1,51 +1,39 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_popen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 1
|
7
|
-
- 0
|
8
|
-
- 9
|
9
|
-
version: 1.0.9
|
4
|
+
version: 1.0.11
|
10
5
|
platform: x86-mswin32-60
|
11
6
|
authors:
|
12
7
|
- Scott Messier
|
13
8
|
- Raphael Simon
|
9
|
+
- Graham Hughes
|
14
10
|
autorequire:
|
15
11
|
bindir: bin
|
16
12
|
cert_chain: []
|
17
13
|
|
18
|
-
date: 2010-
|
14
|
+
date: 2010-09-08 00:00:00 -07:00
|
19
15
|
default_executable:
|
20
16
|
dependencies:
|
21
17
|
- !ruby/object:Gem::Dependency
|
22
18
|
name: eventmachine
|
23
|
-
|
24
|
-
|
19
|
+
type: :runtime
|
20
|
+
version_requirement:
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
22
|
requirements:
|
26
23
|
- - ">="
|
27
24
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
- 12
|
31
|
-
- 10
|
32
25
|
version: 0.12.10
|
33
|
-
|
34
|
-
version_requirements: *id001
|
26
|
+
version:
|
35
27
|
- !ruby/object:Gem::Dependency
|
36
28
|
name: win32-process
|
37
|
-
|
38
|
-
|
29
|
+
type: :runtime
|
30
|
+
version_requirement:
|
31
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
32
|
requirements:
|
40
33
|
- - ">="
|
41
34
|
- !ruby/object:Gem::Version
|
42
|
-
segments:
|
43
|
-
- 0
|
44
|
-
- 6
|
45
|
-
- 1
|
46
35
|
version: 0.6.1
|
47
|
-
|
48
|
-
version_requirements: *id002
|
36
|
+
version:
|
49
37
|
description: |
|
50
38
|
RightPopen allows running external processes aynchronously while still
|
51
39
|
capturing their standard and error outputs. It relies on EventMachine for most
|
@@ -95,22 +83,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
83
|
requirements:
|
96
84
|
- - ">="
|
97
85
|
- !ruby/object:Gem::Version
|
98
|
-
segments:
|
99
|
-
- 1
|
100
|
-
- 8
|
101
|
-
- 6
|
102
86
|
version: 1.8.6
|
87
|
+
version:
|
103
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
89
|
requirements:
|
105
90
|
- - ">="
|
106
91
|
- !ruby/object:Gem::Version
|
107
|
-
segments:
|
108
|
-
- 0
|
109
92
|
version: "0"
|
93
|
+
version:
|
110
94
|
requirements: []
|
111
95
|
|
112
96
|
rubyforge_project: right_popen
|
113
|
-
rubygems_version: 1.3.
|
97
|
+
rubygems_version: 1.3.5
|
114
98
|
signing_key:
|
115
99
|
specification_version: 3
|
116
100
|
summary: Provides a platform-independent popen implementation
|