childprocess 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c4f97dba977d63da875a3d6db8f5587f7b22461
4
- data.tar.gz: ee29a0a23a7b3e157ccb40b7ec1a5b052cfe8260
3
+ metadata.gz: 77e7009c5202bfecb17e331b56d15c79b92d33b0
4
+ data.tar.gz: 343d119d1130d05fe395d5ee2631aeb1a50866a0
5
5
  SHA512:
6
- metadata.gz: f8c08e7184c5395508087fabf42f0dd8b96b289e563c70123a59704017fcf57f7bffdfbe02a55d188a7688a0bb6e2710143f79532df4e3d8dc9bab3666d1bd19
7
- data.tar.gz: b29cfe1b27fd74a17ffc04a1d3c3e43b80265dd94a1dd0750940cc970475164d0f52318e663c7b8240d65ab6cc66272ba5f0f2b98f514bd99fb79aadd4ce54d6
6
+ metadata.gz: f84deda774210ec0d133c08095389c212770ed6afa58b37bddef82a7ca0513e76fcdcd3aaeb0ea4ca0e878329c160a7d9ba4770f19faceb472d9dbe9333cc45a
7
+ data.tar.gz: 7ded6c7fa7364c4c5fe423c7a06e671dce947e6290e62fb3d4be7d62554be1339e0e706159ee9fc4350c0a3a1fc4f5f608122c2c281780485793523d42dcfb5f
@@ -6,8 +6,8 @@ rvm:
6
6
  - 2.1.0
7
7
  - ruby-head
8
8
  env:
9
- - CHILDPROCESS_POSIX_SPAWN=true
10
- - CHILDPROCESS_POSIX_SPAWN=false
9
+ - CHILDPROCESS_POSIX_SPAWN=true CHILDPROCESS_UNSET=should-be-unset
10
+ - CHILDPROCESS_POSIX_SPAWN=false CHILDPROCESS_UNSET=should-be-unset
11
11
  matrix:
12
12
  allow_failures:
13
13
  - rvm: rbx
data/README.md CHANGED
@@ -142,6 +142,17 @@ process.detach = true
142
142
  process.start
143
143
  ```
144
144
 
145
+ #### Invoking a shell
146
+
147
+ As opposed to `Kernel#system`, `Kernel#exec` et al., ChildProcess will not automatically execute your command in a shell (like `/bin/sh` or `cmd.exe`) depending on the arguments.
148
+ This means that if you try to execute e.g. gem executables (like `bundle` or `gem`) or Windows executables (with `.com` or `.bat` extensions) you may see a `ChildProcess::LaunchError`.
149
+ You can work around this by being explicit about what interpreter to invoke:
150
+
151
+ ```ruby
152
+ ChildProcess.build("cmd.exe", "/c", "bundle")
153
+ ChildProcess.build("ruby", "-S", "bundle")
154
+ ```
155
+
145
156
  # Implementation
146
157
 
147
158
  How the process is launched and killed depends on the platform:
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.test_files = `git ls-files -- spec/*`.split("\n")
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_development_dependency "rspec", ">= 2.0.0"
22
+ s.add_development_dependency "rspec", "~> 3.0.0"
23
23
  s.add_development_dependency "yard", ">= 0"
24
24
  s.add_development_dependency "rake", "~> 0.9.2"
25
25
  s.add_development_dependency 'coveralls'
@@ -21,7 +21,8 @@ module ChildProcess
21
21
  stop_pumps
22
22
 
23
23
  true
24
- rescue java.lang.IllegalThreadStateException
24
+ rescue java.lang.IllegalThreadStateException => ex
25
+ log(ex.class => ex.message)
25
26
  false
26
27
  ensure
27
28
  log(:exit_code => @exit_code)
@@ -113,7 +114,11 @@ module ChildProcess
113
114
 
114
115
  def set_env(env)
115
116
  ENV.to_hash.merge(@environment).each do |k,v|
116
- env.put(k.to_s, v.to_s) if v
117
+ if v
118
+ env.put(k.to_s, v.to_s)
119
+ else
120
+ env.remove(k.to_s) if env.key?(k.to_s)
121
+ end
117
122
  end
118
123
  end
119
124
 
@@ -1,3 +1,3 @@
1
1
  module ChildProcess
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
@@ -6,7 +6,7 @@ describe ChildProcess::AbstractIO do
6
6
  it "inherits the parent's IO streams" do
7
7
  io.inherit!
8
8
 
9
- io.stdout.should eq STDOUT
10
- io.stderr.should eq STDERR
9
+ expect(io.stdout).to eq STDOUT
10
+ expect(io.stderr).to eq STDERR
11
11
  end
12
12
  end
@@ -6,8 +6,8 @@ describe ChildProcess do
6
6
  it "returns self when started" do
7
7
  process = sleeping_ruby
8
8
 
9
- process.start.should eq process
10
- process.should be_started
9
+ expect(process.start).to eq process
10
+ expect(process).to be_alive
11
11
  end
12
12
 
13
13
  # We can't detect failure to execve() when using posix_spawn() on Linux
@@ -30,35 +30,35 @@ describe ChildProcess do
30
30
  process = exit_with(1).start
31
31
  process.wait
32
32
 
33
- process.should be_crashed
33
+ expect(process).to be_crashed
34
34
  end
35
35
 
36
36
  it "knows if the process didn't crash" do
37
37
  process = exit_with(0).start
38
38
  process.wait
39
39
 
40
- process.should_not be_crashed
40
+ expect(process).to_not be_crashed
41
41
  end
42
42
 
43
43
  it "can wait for a process to finish" do
44
44
  process = exit_with(0).start
45
45
  return_value = process.wait
46
46
 
47
- process.should_not be_alive
48
- return_value.should == 0
47
+ expect(process).to_not be_alive
48
+ expect(return_value).to eq 0
49
49
  end
50
50
 
51
51
  it 'ignores #wait if process already finished' do
52
52
  process = exit_with(0).start
53
53
  sleep 0.01 until process.exited?
54
54
 
55
- process.wait.should == 0
55
+ expect(process.wait).to eql 0
56
56
  end
57
57
 
58
58
  it "escalates if TERM is ignored" do
59
59
  process = ignored('TERM').start
60
60
  process.stop
61
- process.should be_exited
61
+ expect(process).to be_exited
62
62
  end
63
63
 
64
64
  it "accepts a timeout argument to #stop" do
@@ -74,7 +74,7 @@ describe ChildProcess do
74
74
  end
75
75
 
76
76
  child_env = eval rewind_and_read(file)
77
- child_env['INHERITED'].should == 'yes'
77
+ expect(child_env['INHERITED']).to eql 'yes'
78
78
  end
79
79
  end
80
80
 
@@ -84,12 +84,12 @@ describe ChildProcess do
84
84
  process.environment['CHILD_ONLY'] = '1'
85
85
  process.start
86
86
 
87
- ENV['CHILD_ONLY'].should be_nil
87
+ expect(ENV['CHILD_ONLY']).to be_nil
88
88
 
89
89
  process.wait
90
90
 
91
91
  child_env = eval rewind_and_read(file)
92
- child_env['CHILD_ONLY'].should == '1'
92
+ expect(child_env['CHILD_ONLY']).to eql '1'
93
93
  end
94
94
  end
95
95
 
@@ -104,8 +104,8 @@ describe ChildProcess do
104
104
 
105
105
  child_env = eval rewind_and_read(file)
106
106
 
107
- child_env['INHERITED'].should eq 'yes'
108
- child_env['CHILD_ONLY'].should eq 'yes'
107
+ expect(child_env['INHERITED']).to eq 'yes'
108
+ expect(child_env['CHILD_ONLY']).to eq 'yes'
109
109
  end
110
110
  end
111
111
  end
@@ -120,7 +120,7 @@ describe ChildProcess do
120
120
  process.wait
121
121
 
122
122
  child_env = eval rewind_and_read(file)
123
- child_env.should_not have_key('CHILDPROCESS_UNSET')
123
+ expect(child_env).to_not have_key('CHILDPROCESS_UNSET')
124
124
  end
125
125
  end
126
126
 
@@ -132,12 +132,13 @@ describe ChildProcess do
132
132
  process = write_argv(file.path, *args).start
133
133
  process.wait
134
134
 
135
- rewind_and_read(file).should == args.inspect
135
+ expect(rewind_and_read(file)).to eql args.inspect
136
136
  end
137
137
  end
138
138
 
139
139
  it "lets a detached child live on" do
140
140
  pending "how do we spec this?"
141
+ fail
141
142
  end
142
143
 
143
144
  it "preserves Dir.pwd in the child" do
@@ -153,7 +154,7 @@ describe ChildProcess do
153
154
 
154
155
  process.wait
155
156
 
156
- rewind_and_read(file).should == expected_dir
157
+ expect(rewind_and_read(file)).to eq expected_dir
157
158
  end
158
159
  end
159
160
 
@@ -164,7 +165,7 @@ describe ChildProcess do
164
165
  process = write_argv(file.path, *args).start
165
166
  process.wait
166
167
 
167
- rewind_and_read(file).should == args.inspect
168
+ expect(rewind_and_read(file)).to eq args.inspect
168
169
  end
169
170
  end
170
171
 
@@ -172,14 +173,14 @@ describe ChildProcess do
172
173
  path = File.expand_path('foo bar')
173
174
 
174
175
  with_executable_at(path) do |proc|
175
- proc.start.should eq proc
176
- proc.should be_started
176
+ expect(proc.start).to eq proc
177
+ expect(proc).to be_alive
177
178
  end
178
179
  end
179
180
 
180
181
  it "times out when polling for exit" do
181
182
  process = sleeping_ruby.start
182
- lambda { process.poll_for_exit(0.1) }.should raise_error(ChildProcess::TimeoutError)
183
+ expect { process.poll_for_exit(0.1) }.to raise_error(ChildProcess::TimeoutError)
183
184
  end
184
185
 
185
186
  it "can change working directory" do
@@ -196,10 +197,10 @@ describe ChildProcess do
196
197
  process.start
197
198
  process.wait
198
199
 
199
- rewind_and_read(file).should == dir
200
+ expect(rewind_and_read(file)).to eq dir
200
201
  end
201
202
 
202
- Dir.pwd.should == orig_pwd
203
+ expect(Dir.pwd).to eq orig_pwd
203
204
  }
204
205
  end
205
206
 
@@ -214,7 +215,7 @@ describe ChildProcess do
214
215
  end
215
216
 
216
217
  process.stop
217
- wait_until(3) { alive?(pid).should be_false }
218
+ wait_until(3) { expect(alive?(pid)).to eql(false) }
218
219
  end
219
220
  end
220
221
 
@@ -223,7 +224,7 @@ describe ChildProcess do
223
224
  threads = []
224
225
 
225
226
  threads << Thread.new { sleeping_ruby(1).start.wait }
226
- threads << Thread.new(time) { (Time.now - time).should < 0.5 }
227
+ threads << Thread.new(time) { expect(Time.now - time).to be < 0.5 }
227
228
 
228
229
  threads.each { |t| t.join }
229
230
  end
@@ -17,11 +17,11 @@ describe ChildProcess do
17
17
  process.io.stderr = err
18
18
 
19
19
  process.start
20
- process.io.stdin.should be_nil
20
+ expect(process.io.stdin).to be_nil
21
21
  process.wait
22
22
 
23
- rewind_and_read(out).should eq "0\n"
24
- rewind_and_read(err).should eq "1\n"
23
+ expect(rewind_and_read(out)).to eq "0\n"
24
+ expect(rewind_and_read(err)).to eq "1\n"
25
25
  ensure
26
26
  out.close
27
27
  err.close
@@ -44,7 +44,7 @@ describe ChildProcess do
44
44
  process.start
45
45
  process.wait
46
46
 
47
- rewind_and_read(out).should == "0\n"
47
+ expect(rewind_and_read(out)).to eq "0\n"
48
48
  ensure
49
49
  out.close
50
50
  end
@@ -61,7 +61,7 @@ describe ChildProcess do
61
61
  process.start
62
62
  process.wait
63
63
 
64
- rewind_and_read(out).should == "hello\n"
64
+ expect(rewind_and_read(out)).to eq "hello\n"
65
65
  ensure
66
66
  out.close
67
67
  end
@@ -84,7 +84,7 @@ describe ChildProcess do
84
84
 
85
85
  process.poll_for_exit(exit_timeout)
86
86
 
87
- rewind_and_read(out).should == "hello world\n"
87
+ expect(rewind_and_read(out)).to eq "hello world\n"
88
88
  ensure
89
89
  out.close
90
90
  end
@@ -108,23 +108,23 @@ describe ChildProcess do
108
108
 
109
109
  stdin.puts "hello"
110
110
  stdin.flush
111
- wait_until { rewind_and_read(out_receiver).should =~ /\Ahello\r?\n\z/m }
111
+ wait_until { expect(rewind_and_read(out_receiver)).to match(/\Ahello\r?\n\z/m) }
112
112
 
113
113
  stdin.putc "n"
114
114
  stdin.flush
115
- wait_until { rewind_and_read(out_receiver).should =~ /\Ahello\r?\nn\z/m }
115
+ wait_until { expect(rewind_and_read(out_receiver)).to match(/\Ahello\r?\nn\z/m) }
116
116
 
117
117
  stdin.print "e"
118
118
  stdin.flush
119
- wait_until { rewind_and_read(out_receiver).should =~ /\Ahello\r?\nne\z/m }
119
+ wait_until { expect(rewind_and_read(out_receiver)).to match(/\Ahello\r?\nne\z/m) }
120
120
 
121
121
  stdin.printf "w"
122
122
  stdin.flush
123
- wait_until { rewind_and_read(out_receiver).should =~ /\Ahello\r?\nnew\z/m }
123
+ wait_until { expect(rewind_and_read(out_receiver)).to match(/\Ahello\r?\nnew\z/m) }
124
124
 
125
125
  stdin.write "\nworld\n"
126
126
  stdin.flush
127
- wait_until { rewind_and_read(out_receiver).should =~ /\Ahello\r?\nnew\r?\nworld\r?\n\z/m }
127
+ wait_until { expect(rewind_and_read(out_receiver)).to match(/\Ahello\r?\nnew\r?\nworld\r?\n\z/m) }
128
128
 
129
129
  stdin.close
130
130
  process.poll_for_exit(exit_timeout)
@@ -168,7 +168,7 @@ describe ChildProcess do
168
168
  out = stdout.read
169
169
  err = stderr.read
170
170
 
171
- [out, err].should == %w[stdout stderr]
171
+ expect([out, err]).to eq %w[stdout stderr]
172
172
  end
173
173
 
174
174
  it "can set close-on-exec when IO is inherited" do
@@ -199,7 +199,7 @@ describe ChildProcess do
199
199
  process.start
200
200
  process.wait
201
201
 
202
- rewind_and_read(out).size.should == 3000
202
+ expect(rewind_and_read(out).size).to eq 3000
203
203
  ensure
204
204
  out.close
205
205
  end
@@ -6,7 +6,7 @@ if ChildProcess.jruby? && !ChildProcess.windows?
6
6
  let(:io) { ChildProcess::JRuby::IO.new }
7
7
 
8
8
  it "raises an ArgumentError if given IO does not respond to :to_outputstream" do
9
- lambda { io.stdout = nil }.should raise_error(ArgumentError)
9
+ expect { io.stdout = nil }.to raise_error(ArgumentError)
10
10
  end
11
11
  end
12
12
 
@@ -17,7 +17,7 @@ if ChildProcess.jruby? && !ChildProcess.windows?
17
17
  it "raises an error when trying to access the child's pid" do
18
18
  process = exit_with(0)
19
19
  process.start
20
- lambda { process.pid }.should raise_error(NotImplementedError)
20
+ expect { process.pid }.to raise_error(NotImplementedError)
21
21
  end
22
22
  end
23
23
  end
@@ -6,7 +6,7 @@ shared_examples_for "a platform that provides the child's pid" do
6
6
  process = write_pid(file.path).start
7
7
  process.wait
8
8
 
9
- process.pid.should == rewind_and_read(file).chomp.to_i
9
+ expect(process.pid).to eq rewind_and_read(file).chomp.to_i
10
10
  end
11
11
  end
12
12
  end
@@ -128,9 +128,9 @@ module ChildProcessSpecHelper
128
128
  def with_executable_at(path, &blk)
129
129
  if ChildProcess.os == :windows
130
130
  path << ".cmd"
131
- content = "@echo foo"
131
+ content = "#{RUBY} -e 'sleep 10' \n @echo foo"
132
132
  else
133
- content = "#!/bin/sh\necho foo"
133
+ content = "#!/bin/sh\nsleep 10\necho foo"
134
134
  end
135
135
 
136
136
  File.open(path, 'w', 0744) { |io| io << content }
@@ -9,29 +9,29 @@ if ChildProcess.unix? && !ChildProcess.jruby? && !ChildProcess.posix_spawn?
9
9
  it "handles ECHILD race condition where process dies between timeout and KILL" do
10
10
  process = sleeping_ruby
11
11
 
12
- process.stub(:fork).and_return('fakepid')
13
- process.stub(:send_term)
14
- process.stub(:poll_for_exit).and_raise(ChildProcess::TimeoutError)
15
- process.stub(:send_kill).and_raise(Errno::ECHILD.new)
12
+ allow(process).to receive(:fork).and_return('fakepid')
13
+ allow(process).to receive(:send_term)
14
+ allow(process).to receive(:poll_for_exit).and_raise(ChildProcess::TimeoutError)
15
+ allow(process).to receive(:send_kill).and_raise(Errno::ECHILD.new)
16
16
 
17
17
  process.start
18
- lambda { process.stop }.should_not raise_error
18
+ expect { process.stop }.not_to raise_error
19
19
 
20
- process.stub(:alive?).and_return(false)
20
+ allow(process).to receive(:alive?).and_return(false)
21
21
  end
22
22
 
23
23
  it "handles ESRCH race condition where process dies between timeout and KILL" do
24
24
  process = sleeping_ruby
25
25
 
26
- process.stub(:fork).and_return('fakepid')
27
- process.stub(:send_term)
28
- process.stub(:poll_for_exit).and_raise(ChildProcess::TimeoutError)
29
- process.stub(:send_kill).and_raise(Errno::ESRCH.new)
26
+ allow(process).to receive(:fork).and_return('fakepid')
27
+ allow(process).to receive(:send_term)
28
+ allow(process).to receive(:poll_for_exit).and_raise(ChildProcess::TimeoutError)
29
+ allow(process).to receive(:send_kill).and_raise(Errno::ESRCH.new)
30
30
 
31
31
  process.start
32
- lambda { process.stop }.should_not raise_error
32
+ expect { process.stop }.not_to raise_error
33
33
 
34
- process.stub(:alive?).and_return(false)
34
+ allow(process).to receive(:alive?).and_return(false)
35
35
  end
36
36
  end
37
37
 
@@ -39,14 +39,14 @@ if ChildProcess.unix? && !ChildProcess.jruby? && !ChildProcess.posix_spawn?
39
39
  let(:io) { ChildProcess::Unix::IO.new }
40
40
 
41
41
  it "raises an ArgumentError if given IO does not respond to :to_io" do
42
- lambda { io.stdout = nil }.should raise_error(ArgumentError, /to respond to :to_io/)
42
+ expect { io.stdout = nil }.to raise_error(ArgumentError, /to respond to :to_io/)
43
43
  end
44
44
 
45
45
  it "raises a TypeError if #to_io does not return an IO" do
46
46
  fake_io = Object.new
47
47
  def fake_io.to_io() StringIO.new end
48
48
 
49
- lambda { io.stdout = fake_io }.should raise_error(TypeError, /expected IO, got/)
49
+ expect { io.stdout = fake_io }.to raise_error(TypeError, /expected IO, got/)
50
50
  end
51
51
  end
52
52
 
@@ -10,14 +10,14 @@ if ChildProcess.windows?
10
10
  let(:io) { ChildProcess::Windows::IO.new }
11
11
 
12
12
  it "raises an ArgumentError if given IO does not respond to :fileno" do
13
- lambda { io.stdout = nil }.should raise_error(ArgumentError, /must have :fileno or :to_io/)
13
+ expect { io.stdout = nil }.to raise_error(ArgumentError, /must have :fileno or :to_io/)
14
14
  end
15
15
 
16
16
  it "raises an ArgumentError if the #to_io does not return an IO " do
17
17
  fake_io = Object.new
18
18
  def fake_io.to_io() StringIO.new end
19
19
 
20
- lambda { io.stdout = fake_io }.should raise_error(ArgumentError, /must have :fileno or :to_io/)
20
+ expect { io.stdout = fake_io }.to raise_error(ArgumentError, /must have :fileno or :to_io/)
21
21
  end
22
22
  end
23
23
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: childprocess
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-22 00:00:00.000000000 Z
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0
19
+ version: 3.0.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.0
26
+ version: 3.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: yard
29
29
  requirement: !ruby/object:Gem::Requirement