Class: Cosmos::SuiteResults

Inherits:
Object show all
Defined in:
lib/cosmos/script/suite_results.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSuiteResults

Returns a new instance of SuiteResults.



24
25
26
27
28
29
30
31
32
# File 'lib/cosmos/script/suite_results.rb', line 24

def initialize
  @report = nil
  @context = nil
  @start_time = nil
  @stop_time = nil
  @results = nil
  @settings = nil
  @metadata = nil
end

Instance Attribute Details

#metadataObject

Returns the value of attribute metadata.



22
23
24
# File 'lib/cosmos/script/suite_results.rb', line 22

def 
  @metadata
end

Instance Method Details

#completeObject



98
99
100
101
# File 'lib/cosmos/script/suite_results.rb', line 98

def complete
  @stop_time = Time.now.sys
  footer()
end


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/cosmos/script/suite_results.rb', line 133

def footer
  self.puts "Completed #{@context}"

  @report << ''
  @report << "--- Test Summary ---"
  @report << ''

  pass_count = 0
  skip_count = 0
  fail_count = 0
  stopped    = false
  @results.each do |result|
    if result.result == :PASS
      pass_count += 1
    elsif result.result == :SKIP
      skip_count += 1
    elsif result.result == :FAIL
      fail_count += 1
    end

    if result.stopped
      stopped = true
    end
  end
  run_time = Time.format_seconds(@stop_time - @start_time)
  run_time << " (#{@stop_time - @start_time} seconds)" if @stop_time - @start_time > 60
  @report << "Run Time: #{run_time}"
  @report << "Total Tests: #{@results.length}"
  @report << "Pass: #{pass_count}"
  @report << "Skip: #{skip_count}"
  @report << "Fail: #{fail_count}"
  @report << ''
  if stopped
    @report << '*** Test was stopped prematurely ***'
    @report << ''
  end
end

#headerObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/cosmos/script/suite_results.rb', line 107

def header
  @report << "--- Test Report ---"
  # @report << ''
  # if @metadata
  #   begin
  #     items = get_tlm_packet('SYSTEM', 'META')
  #     @report << ''
  #     @report << "Metadata:"
  #     items.each do |item_name, item_value, _|
  #       next if SetTlmDialog::IGNORED_ITEMS.include?(item_name)
  #       @report << "#{item_name} = #{item_value}"
  #     end
  #   rescue DRb::DRbConnError
  #     # Oh well
  #   end
  # end
  if @settings
    @report << ''
    @report << "Settings:"
    @settings.each { |setting_name, setting_value| @report << "#{setting_name} = #{setting_value}" }
  end
  @report << ''
  @report << "Results:"
  self.puts "Executing #{@context}"
end

#process_result(results) ⇒ Object

process_result can handle an array of CosmosTestResult objects or a single CosmosTestResult object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/cosmos/script/suite_results.rb', line 56

def process_result(results)
  cosmos_lib = Regexp.new(File.join(Cosmos::PATH, 'lib'))
  # If we were passed an array we concat it to the results global
  if results.is_a? Array
    @results.concat(results)
  # A single result is appended and then turned into an array
  else
    @results << results
    results = [results]
  end
  # Process all the results (may be just one)
  results.each do |result|
    self.puts("#{result.group}:#{result.script}:#{result.result}")
    if result.message
      result.message.each_line do |line|
        if /[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F-\xFF]/.match?(line)
          line.chomp!
          line = line.inspect.remove_quotes
        end
        @report << '  ' + line.strip
      end
    end
    if result.exceptions
      @report << "  Exceptions:"
      result.exceptions.each_with_index do |error, index|
        error.formatted().each_line do |line|
          next if /in run_text/.match?(line)
          next if /running_script.rb/.match?(line)
          next if line&.match?(cosmos_lib)

          if /[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F-\xFF]/.match?(line)
            line.chomp!
            line = line.inspect.remove_quotes
          end
          @report << '    ' + line.strip
        end
        @report << '' if index != (result.exceptions.length - 1)
      end
    end
  end
end

#puts(string) ⇒ Object



175
176
177
# File 'lib/cosmos/script/suite_results.rb', line 175

def puts(string)
  @report << Time.now.sys.formatted + ': ' + string
end

#reportObject



103
104
105
# File 'lib/cosmos/script/suite_results.rb', line 103

def report
  @report.join("\n")
end

#start(test_type, test_suite_class, test_class = nil, test_case = nil, settings = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cosmos/script/suite_results.rb', line 34

def start(test_type, test_suite_class, test_class = nil, test_case = nil, settings = nil)
  @results = []
  @start_time = Time.now.sys
  @settings = settings
  @report = []

  if test_case
    # Executing a single test case
    @context = "#{test_suite_class.name}:#{test_class.name}:#{test_case} #{test_type}"
  elsif test_class
    # Executing an entire test
    @context = "#{test_suite_class.name}:#{test_class.name} #{test_type}"
  else
    # Executing a test suite
    @context = "#{test_suite_class.name} #{test_type}"
  end

  header()
end

#write(string) ⇒ Object



171
172
173
# File 'lib/cosmos/script/suite_results.rb', line 171

def write(string)
  @report << Time.now.sys.formatted + ': ' + string
end