From: "Suraj N. Kurapati" Date: 2006-09-05T03:00:07+09:00 Subject: Re: using rcov in already running program -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Mauricio Fernandez wrote: > On Mon, Sep 04, 2006 at 05:15:24PM +0900, Suraj N. Kurapati wrote: >> How can I use rcov from an already running Ruby program? >> >> I'm running a Ruby interpreter that is embedded within a C program. >> This situation is the inverse of how rcov is presently used: rcov is >> used to run *.rb files instead of ruby. >> >> So, I want to be able to write something like "require >> 'rcov/runner'" and have rcov do it do its thing on the currently >> running Ruby program. This is like running unit tests by simply >> doing "require 'test/unit'" (which has a Kernel#at_exit statement >> that runs all the tests before the program terminates). > > I've never used rcov with an embedded Ruby interpreter, but something like > this should work: [code snipped] This works wonderfully. Thank you! > In your case, you can require 'rcov/runner' in the embedded interpreter, and > the code loaded/parsed from that moment on will be monitored. This is fine for my purpose. > rcov/runner.rb seems a good idea and I'd want to add it to the next release; > do you have any suggestions regarding the interface or the default options? Yes, I would like a mechanism to pass the regular rcov command-line options to the embedded rcov runner. I'm thinking that this can be done either by setting the global ARGV array or maybe a RCOV_ARGV array before loading the runner: RCOV_ARGV = ['--html', '--no-color', '--save', 'coverage.html'] require 'rcov/runner' > Dumping a textual report like the above one seems to make sense as it is akin > to Test::Unit's output. This is sufficient, but I would like to see the more detailed HTML report as well, so I can know where coverage needs improvement. Thanks for your consideration. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFE/Gk8mV9O7RYnKMcRApLkAJ9kFZzksCI+lFCPQWTEg9uRDRzN4ACdGG6d 8ppz/ZArivMxULZyUj7b/+c= =4bnx -----END PGP SIGNATURE-----