Skip to content
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
2 changes: 1 addition & 1 deletion core/process.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,7 @@ class Process::Status < Object
# * `false` if the process has completed unsuccessfully and exited.
# * `nil` if the process has not exited.
#
def success?: () -> bool
def success?: () -> bool?

# <!--
# rdoc-file=process.c
Expand Down
27 changes: 27 additions & 0 deletions test/stdlib/Process_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,30 @@ def spawn_child(script = "exit", **opts)
Process.spawn(RUBY_EXECUTABLE, "--disable=all", "-e", script, **opts)
end
end

class Process_StatusInstanceTest < Test::Unit::TestCase
include TestHelper

testing "::Process::Status"

def test_success?
assert_send_type "() -> true",
status_of("exit"), :success?
assert_send_type "() -> false",
status_of("exit 1"), :success?

# A child killed by a signal has not exited, so `success?` returns `nil`.
pid = Process.spawn(RUBY_EXECUTABLE, "--disable=all", "-e", "sleep")
Process.kill(:KILL, pid)
_, status = Process.wait2(pid)
assert_send_type "() -> nil",
status, :success?
end

private

def status_of(script)
_, status = Process.wait2(Process.spawn(RUBY_EXECUTABLE, "--disable=all", "-e", script))
status
end
end
Loading