File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,16 @@ describe Process::Status do
62
62
status_for(:interrupted ).normal_exit?.should be_false
63
63
end
64
64
65
+ it " #abnormal_exit?" do
66
+ Process ::Status .new(exit_status(0 )).abnormal_exit?.should be_false
67
+ Process ::Status .new(exit_status(1 )).abnormal_exit?.should be_false
68
+ Process ::Status .new(exit_status(127 )).abnormal_exit?.should be_false
69
+ Process ::Status .new(exit_status(128 )).abnormal_exit?.should be_false
70
+ Process ::Status .new(exit_status(255 )).abnormal_exit?.should be_false
71
+
72
+ status_for(:interrupted ).abnormal_exit?.should be_true
73
+ end
74
+
65
75
it " #signal_exit?" do
66
76
Process ::Status .new(exit_status(0 )).signal_exit?.should be_false
67
77
Process ::Status .new(exit_status(1 )).signal_exit?.should be_false
Original file line number Diff line number Diff line change @@ -91,6 +91,13 @@ enum Process::ExitReason
91
91
# * On Unix-like systems, this corresponds to `Signal::TERM`.
92
92
# * On Windows, this corresponds to the `CTRL_LOGOFF_EVENT` and `CTRL_SHUTDOWN_EVENT` messages.
93
93
SessionEnded
94
+
95
+ # Returns `true` if the process exited abnormally.
96
+ #
97
+ # This includes all values except `Normal`.
98
+ def abnormal ?
99
+ ! normal?
100
+ end
94
101
end
95
102
96
103
# The status of a terminated process. Returned by `Process#wait`.
@@ -186,10 +193,21 @@ class Process::Status
186
193
# Equivalent to `ExitReason::Normal`
187
194
#
188
195
# * `#exit_reason` provides more insights into other exit reasons.
196
+ # * `#abnormal_exit?` returns the inverse.
189
197
def normal_exit ? : Bool
190
198
exit_reason.normal?
191
199
end
192
200
201
+ # Returns `true` if the process terminated abnormally.
202
+ #
203
+ # Equivalent to `ExitReason#abnormal?`
204
+ #
205
+ # * `#exit_reason` provides more insights into the specific exit reason.
206
+ # * `#normal_exit?` returns the inverse.
207
+ def abnormal_exit ? : Bool
208
+ exit_reason.abnormal?
209
+ end
210
+
193
211
# If `signal_exit?` is `true`, returns the *Signal* the process
194
212
# received and didn't handle. Will raise if `signal_exit?` is `false`.
195
213
#
You can’t perform that action at this time.
0 commit comments