In Files

  • coverage/coverage.c

Methods

Class/Module Index [+]

Quicksearch

Coverage

Coverage provides coverage measurement feature for Ruby. This feature is experimental, so these APIs may be changed in future.

Usage

(1) require “coverage.so” (2) do ::start (3) require or load Ruby source file (4) ::result will return a hash that contains filename as key and

coverage array as value.

Example

[foo.rb]
s = 0
10.times do |x|
  s += x
end

if s == 45
  p :ok
else
  p :ng
end
[EOF]

require "coverage.so"
Coverage.start
require "foo.rb"
p Coverage.result  #=> {"foo.rb"=>[1, 1, 10, nil, nil, 1, 1, nil, 0, nil]}

Public Class Methods

result => hash click to toggle source

Returns a hash that contains filename as key and coverage array as value and disables coverage measurement.

 
               static VALUE
rb_coverage_result(VALUE klass)
{
    VALUE coverages = rb_get_coverages();
    if (!RTEST(coverages)) {
        rb_raise(rb_eRuntimeError, "coverage measurement is not enabled");
    }
    RBASIC(coverages)->klass = rb_cHash;
    st_foreach(RHASH_TBL(coverages), coverage_result_i, 0);
    rb_hash_freeze(coverages);
    rb_reset_coverages();
    return coverages;
}
            
start => nil click to toggle source

Enables coverage measurement.

 
               static VALUE
rb_coverage_start(VALUE klass)
{
    if (!RTEST(rb_get_coverages())) {
        VALUE coverages = rb_hash_new();
        RBASIC(coverages)->klass = 0;
        rb_set_coverages(coverages);
    }
    return Qnil;
}