Module: Regtest

Defined in:
lib/regtest.rb,
lib/regtest/version.rb

Constant Summary collapse

VERSION =
'2.0.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.exit_codesObject (readonly)

Returns the value of attribute exit_codes.



23
24
25
# File 'lib/regtest.rb', line 23

def exit_codes
  @exit_codes
end

.resultsObject (readonly)

Returns the value of attribute results.



23
24
25
# File 'lib/regtest.rb', line 23

def results
  @results
end

.startObject (readonly)

Returns the value of attribute start.



23
24
25
# File 'lib/regtest.rb', line 23

def start
  @start
end

Class Method Details

.check_resultsObject

Checking results, should be overwritten by SCM plugins e.g. regtest/git

Returns:

  • Symbol with check result (one of :success, :unknown_result or :fail)



102
103
104
105
# File 'lib/regtest.rb', line 102

def check_results
  report "\nPlease check result files manually. Regtest isn't able to do that.", type: :unknown_result
  :unknown_result
end

.combinations(hashy) ⇒ Object

Build all combinations of a Hash-like object with arrays as values. Return value is an array of OpenStruct instances.

Example:

require 'ostruct'
require 'regtest'

o = OpenStruct.new
o.a = [1,2,3]
o.b = [:x, :y]
Regtest.combinations(o)
# => [#<OpenStruct a=1, b=:x>, #<OpenStruct a=1, b=:y>,
#     #<OpenStruct a=2, b=:x>, #<OpenStruct a=2, b=:y>,
#     #<OpenStruct a=3, b=:x>, #<OpenStruct a=3, b=:y>]


60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/regtest.rb', line 60

def combinations hashy
  h = hashy.to_h
  a = h.values[0].product(*h.values[1..-1])
  res = []
  a.each do |e|
    o = OpenStruct.new
    h.keys.zip(e) do |k, v|
      o[k] = v
    end
    res << o
  end
  res
end

.determine_output_filenameObject

Determine the filename of the ouput file (results file) with informations from caller



76
77
78
79
# File 'lib/regtest.rb', line 76

def determine_output_filename
  rest = caller.drop_while {|c| c !~ /in `sample'/}.drop_while {|c| c =~ /in `sample'/}
  rest.first.split(/:\d+:/).first.sub(/\.rb/, '') << '.yml'
end

.report(*args, type: nil) ⇒ Object

Report text to output with possible type, could be overwritten by plugins e.g. regtest/colorize.



109
110
111
# File 'lib/regtest.rb', line 109

def report *args, type: nil
  puts *args
end

.report_statisticsObject

Report some statistics, could be overwritten by plugins.



82
83
84
85
86
# File 'lib/regtest.rb', line 82

def report_statistics
  time = Time.now - start
  sample_count = results.values.map(&:size).reduce(0, &:+)
  report format("\n\n%d samples executed in %.2f s (%d samples/s)", sample_count, time, sample_count / time), type: :statistics
end

.sample(name) ⇒ Object

Define a sample



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/regtest.rb', line 26

def sample name
  h = {}
  name = name.to_s if name.kind_of?(Symbol)
  h['sample'] = name
  begin
    h['result'] = yield
  rescue Exception => e
    h['exception'] = e.message
  end
  output_filename = determine_output_filename
  unless Regtest.results[output_filename]
    Regtest.report "\n", type: :filename unless Regtest.results.empty?
    Regtest.report output_filename, type: :filename
    Regtest.results[output_filename] = []
  end
  Regtest.results[output_filename] << h
  print '.'; $stdout.flush
  h
end

.saveObject

Save all results to the corresponding files.



89
90
91
92
93
94
95
96
97
# File 'lib/regtest.rb', line 89

def save
  results.each_pair do |filename, arr|
    File.open(filename, 'w') do |f|
      arr.each do |h|
        f.write h.to_yaml
      end
    end
  end
end