Class: Crosstest::Shell::ExecutionResult

Inherits:
Object
  • Object
show all
Includes:
Core::Util::Hashable
Defined in:
lib/crosstest/shell/execution_result.rb

Overview

Stores the result of running a command

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results) ⇒ ExecutionResult

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ExecutionResult


23
24
25
26
27
28
29
30
# File 'lib/crosstest/shell/execution_result.rb', line 23

def initialize(results)
  @command = results.fetch(:command)
  @exitstatus = results.fetch(:exitstatus)
  # Needs to be UTF-8 to serialize as YAML
  # FIXME: But is serializing to YAML still necessary? Have been using PStore.
  @stdout = results.fetch(:stdout).force_encoding('utf-8')
  @stderr = results.fetch(:stderr).force_encoding('utf-8')
end

Instance Attribute Details

#commandString (readonly)

Returns the command that was executed

Returns:

  • (String)

    the command that was executed


12
13
14
# File 'lib/crosstest/shell/execution_result.rb', line 12

def command
  @command
end

#exitstatusInteger (readonly)

Returns the exit code of the process

Returns:

  • (Integer)

    the exit code of the process


14
15
16
# File 'lib/crosstest/shell/execution_result.rb', line 14

def exitstatus
  @exitstatus
end

#stderrString (readonly)

Returns the captured standard error

Returns:

  • (String)

    the captured standard error


18
19
20
# File 'lib/crosstest/shell/execution_result.rb', line 18

def stderr
  @stderr
end

#stdoutString (readonly)

Returns the captured standard output

Returns:

  • (String)

    the captured standard output


16
17
18
# File 'lib/crosstest/shell/execution_result.rb', line 16

def stdout
  @stdout
end

Instance Method Details

#error!Object

Check if the command succeeded and raises and error if it did not.


39
40
41
42
43
44
45
# File 'lib/crosstest/shell/execution_result.rb', line 39

def error!
  unless successful?
    error = ExecutionError.new "#{command} returned exit code #{exitstatus}"
    error.execution_result = self
    fail error
  end
end

#successful?Boolean

Returns true if the command succeeded (exit code 0)

Returns:

  • (Boolean)

    true if the command succeeded (exit code 0)


33
34
35
# File 'lib/crosstest/shell/execution_result.rb', line 33

def successful?
  @exitstatus == 0
end

#to_sString

Returns a textual summary of the results

Returns:

  • (String)

    a textual summary of the results


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/crosstest/shell/execution_result.rb', line 48

def to_s
  ''"
  Execution Result:
    command: #{command}
    exitstatus: #{exitstatus}
    stdout:
  #{stdout}
    stderr:
  #{stderr}
  "''
end