From: dan@... Date: 2018-01-14T21:10:00+00:00 Subject: [ruby-core:84861] [Ruby trunk Bug#9572] Restarting Coverage does not produce correct coverage result Issue #9572 has been updated by danmayer (Dan Mayer). Thanks for the reply... So you are right about the calculating the current coverage with `peek_result` and if we want to avoid complexity, it would be fine to drop the reset method and have the user app handle calculating the difference. The reset portion of this chance is really a convenience method. The more important piece of the change is being able to pause and resume coverage. Especially being able to continue getting coverage results for files already required. As it can have significant overhead and it is nice to turn it on to collect what you need but only have it running for that. I will get a better example, tomorrow, that shows a more realistic example than calling Coverage methods directly in files being measured. That doesn't illustrate the idea very well. A very quick way to think about the concept would be a rack middleware that would let you record coverage of any request that had a `coverage=true` param appended. ~~~ ruby record_coverage do calls_lots_of_app_code_some_code end ~~~ with something like that method handle setting up coverage, handling recording all the information, calculating the diff from `peek_result` and then formatting it for visualization. ---------------------------------------- Bug #9572: Restarting Coverage does not produce correct coverage result https://bugs.ruby-lang.org/issues/9572#change-69575 * Author: sean_ferguson (Sean Ferguson) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.6.0dev (2018-01-13 trunk 61811) [x86_64-darwin15] * Backport: ---------------------------------------- Feature 4796(https://www.ruby-forum.com/topic/1811306#1001864) appears to have a bug in it. While the test listed there does pass the following test does not:
require "test/unit"
require "coverage"
require 'tmpdir'
class TestCoverage < Test::Unit::TestCase
def test_restarting_coverage
Dir.mktmpdir {|tmp|
Dir.chdir(tmp) {
File.open("test.rb", "w") do |f|
f.puts <<-EOS
def coverage_test_method
puts :ok
end
EOS
end
Coverage.start
require tmp + '/test.rb'
Coverage.result
Coverage.start
coverage_test_method
result = Coverage.result
assert_equal 1, result.size
assert_equal [0, 1, nil], result.first[1] # coverage stats show an empty array here
}
}
end
end
It appears that while the coverage is finding the correct files it is
not giving any coverage stats for those files. Knowing this information would be very helpful in determining test coverage data for individual test files. I'm not very familiar
with how the coverage library works, but if you can point me at where to
look I can give fixing it a try.
Thanks,
Sean Ferguson
--
https://bugs.ruby-lang.org/
Unsubscribe: