Skip to content

Commit 0285752

Browse files
committed
Add test for setting current working directory.
1 parent 19a6bd8 commit 0285752

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

test/async/container/.cwd.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
# Released under the MIT License.
5+
# Copyright, 2020-2024, by Samuel Williams.
6+
7+
require_relative '../../../lib/async/container/controller'
8+
9+
$stdout.sync = true
10+
11+
class Pwd < Async::Container::Controller
12+
def setup(container)
13+
container.spawn do |instance|
14+
instance.ready!
15+
16+
instance.exec("pwd", chdir: "/")
17+
end
18+
end
19+
end
20+
21+
controller = Pwd.new
22+
23+
controller.run

test/async/container/controller.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,19 @@ def after(error = nil)
206206
expect(input.read).to be == 'T'
207207
end
208208
end
209+
210+
with 'working directory' do
211+
let(:controller_path) {File.expand_path(".cwd.rb", __dir__)}
212+
213+
it "can change working directory" do
214+
pipe = IO.pipe
215+
216+
pid = Process.spawn("bundle", "exec", controller_path, out: pipe.last)
217+
pipe.last.close
218+
219+
expect(pipe.first.gets(chomp: true)).to be == "/"
220+
ensure
221+
Process.kill(:INT, pid) if pid
222+
end
223+
end
209224
end

0 commit comments

Comments
 (0)