module Regtest
Constants
- VERSION
Attributes
Flag to show exceptions on STDERR
Public Class Methods
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 136 def check_results report "\nPlease check result files manually. Regtest isn't able to do that.", type: :unknown_result :unknown_result end
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 110 def determine_filename_from_caller ext caller_locations(2, 1).first.path.sub(/\.rb$/, '') << ext.to_s end
Report text to output with possible type, could be overwritten by plugins e.g. regtest/colors.
# File lib/regtest.rb, line 143 def report *args, type: nil puts *args end
Report some statistics, could be overwritten by plugins.
# File lib/regtest.rb, line 115 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 all results to the corresponding files.
# File lib/regtest.rb, line 123 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
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 65 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
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 84 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
Define a sample
# File lib/regtest.rb, line 28 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 if show_exceptions $stderr.puts nil, e.full_message end 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