Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stringification of abnormal Process::Status on Windows [fixup #15255] #15267

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions spec/std/process/status_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]"
Expand Down
42 changes: 27 additions & 15 deletions src/process/status.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -270,22 +274,30 @@ 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.
#
# 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
Loading