right_popen 1.0.8 → 1.0.9
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/Rakefile +55 -55
- data/lib/linux/right_popen.rb +7 -0
- data/lib/right_popen.rb +2 -1
- data/right_popen.gemspec +1 -1
- data/spec/increment.rb +2 -0
- data/spec/print_env.rb +2 -2
- data/spec/produce_mixed_output.rb +8 -8
- data/spec/produce_output.rb +2 -2
- data/spec/produce_stderr_only.rb +5 -5
- data/spec/produce_stdout_only.rb +5 -5
- data/spec/right_popen_spec.rb +17 -6
- metadata +3 -2
data/Rakefile
CHANGED
@@ -1,55 +1,55 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'rake'
|
4
|
-
require 'rake/clean'
|
5
|
-
require 'rake/testtask'
|
6
|
-
require 'rbconfig'
|
7
|
-
|
8
|
-
include Config
|
9
|
-
|
10
|
-
desc "Clean any build files for right_popen"
|
11
|
-
task :clean do
|
12
|
-
if RUBY_PLATFORM =~ /mswin/
|
13
|
-
if File.exists?('ext/Makefile')
|
14
|
-
Dir.chdir('ext') do
|
15
|
-
sh 'nmake distclean'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
rm 'lib/win32/right_popen.so' if File.file?('lib/win32/right_popen.so')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
desc "Build right_popen (but don't install it)"
|
23
|
-
task :build => [:clean] do
|
24
|
-
if RUBY_PLATFORM =~ /mswin/
|
25
|
-
Dir.chdir('ext') do
|
26
|
-
ruby 'extconf.rb'
|
27
|
-
sh 'nmake'
|
28
|
-
end
|
29
|
-
FileUtils::mkdir_p 'lib/win32'
|
30
|
-
mv 'ext/right_popen.so', 'lib/win32'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
desc "Build a binary gem"
|
35
|
-
task :gem => [:build] do
|
36
|
-
Dir["*.gem"].each { |gem| rm gem }
|
37
|
-
ruby 'right_popen.gemspec'
|
38
|
-
end
|
39
|
-
|
40
|
-
desc 'Install the right_popen library as a gem'
|
41
|
-
task :install_gem => [:gem] do
|
42
|
-
file = Dir["*.gem"].first
|
43
|
-
sh "gem install #{file}"
|
44
|
-
end
|
45
|
-
|
46
|
-
desc 'Uninstalls and reinstalls the right_popen library as a gem'
|
47
|
-
task :reinstall_gem do
|
48
|
-
sh "gem uninstall right_popen"
|
49
|
-
sh "rake install_gem"
|
50
|
-
end
|
51
|
-
|
52
|
-
desc 'Runs all spec tests'
|
53
|
-
task :spec do
|
54
|
-
sh "spec spec/*_spec.rb"
|
55
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/clean'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'rbconfig'
|
7
|
+
|
8
|
+
include Config
|
9
|
+
|
10
|
+
desc "Clean any build files for right_popen"
|
11
|
+
task :clean do
|
12
|
+
if RUBY_PLATFORM =~ /mswin/
|
13
|
+
if File.exists?('ext/Makefile')
|
14
|
+
Dir.chdir('ext') do
|
15
|
+
sh 'nmake distclean'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
rm 'lib/win32/right_popen.so' if File.file?('lib/win32/right_popen.so')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Build right_popen (but don't install it)"
|
23
|
+
task :build => [:clean] do
|
24
|
+
if RUBY_PLATFORM =~ /mswin/
|
25
|
+
Dir.chdir('ext') do
|
26
|
+
ruby 'extconf.rb'
|
27
|
+
sh 'nmake'
|
28
|
+
end
|
29
|
+
FileUtils::mkdir_p 'lib/win32'
|
30
|
+
mv 'ext/right_popen.so', 'lib/win32'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Build a binary gem"
|
35
|
+
task :gem => [:build] do
|
36
|
+
Dir["*.gem"].each { |gem| rm gem }
|
37
|
+
ruby 'right_popen.gemspec'
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'Install the right_popen library as a gem'
|
41
|
+
task :install_gem => [:gem] do
|
42
|
+
file = Dir["*.gem"].first
|
43
|
+
sh "gem install #{file}"
|
44
|
+
end
|
45
|
+
|
46
|
+
desc 'Uninstalls and reinstalls the right_popen library as a gem'
|
47
|
+
task :reinstall_gem do
|
48
|
+
sh "gem uninstall right_popen"
|
49
|
+
sh "rake install_gem"
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'Runs all spec tests'
|
53
|
+
task :spec do
|
54
|
+
sh "spec spec/*_spec.rb"
|
55
|
+
end
|
data/lib/linux/right_popen.rb
CHANGED
@@ -34,6 +34,7 @@ module RightScale
|
|
34
34
|
module StdOutHandler
|
35
35
|
|
36
36
|
# === Parameters
|
37
|
+
# options[:input](String):: Input to be sent to child process stdin
|
37
38
|
# options[:target](Object):: Object defining handler methods to be called.
|
38
39
|
# options[:stdout_handler(String):: Token for stdout handler method name.
|
39
40
|
# options[:exit_handler(String):: Token for exit handler method name.
|
@@ -42,6 +43,7 @@ module RightScale
|
|
42
43
|
# read_fd(IO):: Standard output read file descriptor.
|
43
44
|
# write_fd(IO):: Standard output write file descriptor.
|
44
45
|
def initialize(options, stderr_eventable, read_fd, write_fd)
|
46
|
+
@input = options[:input]
|
45
47
|
@target = options[:target]
|
46
48
|
@stdout_handler = options[:stdout_handler]
|
47
49
|
@exit_handler = options[:exit_handler]
|
@@ -52,6 +54,11 @@ module RightScale
|
|
52
54
|
@write_fd = write_fd
|
53
55
|
end
|
54
56
|
|
57
|
+
# Send input to child process stdin
|
58
|
+
def post_init
|
59
|
+
send_data(@input) if @input
|
60
|
+
end
|
61
|
+
|
55
62
|
# Callback from EM to receive data.
|
56
63
|
def receive_data(data)
|
57
64
|
@target.method(@stdout_handler).call(data) if @stdout_handler
|
data/lib/right_popen.rb
CHANGED
@@ -47,6 +47,7 @@ module RightScale
|
|
47
47
|
# === Parameters
|
48
48
|
# options[:command](String):: Command to execute, including any arguments
|
49
49
|
# options[:environment](Hash):: Hash of environment variables values keyed by name
|
50
|
+
# options[:input](String):: Input string that will get streamed into child's process stdin
|
50
51
|
# options[:target](Object):: object defining handler methods to be called, optional (no handlers can be defined if not specified)
|
51
52
|
# options[:stdout_handler](String):: Stdout handler method name, optional
|
52
53
|
# options[:stderr_handler](String):: Stderr handler method name, optional
|
@@ -62,4 +63,4 @@ module RightScale
|
|
62
63
|
true
|
63
64
|
end
|
64
65
|
|
65
|
-
end
|
66
|
+
end
|
data/right_popen.gemspec
CHANGED
@@ -6,7 +6,7 @@ end
|
|
6
6
|
|
7
7
|
spec = Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'right_popen'
|
9
|
-
spec.version = '1.0.
|
9
|
+
spec.version = '1.0.9'
|
10
10
|
spec.authors = ['Scott Messier', 'Raphael Simon']
|
11
11
|
spec.email = 'scott@rightscale.com'
|
12
12
|
spec.homepage = 'https://github.com/rightscale/right_popen'
|
data/spec/increment.rb
ADDED
data/spec/print_env.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
puts "__test__=#{ENV['__test__']}" if ENV['__test__']
|
2
|
-
puts "PATH=#{ENV['PATH']}"
|
1
|
+
puts "__test__=#{ENV['__test__']}" if ENV['__test__']
|
2
|
+
puts "PATH=#{ENV['PATH']}"
|
@@ -1,8 +1,8 @@
|
|
1
|
-
count = ARGV[0] ? ARGV[0].to_i : 1
|
2
|
-
|
3
|
-
count.times do |i|
|
4
|
-
$stderr.puts "stderr #{i}" if 0 == i % 10
|
5
|
-
$stdout.puts "stdout #{i}"
|
6
|
-
end
|
7
|
-
|
8
|
-
exit 99
|
1
|
+
count = ARGV[0] ? ARGV[0].to_i : 1
|
2
|
+
|
3
|
+
count.times do |i|
|
4
|
+
$stderr.puts "stderr #{i}" if 0 == i % 10
|
5
|
+
$stdout.puts "stdout #{i}"
|
6
|
+
end
|
7
|
+
|
8
|
+
exit 99
|
data/spec/produce_output.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
$stdout.puts ARGV[0]
|
2
|
-
$stderr.puts ARGV[1]
|
1
|
+
$stdout.puts ARGV[0]
|
2
|
+
$stderr.puts ARGV[1]
|
data/spec/produce_stderr_only.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
count = ARGV[0] ? ARGV[0].to_i : 1
|
2
|
-
|
3
|
-
count.times do |i|
|
4
|
-
$stderr.puts "stderr #{i}"
|
5
|
-
end
|
1
|
+
count = ARGV[0] ? ARGV[0].to_i : 1
|
2
|
+
|
3
|
+
count.times do |i|
|
4
|
+
$stderr.puts "stderr #{i}"
|
5
|
+
end
|
data/spec/produce_stdout_only.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
count = ARGV[0] ? ARGV[0].to_i : 1
|
2
|
-
|
3
|
-
count.times do |i|
|
4
|
-
$stdout.puts "stdout #{i}"
|
5
|
-
end
|
1
|
+
count = ARGV[0] ? ARGV[0].to_i : 1
|
2
|
+
|
3
|
+
count.times do |i|
|
4
|
+
$stdout.puts "stdout #{i}"
|
5
|
+
end
|
data/spec/right_popen_spec.rb
CHANGED
@@ -32,12 +32,13 @@ describe 'RightScale::popen3' do
|
|
32
32
|
|
33
33
|
attr_reader :output_text, :error_text, :status
|
34
34
|
|
35
|
-
def do_right_popen(command, env=nil)
|
36
|
-
@timeout = EM::Timer.new(
|
35
|
+
def do_right_popen(command, env=nil, input=nil)
|
36
|
+
@timeout = EM::Timer.new(2) { puts "\n** Failed to run #{command.inspect}: Timeout"; EM.stop }
|
37
37
|
@output_text = ''
|
38
38
|
@error_text = ''
|
39
39
|
@status = nil
|
40
40
|
RightScale.popen3(:command => command,
|
41
|
+
:input => input,
|
41
42
|
:target => self,
|
42
43
|
:environment => env,
|
43
44
|
:stdout_handler => :on_read_stdout,
|
@@ -45,16 +46,16 @@ describe 'RightScale::popen3' do
|
|
45
46
|
:exit_handler => :on_exit)
|
46
47
|
end
|
47
48
|
|
48
|
-
def run_right_popen(command, env=nil, count
|
49
|
+
def run_right_popen(command, env=nil, input=nil, count=1)
|
49
50
|
begin
|
50
51
|
@command = command
|
51
52
|
@env = env
|
52
53
|
@last_iteration = 0
|
53
54
|
@count = count
|
54
55
|
puts "#{count}>" if count > 1
|
55
|
-
EM.run { EM.next_tick { do_right_popen(command, env) } }
|
56
|
+
EM.run { EM.next_tick { do_right_popen(command, env, input) } }
|
56
57
|
rescue Exception => e
|
57
|
-
puts "** Failed: #{e.message} FROM\n#{e.backtrace.join("\n")}"
|
58
|
+
puts "\n** Failed: #{e.message} FROM\n#{e.backtrace.join("\n")}"
|
58
59
|
raise e
|
59
60
|
end
|
60
61
|
end
|
@@ -199,12 +200,22 @@ describe 'RightScale::popen3' do
|
|
199
200
|
end
|
200
201
|
|
201
202
|
it 'should run repeatedly without leaking resources' do
|
203
|
+
pending 'Set environment variable TEST_LEAK to enable' unless ENV['TEST_LEAK']
|
202
204
|
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'produce_output.rb'))}\" \"#{STANDARD_MESSAGE}\" \"#{ERROR_MESSAGE}\""
|
203
205
|
runner = RightPopenSpec::Runner.new
|
204
|
-
runner.run_right_popen(command, nil, REPEAT_TEST_COUNTER)
|
206
|
+
runner.run_right_popen(command, nil, nil, REPEAT_TEST_COUNTER)
|
205
207
|
runner.status.exitstatus.should == 0
|
206
208
|
runner.output_text.should == STANDARD_MESSAGE + "\n"
|
207
209
|
runner.error_text.should == ERROR_MESSAGE + "\n"
|
208
210
|
end
|
209
211
|
|
212
|
+
it 'should pass input to child process' do
|
213
|
+
command = "\"#{RUBY_CMD}\" \"#{File.expand_path(File.join(File.dirname(__FILE__), 'increment.rb'))}\""
|
214
|
+
runner = RightPopenSpec::Runner.new
|
215
|
+
runner.run_right_popen(command, nil, "42\n")
|
216
|
+
runner.status.exitstatus.should == 0
|
217
|
+
runner.output_text.should == "43\n"
|
218
|
+
runner.error_text.should be_empty
|
219
|
+
end
|
220
|
+
|
210
221
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_popen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Messier
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-06-
|
13
|
+
date: 2010-06-21 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/linux/right_popen.rb
|
44
44
|
- lib/right_popen.rb
|
45
45
|
- right_popen.gemspec
|
46
|
+
- spec/increment.rb
|
46
47
|
- spec/print_env.rb
|
47
48
|
- spec/produce_mixed_output.rb
|
48
49
|
- spec/produce_output.rb
|