[ANN] rcov 0.2.0 - code coverage tool for Ruby

M

Mauricio Fernandez

Source code, additional information, screenshots... available at

http://eigenclass.org/hiki.rb?rcov


Overview
--------

rcov is a tool for simple code coverage analysis in Ruby. It improves on
the better known coverage[1] in a number of ways:
* 20-300 times faster: typically, the program being inspect runs only ~3
times slower than without rcov (i.e. not 200 times slower as with
some other tools)
* more convenient interface
* prettier output (since 0.2.0)
* more accurate coverage information through code linkage inference using
simple heuristics
* additional features like bogo-profile mode, colorblind-friendliness...

Code coverage shouldn't be abused (in few words, C0 coverage guarantees
nothing) but it's still useful for testing: it will at least tell you when
your tests need more work, and most importantly where.


What's new in 0.2.0
-------------------
A change summary is available at
http://eigenclass.org/hiki.rb?rcov+0.2.0

Visible changes since 0.1.0:
* improved HTML output (cleaner and more readable) --- using xx under the hood
* textual output: execution counts or code decorated with ANSI sequences
* more convenient interface: run several scripts/tests in one go, argument
propagation...


Downloading
-----------

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


How do I use it? What does it look like?
----------------------------------------

Just use rcov to run your program (instead of ruby), and a number of XHTML
files with the code coverage information will be generated, e.g.

rcov test/*.rb

will execute all the .rb files under test/ and generate the code coverage report
under coverage/. rcov can also operate in "bogo-profiling mode"
and output the relevant information in alternative formats (for the time
being, plain text with execution count annotations and colored text). Use
rcov -h
for more information.


Sample output
-------------

See http://eigenclass.org/hiki.rb?rcov (once again) for screenshots.
The (undecorated) textual output with execution count information looks like this:

$ rcov --no-html -t 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.


[1] http://freshmeat.net/projects/rubycoverage
 
R

Robert Feldt

Thanks Mauricio, this looks great and arrives just at the right momen
when the students in my testing course goes into structural testing of
their programs. I'll point them to this!

Keep up the good work!

Thanks,

Robert Feldt
 
S

Shashank Date

--0-277823646-1141178109=:76837
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hi,
=20
=20

Source code, additional information, screenshots... available at=20

http://eigenclass.org/hiki.rb?rcov


On Windows XP (HOME SP2) using MSVC ++ 6.0 and latest one-click install=
er:
=20
C:\extract\_ruby\rcov>ruby setup.rb
---> bin
<--- bin
---> ext
---> ext/rcovrt
C:/ruby/bin/ruby.exe C:/extract/_ruby/rcov/ext/rcovrt/extconf.rb
creating Makefile
<--- ext/rcovrt
<--- ext
---> bin
updating shebang: rcov
<--- bin
---> ext
---> ext/rcovrt
nmake
Microsoft (R) Program Maintenance Utility Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.
cl -nologo -MD -Zi -O2b2xg- -G6 -I. -IC:/ruby/lib/ruby/1.8/i386=
-mswin32 -IC:/ruby/lib/ruby/1.8/i386-mswin32 -IC:/extract/_ruby/rcov/ext/=
rcovrt -I. -I./.. -I./../missing -c -Tcrcov.c
rcov.c
rcov.c(21) : error C2146: syntax error : missing ')' before identifier 'e=
vent'
rcov.c(21) : error C2061: syntax error : identifier 'event'
rcov.c(21) : error C2059: syntax error : ';'
rcov.c(21) : error C2059: syntax error : ','
rcov.c(22) : error C2059: syntax error : ')'
rcov.c(70) : error C2065: 'coverage_event_hook' : undeclared identifier
rcov.c(71) : error C2065: 'RUBY_EVENT_ALL' : undeclared identifier
rcov.c(71) : error C2065: 'RUBY_EVENT_C_CALL' : undeclared identifier
rcov.c(72) : error C2065: 'RUBY_EVENT_C_RETURN' : undeclared identifier
rcov.c(72) : error C2065: 'RUBY_EVENT_CLASS' : undeclared identifier
NMAKE : fatal error U1077: 'cl' : return code '0x2'
Stop.
setup.rb:655:in `command': system("nmake") failed (RuntimeError)
from setup.rb:664:in `make'
from setup.rb:1258:in `setup_dir_ext'
from setup.rb:1532:in `__send__'
from setup.rb:1532:in `traverse'
from setup.rb:1530:in `dive_into'
from setup.rb:1530:in `traverse'
from setup.rb:1534:in `traverse'
from setup.rb:1533:in `each'
... 7 levels...
from setup.rb:996:in `exec_setup'
from setup.rb:813:in `invoke'
from setup.rb:773:in `invoke'
from setup.rb:1578
C:\extract\_ruby\rcov>
=20
=20

=09
 
M

Meinrad Recheis

------=_Part_13304_18007145.1141152674929
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

many thanks for rcov, batsman!!
i was just trying it out. what a great tool. i will be using it heavily for
sure!
-- henon

Source code, additional information, screenshots... available at

http://eigenclass.org/hiki.rb?rcov


Overview
--------

rcov is a tool for simple code coverage analysis in Ruby. It improves on
the better known coverage[1] in a number of ways:
* 20-300 times faster: typically, the program being inspect runs only ~3
times slower than without rcov (i.e. not 200 times slower as with
some other tools)
* more convenient interface
* prettier output (since 0.2.0)
* more accurate coverage information through code linkage inference using
simple heuristics
* additional features like bogo-profile mode, colorblind-friendliness...

Code coverage shouldn't be abused (in few words, C0 coverage guarantees
nothing) but it's still useful for testing: it will at least tell you whe= n
your tests need more work, and most importantly where.


What's new in 0.2.0
-------------------
A change summary is available at
http://eigenclass.org/hiki.rb?rcov+0.2.0

Visible changes since 0.1.0:
* improved HTML output (cleaner and more readable) --- using xx under the
hood
* textual output: execution counts or code decorated with ANSI sequences
* more convenient interface: run several scripts/tests in one go, argumen= t
propagation...


Downloading
-----------

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


How do I use it? What does it look like?
----------------------------------------

Just use rcov to run your program (instead of ruby), and a number of XHTM= L
files with the code coverage information will be generated, e.g.

rcov test/*.rb

will execute all the .rb files under test/ and generate the code coverage
report
under coverage/. rcov can also operate in "bogo-profiling mode"
and output the relevant information in alternative formats (for the time
being, plain text with execution count annotations and colored text). Use
rcov -h
for more information.


Sample output
-------------

See http://eigenclass.org/hiki.rb?rcov (once again) for screenshots.
The (undecorated) textual output with execution count information looks
like this:

$ rcov --no-html -t b.rb

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D
./b.rb

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D

| 2
a, b, c =3D (1..3).to_a
| 2
10.times do
| 1
a +=3D
1 | 10
20.times do |i|
| 10
b +=3D
i | 200
b.timesdo | = 200
c +=3D (j =3D (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.


[1] http://freshmeat.net/projects/rubycoverage

------=_Part_13304_18007145.1141152674929--
 
S

Shashank Date

--0-1571069316-1141190198=:69240
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hi ,

Mauricio Fernandez wrote:
Source code, additional information, screenshots... available at=20

http://eigenclass.org/hiki.rb?rcov


On Windows XP (HOME SP2) using MSVC ++ 6.0 and latest one-click installer=
:


=20
I was wrong ... this error only occurs if I use the older version of on=
e-click installer.=20
Works fine with the latest version.=20
=20
However, now after successful compile and install, when I do this:
=20
C:\atest>rcov --no-html -t tst_rcov.rb
=20
C:\atest>c:\ruby\bin\ruby.exe c:\ruby\bin\rcov.rb --no-html -t tst_rcov=
rb
c:/ruby/lib/ruby/1.8/optparse.rb:1445:in `complete': invalid option: --no=
-html (OptionParser::Invalid
from c:/ruby/lib/ruby/1.8/optparse.rb:1443:in `complete'
from c:/ruby/lib/ruby/1.8/optparse.rb:1278:in `order!'
from c:/ruby/lib/ruby/1.8/optparse.rb:1271:in `order!'
from c:/ruby/lib/ruby/1.8/optparse.rb:1351:in `permute!'
from c:/ruby/lib/ruby/1.8/optparse.rb:1378:in `parse!'
from c:/ruby/bin/rcov.rb:627
=20
C:\atest>rcov -h
=20
C:\atest>c:\ruby\bin\ruby.exe c:\ruby\bin\rcov.rb -h
rcov 0.1.0 2006-01-23
Usage: rcov [options] <script.rb>
Options:
-o, --output PATH Destination directory.
-I, --include PATHS Prepend PATHS to $: (colon separated=
list)
-n, --no-color Create colorblind-safe output.
-x, --exclude PATTERNS Don't generate info for the files ma=
tching any
of the given patterns (comma-separat=
ed regexp list)
-p, --profile Generate bogo-profiling info.
-r, --range Color scale range for profiling info=
(dB).
-h, --help Show this message
--version Show version
C:\atest>
=20
=20
=20

=09
 
S

Shashank Date

--0-1384320789-1141190841=:60579
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hi,
=20
It works ... if I use the correct version !=20
=20
Sorry for the noise ....
=20
And now, I have the Windows binary in case anybody wants to try it out wi=
th the _latest_ one click installer.
=20
-- Shashank
=20
Hi ,

Shashank Date wrote:=20
Mauricio Fernandez wrote:
Source code, additional information, screenshots... available at=20

http://eigenclass.org/hiki.rb?rcov


On Windows XP (HOME SP2) using MSVC ++ 6.0 and latest one-click installer=
:



I was wrong ... this error only occurs if I use the older version of one-=
click installer.=20
Works fine with the latest version.=20

However, now after successful compile and install, when I do this:

C:\atest>rcov --no-html -t tst_rcov.rb

C:\atest>c:\ruby\bin\ruby.exe c:\ruby\bin\rcov.rb --no-html -t tst_rcov.r=
b
c:/ruby/lib/ruby/1.8/optparse.rb:1445:in `complete': invalid option: --no=
-html (OptionParser::Invalid
from c:/ruby/lib/ruby/1.8/optparse.rb:1443:in `complete'
from c:/ruby/lib/ruby/1.8/optparse.rb:1278:in `order!'
from c:/ruby/lib/ruby/1.8/optparse.rb:1271:in `order!'
from c:/ruby/lib/ruby/1.8/optparse.rb:1351:in `permute!'
from c:/ruby/lib/ruby/1.8/optparse.rb:1378:in `parse!'
from c:/ruby/bin/rcov.rb:627

C:\atest>rcov -h

C:\atest>c:\ruby\bin\ruby.exe c:\ruby\bin\rcov.rb -h
rcov 0.1.0 2006-01-23
Usage: rcov [options]=20
Options:
-o, --output PATH Destination directory.
-I, --include PATHS Prepend PATHS to $: (colon separated list)
-n, --no-color Create colorblind-safe output.
-x, --exclude PATTERNS Don't generate info for the files matching any
of the given patterns (comma-separated regexp list)
-p, --profile Generate bogo-profiling info.
-r, --range Color scale range for profiling info (dB).
-h, --help Show this message
--version Show version
C:\atest>
 
V

Ville Mattila

Hello,

It seems like you are using the old rcov eg. rcov 0.1 instead of 0.2

- Ville
 
M

Mauricio Fernandez

It works ... if I use the correct version !

I think I might be to blame for that; I didn't really think about
win32 issues like whether the executable is associated to the Ruby
interpreter. I'll try to do better next time.
 
M

Mauricio Fernandez

Fabulous!

I would like to get coverage for my test cases too. Could this be
accomodated (without tweaking @ignore_files in the source)?

It will be possible in the next release; in the meantime, could you use the
following patch?


--- old-rcov/bin/rcov 2006-03-14 18:12:47.000000000 +0100
+++ new-rcov/bin/rcov 2006-03-14 09:53:07.000000000 +0100
@@ -790,6 +790,11 @@
regexps = list.split(/,/).map{|x| Regexp.new x}
options.skip += regexps
end
+ opts.on("--exclude-only PATTERNS",
+ "Skip info generation only for the files matching the",
+ "given patterns (i.e. discard the default regexp list).") do |list|
+ options.skip = list.split(/,/).map{|x| Regexp.new(x) }
+ end
opts.on("-p", "--profile", "Generate bogo-profiling info.") do
options.profiling = true
options.destdir ||= "profiling"


After applying: (note that in rcov 0.2.0 -n == --no-color is ignored in -T
rich-text mode, so you'll get ANSI-decorated output instead of the following)

$ rcov --exclude-only lib/ruby --no-html -n -T tc_foo.rb
Loaded suite tc_foo
Started
6
 
P

pat eyler

Just want to join the chorus of thank you. This is perfect. I found a
blog entry (http://asplake.blogspot.com/2006/01/revert-that-rakefile.ht= ml)
and worked it over a little into the file below which I put in
lib/tasks/rcov.rake in a rails project. It works great.
...
[rcov.rake]

Thank you! May I distribute it with rcov (under Ruby's license)? It
seems many people will want to use it that way...

Please do! I've got a much uglier/less comprehensive set of Rake
tasks that I use, I'd love to have a cleaner version. (My tasks build
the standard html output for files in my repository or create the ascii
'poor mans profiling'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top