Skip to content

Commit

Permalink
♻️ Improved shell_capture() results
Browse files Browse the repository at this point in the history
- Restored a default exit_code of nil to communicate crash condition to consumers of results
- Added explicit stderr and stdout fields to results for logging
  • Loading branch information
mkarlesky committed May 14, 2024
1 parent f483413 commit dee5c81
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/ceedling/system_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def shell_capture3(command:, boom:false)
# by the more capable and robust Process::Status.
# Parts of Process::Status's behavior is similar to an integer exit code in
# some operations but not all.
exit_code = 0
exit_code = nil

stdout, stderr = '' # Safe initialization defaults
status = nil # Safe initialization default
Expand All @@ -75,20 +75,21 @@ def shell_capture3(command:, boom:false)
stdout, stderr, status = Open3.capture3( command )
rescue => err
stderr = err.to_s
exit_code = -1
exit_code = nil
end

# If boom, then capture the actual exit code, otherwise leave it as zero
# as though execution succeeded
exit_code = status.exitstatus.freeze if boom and !status.nil?

# (Re)set the system exit code
$exit_code = exit_code

return {
# Combine stdout & stderr streams for complete output
:output => (stdout + stderr).freeze,

# Individual streams for detailed logging
:stdout => stdout.freeze,
:stderr => stderr.freeze,

# Relay full Process::Status
:status => status.freeze,

Expand Down

0 comments on commit dee5c81

Please sign in to comment.