Class: Henitai::ScenarioExecutionResult
- Inherits:
-
Object
- Object
- Henitai::ScenarioExecutionResult
- Defined in:
- lib/henitai/scenario_execution_result.rb,
sig/henitai.rbs
Overview
Captures the result of one baseline or mutant test run.
Instance Attribute Summary collapse
-
#exit_status ⇒ Integer?
readonly
Returns the value of attribute exit_status.
-
#log_path ⇒ String
readonly
Returns the value of attribute log_path.
-
#status ⇒ Symbol
readonly
Returns the value of attribute status.
-
#stderr ⇒ String
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ String
readonly
Returns the value of attribute stdout.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #combined_output ⇒ String
- #failure_tail(all_logs: nil, lines: 12) ⇒ String
-
#initialize(status:, stdout:, stderr:, log_path:, exit_status: nil) ⇒ ScenarioExecutionResult
constructor
A new instance of ScenarioExecutionResult.
- #killed? ⇒ Boolean
- #log_text ⇒ String
-
#release_output! ⇒ Object
Frees the captured child output once it has been consumed (e.g. by the progress reporter).
- #should_show_logs?(all_logs: nil) ⇒ Boolean
- #survived? ⇒ Boolean
- #tail(lines = 12) ⇒ String
- #timeout? ⇒ Boolean
Constructor Details
#initialize(status:, stdout:, stderr:, log_path:, exit_status: nil) ⇒ ScenarioExecutionResult
Returns a new instance of ScenarioExecutionResult.
18 19 20 21 22 23 24 |
# File 'lib/henitai/scenario_execution_result.rb', line 18 def initialize(status:, stdout:, stderr:, log_path:, exit_status: nil) @status = status @stdout = stdout.to_s @stderr = stderr.to_s @log_path = log_path @exit_status = exit_status end |
Instance Attribute Details
#exit_status ⇒ Integer? (readonly)
Returns the value of attribute exit_status.
6 7 8 |
# File 'lib/henitai/scenario_execution_result.rb', line 6 def exit_status @exit_status end |
#log_path ⇒ String (readonly)
Returns the value of attribute log_path.
6 7 8 |
# File 'lib/henitai/scenario_execution_result.rb', line 6 def log_path @log_path end |
#status ⇒ Symbol (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/henitai/scenario_execution_result.rb', line 6 def status @status end |
#stderr ⇒ String (readonly)
Returns the value of attribute stderr.
6 7 8 |
# File 'lib/henitai/scenario_execution_result.rb', line 6 def stderr @stderr end |
#stdout ⇒ String (readonly)
Returns the value of attribute stdout.
6 7 8 |
# File 'lib/henitai/scenario_execution_result.rb', line 6 def stdout @stdout end |
Class Method Details
.build(wait_result:, stdout:, stderr:, log_path:) ⇒ ScenarioExecutionResult
8 9 10 11 12 13 14 15 16 |
# File 'lib/henitai/scenario_execution_result.rb', line 8 def self.build(wait_result:, stdout:, stderr:, log_path:) new( status: status_for(wait_result, stdout:, stderr:), stdout: stdout, stderr: stderr, log_path: log_path, exit_status: exit_status_for(wait_result) ) end |
Instance Method Details
#==(other) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/henitai/scenario_execution_result.rb', line 50 def ==(other) return status == other.status if other.respond_to?(:status) return status == other if other.is_a?(Symbol) super end |
#combined_output ⇒ String
65 66 67 68 69 70 |
# File 'lib/henitai/scenario_execution_result.rb', line 65 def combined_output [ (stdout.empty? ? nil : stream_section("stdout", stdout)), (stderr.empty? ? nil : stream_section("stderr", stderr)) ].compact.join("\n") end |
#failure_tail(all_logs: nil, lines: 12) ⇒ String
80 81 82 83 84 85 |
# File 'lib/henitai/scenario_execution_result.rb', line 80 def failure_tail(all_logs: nil, lines: 12) return combined_output if all_logs return "" unless should_show_logs?(all_logs:) tail(lines) end |
#killed? ⇒ Boolean
42 43 44 |
# File 'lib/henitai/scenario_execution_result.rb', line 42 def killed? status == :killed end |
#log_text ⇒ String
57 58 59 60 61 62 63 |
# File 'lib/henitai/scenario_execution_result.rb', line 57 def log_text @log_text ||= if File.exist?(log_path) File.read(log_path) else combined_output end end |
#release_output! ⇒ Object
Frees the captured child output once it has been consumed (e.g. by the progress reporter). The scheduler retains one result per mutant for the whole run; without this a runaway mutant's multi-hundred-MB output would stay resident until the run ends. Status/log_path/exit_status are kept so the result stays usable for scoring and log lookups.
31 32 33 34 35 36 |
# File 'lib/henitai/scenario_execution_result.rb', line 31 def release_output! @stdout = "" @stderr = "" @log_text = nil self end |
#should_show_logs?(all_logs: nil) ⇒ Boolean
76 77 78 |
# File 'lib/henitai/scenario_execution_result.rb', line 76 def should_show_logs?(all_logs: nil) all_logs || timeout? || status == :compile_error end |
#survived? ⇒ Boolean
38 39 40 |
# File 'lib/henitai/scenario_execution_result.rb', line 38 def survived? status == :survived end |
#tail(lines = 12) ⇒ String
72 73 74 |
# File 'lib/henitai/scenario_execution_result.rb', line 72 def tail(lines = 12) log_text.lines.last(lines).join end |
#timeout? ⇒ Boolean
46 47 48 |
# File 'lib/henitai/scenario_execution_result.rb', line 46 def timeout? status == :timeout end |