using rcov in already running program

  • Thread starter Suraj N. Kurapati
  • Start date
S

Suraj N. Kurapati

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

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).

Thanks for your consideration.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFE++CYmV9O7RYnKMcRAtDEAJ47xWPou9UKhk7JWgQuypnFGxFnOQCgsrOB
kdBiWljhTRfJe6pZB/BhqvM=
=KQjU
-----END PGP SIGNATURE-----
 
S

Suraj N. Kurapati

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mauricio said:
require 'rcov'
require 'rbconfig'

# try to load xx, but don't give up if it's not available
begin
require 'xx'
rescue LoadError
end
begin
require 'rcov/report'
rescue NameError
# hack to make textual reports work in the absence of xx-0.1.0
# Rcov::HTMLCoverage cannot be used without it though
end

rcov_analyzer = Rcov::CodeCoverageAnalyzer.new
at_exit do
rcov_analyzer.remove_hook
rcov_analyzer.dump_coverage_info([Rcov::TextReport.new])
# use Rcov::HTMLCoverage above to generate HTML reports; the formatters admit
# a number of options, listed in rcov's RDoc documentation.
end
rcov_analyzer.install_hook

I can't find Rcov::CodeCoverageAnalyzer#dump_coverage_info,
Rcov::HTMLCoverage, or Rcov::TextReport in the RDoc shipped with
rcov 0.7.0.1

Aren't these internal structures undocumented because they shouldn't
be used by outsiders?

Thanks for your attention.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFFAZ/EmV9O7RYnKMcRAsMKAKCAeme9tvUFN7g+7mYSLT45c6T3hACggLP8
xW150lZhoHpM0vTbA5ldaPA=
=lVQA
-----END PGP SIGNATURE-----
 
M

Mauricio Fernandez

Mauricio said:
rcov_analyzer = Rcov::CodeCoverageAnalyzer.new
at_exit do
rcov_analyzer.remove_hook
rcov_analyzer.dump_coverage_info([Rcov::TextReport.new])
# use Rcov::HTMLCoverage above to generate HTML reports; the formatters admit
# a number of options, listed in rcov's RDoc documentation.
end
rcov_analyzer.install_hook

I can't find Rcov::CodeCoverageAnalyzer#dump_coverage_info,
Rcov::HTMLCoverage, or Rcov::TextReport in the RDoc shipped with
rcov 0.7.0.1

Aren't these internal structures undocumented because they shouldn't
be used by outsiders?

Yes, I originally didn't want them to be used externally because I didn't want
to commit to keeping API compatibility, etc. But you've presented a good use
case that warrants exposing some of them, so I'll think about the API to make
sure it is reasonable and will not require changes in short, and document it.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top