diff --git a/spec/std/process/status_spec.cr b/spec/std/process/status_spec.cr index ce066e0d7968..8aa26fe8c1e0 100644 --- a/spec/std/process/status_spec.cr +++ b/spec/std/process/status_spec.cr @@ -226,6 +226,14 @@ describe Process::Status do assert_prints Process::Status.new(exit_status(255)).to_s, "255" end + it "on abnormal exit" do + {% if flag?(:win32) %} + assert_prints status_for(:interrupted).to_s, "3221225786" + {% 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 +252,14 @@ 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) %} + assert_prints status_for(:interrupted).inspect, "Process::Status[3221225786]" + {% 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]" 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