childprocess 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -8,7 +8,15 @@ a standalone library.
8
8
 
9
9
  == Usage
10
10
 
11
- process = ChildProcess.build("ruby", "-e", "sleep").start
11
+ process = ChildProcess.build("ruby", "-e", "sleep")
12
+
13
+ # inherit stdout/stderr from parent
14
+ process.io.inherit!
15
+
16
+ # or pass an IO
17
+ process.io.stdout = Tempfile.new("child-output")
18
+
19
+ process.start
12
20
 
13
21
  process.started? #=> true
14
22
  process.alive? #=> true
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gem.email = "jari.bakken@gmail.com"
12
12
  gem.homepage = "http://github.com/jarib/childprocess"
13
13
  gem.authors = ["Jari Bakken"]
14
- gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "rspec", ">= 2.0.0"
15
15
  gem.add_development_dependency "yard", ">= 0"
16
16
 
17
17
  gem.add_dependency "ffi", "~> 0.6.3"
@@ -22,21 +22,22 @@ rescue LoadError
22
22
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
23
  end
24
24
 
25
- require 'spec/rake/spectask'
26
- Spec::Rake::SpecTask.new(:spec) do |spec|
27
- spec.libs << 'lib' << 'spec'
28
- spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ require 'rspec/core/rake_task'
26
+ RSpec::Core::RakeTask.new(:spec) do |spec|
27
+ spec.ruby_opts = "-I lib:spec"
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov_opts = %w[--exclude spec,ruby-debug,/Library/Ruby,.gem --include lib/childprocess]
29
30
  end
30
31
 
31
- Spec::Rake::SpecTask.new(:rcov) do |spec|
32
- spec.libs << 'lib' << 'spec'
33
- spec.pattern = 'spec/**/*_spec.rb'
34
- spec.rcov = true
32
+ desc 'Run specs for rcov'
33
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
34
+ spec.ruby_opts = "-I lib:spec"
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
35
37
  spec.rcov_opts = %w[--exclude spec,ruby-debug,/Library/Ruby,.gem --include lib/childprocess]
36
38
  end
37
39
 
38
40
  task :spec => :check_dependencies
39
-
40
41
  task :default => :spec
41
42
 
42
43
  begin
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
data/childprocess.gemspec CHANGED
@@ -1,70 +1,68 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{childprocess}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jari Bakken"]
12
- s.date = %q{2010-11-08}
12
+ s.date = %q{2010-12-10}
13
13
  s.description = %q{This gem aims at being a simple and reliable solution for controlling external programs running in the background on any Ruby / OS combination.}
14
14
  s.email = %q{jari.bakken@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "childprocess.gemspec",
27
- "lib/childprocess.rb",
28
- "lib/childprocess/abstract_io.rb",
29
- "lib/childprocess/abstract_process.rb",
30
- "lib/childprocess/errors.rb",
31
- "lib/childprocess/ironruby.rb",
32
- "lib/childprocess/ironruby/process.rb",
33
- "lib/childprocess/jruby.rb",
34
- "lib/childprocess/jruby/io.rb",
35
- "lib/childprocess/jruby/process.rb",
36
- "lib/childprocess/jruby/redirector.rb",
37
- "lib/childprocess/unix.rb",
38
- "lib/childprocess/unix/io.rb",
39
- "lib/childprocess/unix/process.rb",
40
- "lib/childprocess/windows.rb",
41
- "lib/childprocess/windows/api.rb",
42
- "lib/childprocess/windows/constants.rb",
43
- "lib/childprocess/windows/functions.rb",
44
- "lib/childprocess/windows/handle.rb",
45
- "lib/childprocess/windows/io.rb",
46
- "lib/childprocess/windows/process.rb",
47
- "lib/childprocess/windows/structs.rb",
48
- "spec/abstract_io_spec.rb",
49
- "spec/childprocess_spec.rb",
50
- "spec/jruby_spec.rb",
51
- "spec/spec.opts",
52
- "spec/spec_helper.rb",
53
- "spec/unix_spec.rb",
54
- "spec/windows_spec.rb"
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "childprocess.gemspec",
26
+ "lib/childprocess.rb",
27
+ "lib/childprocess/abstract_io.rb",
28
+ "lib/childprocess/abstract_process.rb",
29
+ "lib/childprocess/errors.rb",
30
+ "lib/childprocess/ironruby.rb",
31
+ "lib/childprocess/ironruby/process.rb",
32
+ "lib/childprocess/jruby.rb",
33
+ "lib/childprocess/jruby/io.rb",
34
+ "lib/childprocess/jruby/process.rb",
35
+ "lib/childprocess/jruby/redirector.rb",
36
+ "lib/childprocess/unix.rb",
37
+ "lib/childprocess/unix/io.rb",
38
+ "lib/childprocess/unix/process.rb",
39
+ "lib/childprocess/windows.rb",
40
+ "lib/childprocess/windows/api.rb",
41
+ "lib/childprocess/windows/constants.rb",
42
+ "lib/childprocess/windows/functions.rb",
43
+ "lib/childprocess/windows/handle.rb",
44
+ "lib/childprocess/windows/io.rb",
45
+ "lib/childprocess/windows/process.rb",
46
+ "lib/childprocess/windows/structs.rb",
47
+ "spec/abstract_io_spec.rb",
48
+ "spec/childprocess_spec.rb",
49
+ "spec/jruby_spec.rb",
50
+ "spec/spec.opts",
51
+ "spec/spec_helper.rb",
52
+ "spec/unix_spec.rb",
53
+ "spec/windows_spec.rb"
55
54
  ]
56
55
  s.homepage = %q{http://github.com/jarib/childprocess}
57
- s.rdoc_options = ["--charset=UTF-8"]
58
56
  s.require_paths = ["lib"]
59
57
  s.rubygems_version = %q{1.3.7}
60
58
  s.summary = %q{Cross-platform ruby library for managing child processes.}
61
59
  s.test_files = [
62
60
  "spec/abstract_io_spec.rb",
63
- "spec/childprocess_spec.rb",
64
- "spec/jruby_spec.rb",
65
- "spec/spec_helper.rb",
66
- "spec/unix_spec.rb",
67
- "spec/windows_spec.rb"
61
+ "spec/childprocess_spec.rb",
62
+ "spec/jruby_spec.rb",
63
+ "spec/spec_helper.rb",
64
+ "spec/unix_spec.rb",
65
+ "spec/windows_spec.rb"
68
66
  ]
69
67
 
70
68
  if s.respond_to? :specification_version then
@@ -72,16 +70,16 @@ Gem::Specification.new do |s|
72
70
  s.specification_version = 3
73
71
 
74
72
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
75
- s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
73
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
76
74
  s.add_development_dependency(%q<yard>, [">= 0"])
77
75
  s.add_runtime_dependency(%q<ffi>, ["~> 0.6.3"])
78
76
  else
79
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
77
+ s.add_dependency(%q<rspec>, [">= 2.0.0"])
80
78
  s.add_dependency(%q<yard>, [">= 0"])
81
79
  s.add_dependency(%q<ffi>, ["~> 0.6.3"])
82
80
  end
83
81
  else
84
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
82
+ s.add_dependency(%q<rspec>, [">= 2.0.0"])
85
83
  s.add_dependency(%q<yard>, [">= 0"])
86
84
  s.add_dependency(%q<ffi>, ["~> 0.6.3"])
87
85
  end
data/lib/childprocess.rb CHANGED
@@ -19,8 +19,10 @@ module ChildProcess
19
19
  IronRuby::Process.new(args)
20
20
  when :windows
21
21
  Windows::Process.new(args)
22
- else
22
+ when :macosx, :linux, :unix, :cygwin
23
23
  Unix::Process.new(args)
24
+ else
25
+ raise Error, "unsupported platform #{platform.inspect}"
24
26
  end
25
27
  end
26
28
  alias_method :build, :new
@@ -32,6 +34,8 @@ module ChildProcess
32
34
  :ironruby
33
35
  elsif RUBY_PLATFORM =~ /mswin|msys|mingw32/
34
36
  :windows
37
+ elsif RUBY_PLATFORM =~ /cygwin/
38
+ :cygwin
35
39
  else
36
40
  os
37
41
  end
@@ -55,7 +59,7 @@ module ChildProcess
55
59
  host_os = RbConfig::CONFIG['host_os']
56
60
 
57
61
  case host_os
58
- when /mswin|msys|mingw32/
62
+ when /mswin|msys|mingw32|cygwin/
59
63
  :windows
60
64
  when /darwin|mac os/
61
65
  :macosx
@@ -68,21 +72,23 @@ module ChildProcess
68
72
  end
69
73
  )
70
74
  end
71
-
75
+
76
+ #
77
+ # By default, a child process will inherit open file descriptors from the parent process.
78
+ # This helper provides a cross-platform way of making sure that doesn't happen for the given file/io.
72
79
  #
73
- # By default, a child process will inherit open files and sockets from the parent process.
74
- # This helper provides a cross-platform way of making sure that doesn't happen for the given file.
75
- #
76
80
 
77
81
  def close_on_exec(file)
78
- if windows?
79
- Windows.dont_inherit file
82
+ if file.respond_to?(:close_on_exec=)
83
+ file.close_on_exec = true
80
84
  elsif file.respond_to?(:fcntl) && defined?(Fcntl::FD_CLOEXEC)
81
85
  file.fcntl Fcntl::F_SETFD, Fcntl::FD_CLOEXEC
86
+ elsif windows?
87
+ Windows.dont_inherit file
82
88
  else
83
- raise Error, "not sure how to set close-on-exec for #{file.inspect} on #{platform}"
89
+ raise Error, "not sure how to set close-on-exec for #{file.inspect} on #{platform.inspect}"
84
90
  end
85
91
  end
86
92
 
87
93
  end # class << self
88
- end # ChildProcess
94
+ end # ChildProcess
@@ -104,8 +104,9 @@ describe ChildProcess do
104
104
  process.io.inherit!
105
105
 
106
106
  process.start
107
- server.close
107
+ sleep 0.5 # give the forked process a chance to exec() (which closes the fd)
108
108
 
109
+ server.close
109
110
  lambda { TCPServer.new("localhost", 4433).close }.should_not raise_error
110
111
  end
111
112
 
data/spec/spec_helper.rb CHANGED
@@ -2,10 +2,10 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
 
4
4
  require 'childprocess'
5
- require 'spec'
6
- require 'spec/autorun'
5
+ require 'rspec'
7
6
  require 'tempfile'
8
- require "socket"
7
+ require 'socket'
8
+ require 'stringio'
9
9
 
10
10
  module ChildProcessSpecHelper
11
11
  RUBY = defined?(Gem) ? Gem.ruby : 'ruby'
@@ -74,7 +74,7 @@ module ChildProcessSpecHelper
74
74
  until ok || Time.now >= end_time
75
75
  begin
76
76
  ok = yield
77
- rescue Spec::Expectations::ExpectationNotMetError => last_error
77
+ rescue RSpec::Expectations::ExpectationNotMetError => last_error
78
78
  end
79
79
  end
80
80
 
@@ -89,7 +89,7 @@ end # ChildProcessSpecHelper
89
89
 
90
90
  Thread.abort_on_exception = true
91
91
 
92
- Spec::Runner.configure do |config|
92
+ RSpec.configure do |config|
93
93
  config.include(ChildProcessSpecHelper)
94
94
  config.after(:each) {
95
95
  @process && @process.alive? && @process.stop
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jari Bakken
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-08 00:00:00 +01:00
17
+ date: 2010-12-10 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -26,10 +26,10 @@ dependencies:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
- - 1
30
29
  - 2
31
- - 9
32
- version: 1.2.9
30
+ - 0
31
+ - 0
32
+ version: 2.0.0
33
33
  type: :development
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
@@ -71,7 +71,6 @@ extra_rdoc_files:
71
71
  - README.rdoc
72
72
  files:
73
73
  - .document
74
- - .gitignore
75
74
  - LICENSE
76
75
  - README.rdoc
77
76
  - Rakefile
@@ -110,8 +109,8 @@ homepage: http://github.com/jarib/childprocess
110
109
  licenses: []
111
110
 
112
111
  post_install_message:
113
- rdoc_options:
114
- - --charset=UTF-8
112
+ rdoc_options: []
113
+
115
114
  require_paths:
116
115
  - lib
117
116
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC