From f3df884c46660a74cc4dbde9e6da9b071f555782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 11 Dec 2024 11:54:43 +0100 Subject: [PATCH 1/3] Add specs for status quo --- spec/std/process/status_spec.cr | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/std/process/status_spec.cr b/spec/std/process/status_spec.cr index ce066e0d7968..db207beb50a5 100644 --- a/spec/std/process/status_spec.cr +++ b/spec/std/process/status_spec.cr @@ -226,6 +226,18 @@ describe Process::Status do assert_prints Process::Status.new(exit_status(255)).to_s, "255" end + it "on abnormal exit" do + {% if flag?(:win32) %} + expect_raises(NotImplementedError, "Not Implemented: Process::Status#exit_signal") do + status_for(:interrupted).to_s + end + {% elsif flag?(:wasi) %} + assert_prints status_for(:interrupted).to_s, "INT" + {% else %} + assert_prints status_for(:interrupted).to_s, "INT" + {% end %} + end + {% if flag?(:unix) && !flag?(:wasi) %} it "with exit signal" do assert_prints Process::Status.new(Signal::HUP.value).to_s, "HUP" @@ -244,6 +256,18 @@ describe Process::Status do assert_prints Process::Status.new(exit_status(255)).inspect, "Process::Status[255]" end + it "on abnormal exit" do + {% if flag?(:win32) %} + expect_raises(NotImplementedError, "Not Implemented: Process::Status#exit_signal") do + status_for(:interrupted).inspect + end + {% elsif flag?(:wasi) %} + assert_prints status_for(:interrupted).inspect, "Process::Status[Signal::INT]" + {% else %} + assert_prints status_for(:interrupted).inspect, "Process::Status[Signal::INT]" + {% end %} + end + {% if flag?(:unix) && !flag?(:wasi) %} it "with exit signal" do assert_prints Process::Status.new(Signal::HUP.value).inspect, "Process::Status[Signal::HUP]" From ca709bf9d591d6eb41046c27ce84b85ab9ff5df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 11 Dec 2024 12:19:21 +0100 Subject: [PATCH 2/3] Fix implementation of `Process::Status#to_s` on Windows --- spec/std/process/status_spec.cr | 8 ++----- src/process/status.cr | 42 +++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/spec/std/process/status_spec.cr b/spec/std/process/status_spec.cr index db207beb50a5..9ed542d82b4f 100644 --- a/spec/std/process/status_spec.cr +++ b/spec/std/process/status_spec.cr @@ -228,9 +228,7 @@ describe Process::Status do it "on abnormal exit" do {% if flag?(:win32) %} - expect_raises(NotImplementedError, "Not Implemented: Process::Status#exit_signal") do - status_for(:interrupted).to_s - end + assert_prints status_for(:interrupted).to_s, "3221225786" {% elsif flag?(:wasi) %} assert_prints status_for(:interrupted).to_s, "INT" {% else %} @@ -258,9 +256,7 @@ describe Process::Status do it "on abnormal exit" do {% if flag?(:win32) %} - expect_raises(NotImplementedError, "Not Implemented: Process::Status#exit_signal") do - status_for(:interrupted).inspect - end + assert_prints status_for(:interrupted).inspect, "Process::Status[3221225786]" {% elsif flag?(:wasi) %} assert_prints status_for(:interrupted).inspect, "Process::Status[Signal::INT]" {% else %} diff --git a/src/process/status.cr b/src/process/status.cr index 694b35d0fd52..631bc73320a3 100644 --- a/src/process/status.cr +++ b/src/process/status.cr @@ -257,11 +257,15 @@ class Process::Status # `Process::Status[Signal::HUP]`. def inspect(io : IO) : Nil io << "Process::Status[" - if normal_exit? - exit_code.inspect(io) - else - exit_signal.inspect(io) - end + {% if flag?(:win32) %} + @exit_status.to_s(io) + {% else %} + if normal_exit? + exit_code.inspect(io) + else + exit_signal.inspect(io) + end + {% end %} io << "]" end @@ -270,11 +274,15 @@ class Process::Status # A normal exit status prints the numerical value (`0`, `1` etc). # A signal exit status prints the name of the `Signal` member (`HUP`, `INT`, etc.). def to_s(io : IO) : Nil - if normal_exit? - io << exit_code - else - io << exit_signal - end + {% if flag?(:win32) %} + @exit_status.to_s(io) + {% else %} + if normal_exit? + io << exit_code + else + io << exit_signal + end + {% end %} end # Returns a textual representation of the process status. @@ -282,10 +290,14 @@ class Process::Status # A normal exit status prints the numerical value (`0`, `1` etc). # A signal exit status prints the name of the `Signal` member (`HUP`, `INT`, etc.). def to_s : String - if normal_exit? - exit_code.to_s - else - exit_signal.to_s - end + {% if flag?(:win32) %} + @exit_status.to_s + {% else %} + if normal_exit? + exit_code.to_s + else + exit_signal.to_s + end + {% end %} end end From 4218fda6de1be2890881568d7318a1f2c5deb084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 11 Dec 2024 19:08:48 +0100 Subject: [PATCH 3/3] Drop wasi branches --- spec/std/process/status_spec.cr | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/std/process/status_spec.cr b/spec/std/process/status_spec.cr index 9ed542d82b4f..8aa26fe8c1e0 100644 --- a/spec/std/process/status_spec.cr +++ b/spec/std/process/status_spec.cr @@ -229,8 +229,6 @@ describe Process::Status do it "on abnormal exit" do {% if flag?(:win32) %} assert_prints status_for(:interrupted).to_s, "3221225786" - {% elsif flag?(:wasi) %} - assert_prints status_for(:interrupted).to_s, "INT" {% else %} assert_prints status_for(:interrupted).to_s, "INT" {% end %} @@ -257,8 +255,6 @@ describe Process::Status do it "on abnormal exit" do {% if flag?(:win32) %} assert_prints status_for(:interrupted).inspect, "Process::Status[3221225786]" - {% elsif flag?(:wasi) %} - assert_prints status_for(:interrupted).inspect, "Process::Status[Signal::INT]" {% else %} assert_prints status_for(:interrupted).inspect, "Process::Status[Signal::INT]" {% end %}