From f24243f4ee7f8003f365ebb1d993030c8593f4da Mon Sep 17 00:00:00 2001 From: Devonte W Date: Thu, 25 May 2023 09:05:17 +0100 Subject: [PATCH 1/3] fix(process): ensure chdir is a string Ensures that when `chdir` is not a `String` or `Nil` that it is converted to a `String`. --- src/process.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/process.cr b/src/process.cr index 12173c68b4a7..159b08b39eaa 100644 --- a/src/process.cr +++ b/src/process.cr @@ -243,7 +243,7 @@ class Process fork_output = stdio_to_fd(output, for: STDOUT) fork_error = stdio_to_fd(error, for: STDERR) - pid = Crystal::System::Process.spawn(command_args, env, clear_env, fork_input, fork_output, fork_error, chdir) + pid = Crystal::System::Process.spawn(command_args, env, clear_env, fork_input, fork_output, fork_error, chdir.try &.to_s) @process_info = Crystal::System::Process.new(pid) fork_input.close unless fork_input.in?(input, STDIN) From 69ea4521146643e91e0aa5d47098c5de2908bdce Mon Sep 17 00:00:00 2001 From: devnote-dev Date: Thu, 25 May 2023 15:30:56 +0100 Subject: [PATCH 2/3] spec(std/process): use Path for chdir --- spec/std/process_spec.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/std/process_spec.cr b/spec/std/process_spec.cr index 9292fd25aec9..837bcb7c47be 100644 --- a/spec/std/process_spec.cr +++ b/spec/std/process_spec.cr @@ -181,7 +181,7 @@ describe Process do end it "sets working directory" do - parent = File.dirname(Dir.current) + parent = Path.new File.dirname(Dir.current) command = {% if flag?(:win32) %} "cmd.exe /c echo %cd%" {% else %} From 299fca6170d557b09bf460bbfbfc875a8a3f1209 Mon Sep 17 00:00:00 2001 From: devnote-dev Date: Thu, 25 May 2023 15:59:56 +0100 Subject: [PATCH 3/3] spec(std/process): separate String and Path specs --- spec/std/process_spec.cr | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/spec/std/process_spec.cr b/spec/std/process_spec.cr index 837bcb7c47be..628baa93c39e 100644 --- a/spec/std/process_spec.cr +++ b/spec/std/process_spec.cr @@ -180,7 +180,20 @@ describe Process do $?.exit_code.should eq(0) end - it "sets working directory" do + it "sets working directory with string" do + parent = File.dirname(Dir.current) + command = {% if flag?(:win32) %} + "cmd.exe /c echo %cd%" + {% else %} + "pwd" + {% end %} + value = Process.run(command, shell: true, chdir: parent, output: Process::Redirect::Pipe) do |proc| + proc.output.gets_to_end + end + value.should eq "#{parent}#{newline}" + end + + it "sets working directory with path" do parent = Path.new File.dirname(Dir.current) command = {% if flag?(:win32) %} "cmd.exe /c echo %cd%"