# Rcov 0.5.0: code coverage + callsite info, RubyGems, Rant

**URL:** <https://www.ruby-forum.com/t/rcov-0-5-0-code-coverage-callsite-info-rubygems-rant/61969>\
**Category:** Ruby\
**Created:** [May 30, 2006, 11:58am UTC](https://www.ruby-forum.com/t/rcov-0-5-0-code-coverage-callsite-info-rubygems-rant/61969 "2006-05-30T11:58:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tulkas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5daacb/32.png) [@tulkas](https://www.ruby-forum.com/u/tulkas)\
**Post date:** [May 30, 2006, 11:58am UTC](https://www.ruby-forum.com/t/rcov-0-5-0-code-coverage-callsite-info-rubygems-rant/61969/1 "2006-05-30T11:58:03Z")

</div>

Source code, additional information, screenshots… available at  
[eigenclass.org](http://eigenclass.org/hiki.rb?rcov)  
Release information:  
[http://eigenclass.org/hiki.rb?rcov+0.5.0](http://eigenclass.org/hiki.rb?rcov+0.5.0)  
Sample cross-referenced report generated by rcov:  
[eigenclass.org](http://eigenclass.org/static/rcov-sample-report-crossref/)

This release is the first to include RubyGems packages: both a binary  
one for  
Win32 and a platform-independent one for all those with a compiler, (or  
a lot  
of patience, if willing to run rcov in pure-Ruby mode), so  
gem install rcov  
should work.

# Overview

rcov is a code coverage tool for Ruby. It is commonly used for viewing  
overall  
test coverage of target code. It features:

- fast execution: 20-300 times faster than previous tools
- multiple analysis modes: standard, bogo-profile, “intentional  
testing”,  
dependency analysis…
- fairly accurate coverage information through code linkage inference  
using  
simple heuristics
- cross-referenced XHTML and several kinds of text reports
- support for easy automation with Rake and Rant
- colorblind-friendliness

# What’s new in 0.5.0

See [http://eigenclass.org/hiki.rb?rcov+0.5.0](http://eigenclass.org/hiki.rb?rcov+0.5.0) for the detailed change  
summary.

The big feature introduced in this release is the ability to generate  
cross-referenced reports showing where methods are called from. This  
should  
prove useful when you’re attempting to optimize your program, or even  
when  
just trying to understand what is going on. You can view a sample report  
at

[eigenclass.org](http://eigenclass.org/static/rcov-sample-report-crossref/)

As usual, there are also some improvements in the heuristics (many  
multi-line  
quoted strings work now), a few additional features, more polishing of  
the  
existing ones and a bunch of bugfixes.

# Downloading

The last version is available at  
[eigenclass.org](http://eigenclass.org/hiki.rb?rcov)

# How do I use it?

In the common scenario, your tests are under test/ and the target code  
(whose coverage you want) is in lib/. In that case, all you have to do  
is  
use rcov to run the tests (instead of testrb), and a number of XHTML  
files  
with the code coverage information will be generated, e.g.

```
rcov -Ilib test/*.rb

```

will execute all the .rb files under test/ and generate the code  
coverage  
report for the target code (i.e. for the files in lib/) under coverage/.  
The  
target code needs not be under lib/; rcov will detect is as long as it  
is  
require()d by the tests. rcov is smart enough to ignore “uninteresting”  
files: the tests themselves, files installed in Ruby’s standard  
locations,  
etc. See rcov --help for the list of regexps rcov matches filenames  
against.

rcov can also be used from Rake or Rant; see README.{rake,rant} or the  
RDoc  
documentation for more information.

rcov can output information in several formats, and perform different  
kinds  
of analyses in addition to plain code coverage. See rcov --help for a  
description of the available options.

# Sample output

See [eigenclass.org](http://eigenclass.org/hiki.rb?rcov) (once again) for screenshots.

The text report (also used by default in RcovTasks) resembles

±----------------------------------------------------±------±------±-------+  
| File | Lines | LOC | COV |  
±----------------------------------------------------±------±------±-------+  
|lib/rcov.rb | 572 | 358 | 91.3% |  
±----------------------------------------------------±------±------±-------+  
|Total | 572 | 358 | 91.3% |  
±----------------------------------------------------±------±------±-------+  
91.3% 1 file(s) 572 Lines 358 LOC

The (undecorated) textual output with execution count information looks  
like this:

# $ rcov --no-html --text-counts b.rb

# ./b.rb

```
                                                                   | 

```

2  
a, b, c = (1…3).to\_a |  
2  
10.times do |  
1  
a += 1 |  
10  
20.times do |i| |  
10  
b += i |  
200  
b.times do |  
200  
c += (j = (b-a).abs) \> 0 ? j : 0 |  
738800  
end |  
0  
end |  
0  
end |  
0

## License

rcov is released under the terms of Ruby’s license.  
rcov includes xx 0.1.0, which is subject to the following conditions:

ePark Labs Public License version 1  
Copyright (c) 2005, ePark Labs, Inc. and contributors  
All rights reserved.

Redistribution and use in source and binary forms, with or without  
modification,  
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright  
notice, this  
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright  
notice,  
this list of conditions and the following disclaimer in the  
documentation  
and/or other materials provided with the distribution.
3. Neither the name of ePark Labs nor the names of its contributors  
may be  
used to endorse or promote products derived from this software  
without  
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS  
IS” AND  
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE  
IMPLIED  
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE  
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE  
LIABLE FOR  
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  
DAMAGES  
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR  
SERVICES;  
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  
AND ON  
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF  
THIS  
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
