childprocess 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/childprocess.gemspec +76 -0
- data/lib/childprocess/abstract_process.rb +1 -1
- data/lib/childprocess/unix/process.rb +0 -1
- data/spec/childprocess_spec.rb +33 -8
- data/spec/spec_helper.rb +44 -2
- metadata +17 -33
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{childprocess}
|
8
|
+
s.version = "0.0.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jari Bakken"]
|
12
|
+
s.date = %q{2010-10-08}
|
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
|
+
s.email = %q{jari.bakken@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"childprocess.gemspec",
|
27
|
+
"lib/childprocess.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/process.rb",
|
34
|
+
"lib/childprocess/unix.rb",
|
35
|
+
"lib/childprocess/unix/process.rb",
|
36
|
+
"lib/childprocess/windows.rb",
|
37
|
+
"lib/childprocess/windows/api.rb",
|
38
|
+
"lib/childprocess/windows/constants.rb",
|
39
|
+
"lib/childprocess/windows/functions.rb",
|
40
|
+
"lib/childprocess/windows/handle.rb",
|
41
|
+
"lib/childprocess/windows/process.rb",
|
42
|
+
"lib/childprocess/windows/structs.rb",
|
43
|
+
"spec/childprocess_spec.rb",
|
44
|
+
"spec/spec.opts",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
47
|
+
s.homepage = %q{http://github.com/jarib/childprocess}
|
48
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
49
|
+
s.require_paths = ["lib"]
|
50
|
+
s.rubygems_version = %q{1.3.5}
|
51
|
+
s.summary = %q{Cross-platform ruby library for managing child processes.}
|
52
|
+
s.test_files = [
|
53
|
+
"spec/childprocess_spec.rb",
|
54
|
+
"spec/spec_helper.rb"
|
55
|
+
]
|
56
|
+
|
57
|
+
if s.respond_to? :specification_version then
|
58
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
59
|
+
s.specification_version = 3
|
60
|
+
|
61
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
62
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
63
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
64
|
+
s.add_runtime_dependency(%q<ffi>, ["~> 0.6.3"])
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
67
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
68
|
+
s.add_dependency(%q<ffi>, ["~> 0.6.3"])
|
69
|
+
end
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
72
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
73
|
+
s.add_dependency(%q<ffi>, ["~> 0.6.3"])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
data/spec/childprocess_spec.rb
CHANGED
@@ -2,34 +2,59 @@ require File.expand_path('../spec_helper', __FILE__)
|
|
2
2
|
|
3
3
|
describe ChildProcess do
|
4
4
|
|
5
|
-
EXIT_TIMEOUT =
|
5
|
+
EXIT_TIMEOUT = 10
|
6
6
|
|
7
7
|
it "returns self when started" do
|
8
8
|
process = sleeping_ruby
|
9
|
+
|
9
10
|
process.start.should == process
|
10
11
|
process.should be_started
|
11
12
|
end
|
12
13
|
|
13
|
-
it "
|
14
|
+
it "knows if the process crashed" do
|
14
15
|
process = exit_with(1).start
|
15
|
-
process.poll_for_exit(EXIT_TIMEOUT)
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
within(EXIT_TIMEOUT) {
|
18
|
+
process.should be_crashed
|
19
|
+
}
|
19
20
|
end
|
20
21
|
|
21
|
-
it "
|
22
|
+
it "knows if the process didn't crash" do
|
22
23
|
process = exit_with(0).start
|
23
24
|
process.poll_for_exit(EXIT_TIMEOUT)
|
24
25
|
|
25
|
-
process.should be_exited
|
26
26
|
process.should_not be_crashed
|
27
27
|
end
|
28
28
|
|
29
|
-
it "
|
29
|
+
it "escalates if TERM is ignored" do
|
30
30
|
process = ignored('TERM').start
|
31
31
|
process.stop
|
32
32
|
process.should be_exited
|
33
33
|
end
|
34
34
|
|
35
|
+
it "lets child process inherit the environment of the current process" do
|
36
|
+
Tempfile.open("env-spec") do |file|
|
37
|
+
with_env('env-spec' => 'yes') do
|
38
|
+
process = write_env(file.path).start
|
39
|
+
process.poll_for_exit(EXIT_TIMEOUT)
|
40
|
+
end
|
41
|
+
|
42
|
+
file.rewind
|
43
|
+
child_env = eval(file.read)
|
44
|
+
child_env['env-spec'].should == 'yes'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "passes arguments to the child" do
|
49
|
+
args = ["foo", "bar"]
|
50
|
+
|
51
|
+
Tempfile.open("argv-spec") do |file|
|
52
|
+
process = write_argv(file.path, *args).start
|
53
|
+
process.poll_for_exit(EXIT_TIMEOUT)
|
54
|
+
|
55
|
+
file.rewind
|
56
|
+
file.read.should == args.inspect
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
35
60
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,9 +6,10 @@ require 'spec/autorun'
|
|
6
6
|
require 'tempfile'
|
7
7
|
|
8
8
|
module ChildProcessSpecHelper
|
9
|
+
RUBY = defined?(Gem) ? Gem.ruby : 'ruby'
|
9
10
|
|
10
11
|
def ruby_process(*args)
|
11
|
-
@process = ChildProcess.build(
|
12
|
+
@process = ChildProcess.build(RUBY , *args)
|
12
13
|
end
|
13
14
|
|
14
15
|
def sleeping_ruby
|
@@ -24,10 +25,35 @@ module ChildProcessSpecHelper
|
|
24
25
|
ruby_process tmp_script(code)
|
25
26
|
end
|
26
27
|
|
28
|
+
def write_env(path)
|
29
|
+
code = <<-RUBY
|
30
|
+
File.open(#{path.inspect}, "w") { |f| f << ENV.inspect }
|
31
|
+
RUBY
|
32
|
+
|
33
|
+
ruby_process tmp_script(code)
|
34
|
+
end
|
35
|
+
|
36
|
+
def write_argv(path, *args)
|
37
|
+
code = <<-RUBY
|
38
|
+
File.open(#{path.inspect}, "w") { |f| f << ARGV.inspect }
|
39
|
+
RUBY
|
40
|
+
|
41
|
+
ruby_process(tmp_script(code), *args)
|
42
|
+
end
|
43
|
+
|
27
44
|
def exit_with(exit_code)
|
28
45
|
ruby_process(tmp_script("exit(#{exit_code})"))
|
29
46
|
end
|
30
47
|
|
48
|
+
def with_env(hash)
|
49
|
+
hash.each { |k,v| ENV[k] = v }
|
50
|
+
begin
|
51
|
+
yield
|
52
|
+
ensure
|
53
|
+
hash.each_key { |k| ENV[k] = nil }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
31
57
|
def tmp_script(code)
|
32
58
|
tf = Tempfile.new("childprocess-temp")
|
33
59
|
tf << code
|
@@ -37,7 +63,23 @@ module ChildProcessSpecHelper
|
|
37
63
|
|
38
64
|
tf.path
|
39
65
|
end
|
40
|
-
|
66
|
+
|
67
|
+
def within(seconds, &blk)
|
68
|
+
end_time = Time.now + seconds
|
69
|
+
ok = false
|
70
|
+
last_error = nil
|
71
|
+
|
72
|
+
until ok || Time.now >= end_time
|
73
|
+
begin
|
74
|
+
ok = yield
|
75
|
+
rescue Spec::Expectations::ExpectationNotMetError => last_error
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
raise last_error unless ok
|
80
|
+
end
|
81
|
+
|
82
|
+
end # ChildProcessSpecHelper
|
41
83
|
|
42
84
|
|
43
85
|
Spec::Runner.configure do |config|
|
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: childprocess
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
version: 0.0.2
|
4
|
+
version: 0.0.3
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- Jari Bakken
|
@@ -19,44 +14,34 @@ default_executable:
|
|
19
14
|
dependencies:
|
20
15
|
- !ruby/object:Gem::Dependency
|
21
16
|
name: rspec
|
22
|
-
|
23
|
-
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
20
|
requirements:
|
25
21
|
- - ">="
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 1
|
29
|
-
- 2
|
30
|
-
- 9
|
31
23
|
version: 1.2.9
|
32
|
-
|
33
|
-
version_requirements: *id001
|
24
|
+
version:
|
34
25
|
- !ruby/object:Gem::Dependency
|
35
26
|
name: yard
|
36
|
-
|
37
|
-
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
30
|
requirements:
|
39
31
|
- - ">="
|
40
32
|
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
33
|
version: "0"
|
44
|
-
|
45
|
-
version_requirements: *id002
|
34
|
+
version:
|
46
35
|
- !ruby/object:Gem::Dependency
|
47
36
|
name: ffi
|
48
|
-
|
49
|
-
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
40
|
requirements:
|
51
41
|
- - ~>
|
52
42
|
- !ruby/object:Gem::Version
|
53
|
-
segments:
|
54
|
-
- 0
|
55
|
-
- 6
|
56
|
-
- 3
|
57
43
|
version: 0.6.3
|
58
|
-
|
59
|
-
version_requirements: *id003
|
44
|
+
version:
|
60
45
|
description: This gem aims at being a simple and reliable solution for controlling external programs running in the background on any Ruby / OS combination.
|
61
46
|
email: jari.bakken@gmail.com
|
62
47
|
executables: []
|
@@ -73,6 +58,7 @@ files:
|
|
73
58
|
- README.rdoc
|
74
59
|
- Rakefile
|
75
60
|
- VERSION
|
61
|
+
- childprocess.gemspec
|
76
62
|
- lib/childprocess.rb
|
77
63
|
- lib/childprocess/abstract_process.rb
|
78
64
|
- lib/childprocess/errors.rb
|
@@ -105,20 +91,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
91
|
requirements:
|
106
92
|
- - ">="
|
107
93
|
- !ruby/object:Gem::Version
|
108
|
-
segments:
|
109
|
-
- 0
|
110
94
|
version: "0"
|
95
|
+
version:
|
111
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
97
|
requirements:
|
113
98
|
- - ">="
|
114
99
|
- !ruby/object:Gem::Version
|
115
|
-
segments:
|
116
|
-
- 0
|
117
100
|
version: "0"
|
101
|
+
version:
|
118
102
|
requirements: []
|
119
103
|
|
120
104
|
rubyforge_project:
|
121
|
-
rubygems_version: 1.3.
|
105
|
+
rubygems_version: 1.3.5
|
122
106
|
signing_key:
|
123
107
|
specification_version: 3
|
124
108
|
summary: Cross-platform ruby library for managing child processes.
|