childprocess 0.2.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -20,8 +20,11 @@ process.io.inherit!
20
20
  # ...or pass an IO
21
21
  process.io.stdout = Tempfile.new("child-output")
22
22
 
23
- # start the process
23
+ # modify the environment for the child
24
+ process.environment["a"] = "b"
25
+ process.environment["c"] = nil
24
26
 
27
+ # start the process
25
28
  process.start
26
29
 
27
30
  # check process status
@@ -111,8 +111,9 @@ module ChildProcess
111
111
  end
112
112
 
113
113
  def set_env(env)
114
- ENV.each { |k,v| env.put(k, v) } # not sure why this is needed
115
- @environment.each { |k,v| env.put(k.to_s, v.to_s) }
114
+ ENV.to_hash.merge(@environment).each do |k,v|
115
+ env.put(k.to_s, v.to_s) if v
116
+ end
116
117
  end
117
118
 
118
119
  end # Process
@@ -52,7 +52,7 @@ module ChildProcess
52
52
  end
53
53
 
54
54
  def set_env
55
- @environment.each { |k, v| ENV[k.to_s] = v.to_s }
55
+ @environment.each { |k, v| ENV[k.to_s] = v.nil? ? nil : v.to_s }
56
56
  end
57
57
 
58
58
  end # Process
@@ -100,12 +100,14 @@ module ChildProcess
100
100
  class Envp
101
101
  def initialize(env)
102
102
  @ptrs = env.map do |key, val|
103
+ next if val.nil?
104
+
103
105
  if key =~ /=|\0/ || val.include?("\0")
104
106
  raise InvalidEnvironmentVariable, "#{key.inspect} => #{val.inspect}"
105
107
  end
106
108
 
107
109
  FFI::MemoryPointer.from_string("#{key}=#{val}")
108
- end
110
+ end.compact
109
111
 
110
112
  @ptrs << nil
111
113
  end
@@ -1,3 +1,3 @@
1
1
  module ChildProcess
2
- VERSION = "0.2.9"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -44,12 +44,12 @@ module ChildProcess
44
44
  def create_environment_pointer
45
45
  return unless @environment.kind_of?(Hash) && @environment.any?
46
46
 
47
- # inherited env
48
- strings = ENV.map { |k,v| "#{k}=#{v}\0" }
47
+ strings = []
49
48
 
50
- # extras
51
- @environment.each do |key, val|
52
- if key =~ /=|\0/ || val.include?("\0")
49
+ ENV.to_hash.merge(@environment).each do |key, val|
50
+ next if val.nil?
51
+
52
+ if key.to_s =~ /=|\0/ || val.to_s.include?("\0")
53
53
  raise InvalidEnvironmentVariable, "#{key.inspect} => #{val.inspect}"
54
54
  end
55
55
 
@@ -101,6 +101,22 @@ describe ChildProcess do
101
101
  end
102
102
  end
103
103
 
104
+ it "can unset env vars" do
105
+ Tempfile.open("env-spec") do |file|
106
+ ENV['CHILDPROCESS_UNSET'] = '1'
107
+ process = write_env(file.path)
108
+ process.environment['CHILDPROCESS_UNSET'] = nil
109
+ process.start
110
+
111
+ process.wait
112
+ file.rewind
113
+
114
+ child_env = eval(file.read)
115
+ child_env.should_not have_key('CHILDPROCESS_UNSET')
116
+ end
117
+ end
118
+
119
+
104
120
  it "passes arguments to the child" do
105
121
  args = ["foo", "bar"]
106
122
 
@@ -122,11 +138,14 @@ describe ChildProcess do
122
138
  process = ruby("print Dir.pwd")
123
139
  process.io.stdout = process.io.stderr = file
124
140
 
125
- process.start
141
+ Dir.chdir(Dir.tmpdir) do
142
+ process.start
143
+ end
144
+
126
145
  process.wait
127
146
 
128
147
  file.rewind
129
- file.read.should == Dir.pwd
148
+ file.read.should == Dir.tmpdir
130
149
  end
131
150
  end
132
151
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: childprocess
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 9
10
- version: 0.2.9
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jari Bakken
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-12 00:00:00 Z
18
+ date: 2012-01-13 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec