module Regtest

Constants

Colorize
VERSION

Attributes

exit_codes[R]
log_filenames[R]
results[R]
start[R]

Public Class Methods

check_results() click to toggle source

Checking results, should be overwritten by SCM plugins e.g. regtest/git @return Symbol with check result (one of :success, :unknown_result or :fail)

# File lib/regtest.rb, line 128
def check_results
  report "\nPlease check result files manually. Regtest isn't able to do that.", type: :unknown_result
  :unknown_result
end
determine_filename_from_caller(ext) click to toggle source

Determine a filename which is derived from the filename of the “real” caller of the calling method @param ext new extension (i.e. '.yml')

# File lib/regtest.rb, line 102
def determine_filename_from_caller ext
  caller_locations(2, 1).first.path.sub(/\.rb$/, '') << ext.to_s
end
report(*args, type: nil) click to toggle source

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

# File lib/regtest.rb, line 135
def report *args, type: nil
  puts *args
end
report_statistics() click to toggle source

Report some statistics, could be overwritten by plugins.

# File lib/regtest.rb, line 107
def report_statistics
  now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  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
save() click to toggle source

Save all results to the corresponding files.

# File lib/regtest.rb, line 115
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

Public Instance Methods

combinations(hashy) click to toggle source

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>]
# 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
log(s, mode: nil) click to toggle source

Write (temporary) informations to a log file By default the log file is truncated at the first call of Regtest.log for each run of regtest, and all following calls appends to the log file. So you have a log for one run of regtest. You can use mode ('a' or 'w') to change this behaviour for each call of Regtest.log.

# File lib/regtest.rb, line 79
def log s, mode: nil
  log_filename = Regtest.determine_filename_from_caller('.log')
  case mode
  when nil
    mode = Regtest.log_filenames.include?(log_filename) ? 'a' : 'w'
  when 'a', 'w'
    # ok
  else
    raise ArgumentError.new(format('Mode %s is not allowed.', mode))
  end
  Regtest.log_filenames << log_filename
  File.open log_filename, mode do |f|
    f.puts s
  end
end
sample(name) { || ... } click to toggle source

Define a sample

# 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 = Regtest.determine_filename_from_caller('.yml')
  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