More coverage tests & specs. (#7171)

* Add spec for eval and line coverage.

* Add test for main file coverage.
This commit is contained in:
Samuel Williams 2023-01-21 16:49:13 -08:00 committed by GitHub
parent 2c93c55401
commit f5ea43a2e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
Notes: git 2023-01-22 00:49:35 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
4 changed files with 17 additions and 1 deletions

View File

@ -2,5 +2,11 @@ require_relative '../../spec_helper'
require 'coverage'
describe 'Coverage.start' do
it 'needs to be reviewed for spec completeness'
ruby_version_is '3.2' do
it "can measure coverage within eval" do
Coverage.start(lines: true, eval: true)
eval("Object.new\n"*3, binding, "test.rb", 1)
Coverage.result["test.rb"].should == {lines: [1, 1, 1]}
end
end
end

View File

@ -0,0 +1,2 @@
require 'coverage'
Coverage.start(:all)

1
test/coverage/main.rb Normal file
View File

@ -0,0 +1 @@
puts Coverage.peek_result[__FILE__][:lines]

View File

@ -26,6 +26,13 @@ class TestCoverage < Test::Unit::TestCase
end;
end
def test_coverage_in_main_script
autostart_path = File.expand_path("autostart.rb", __dir__)
main_path = File.expand_path("main.rb", __dir__)
assert_in_out_err(['-r', autostart_path, main_path], "", ["1"], [])
end
def test_coverage_running?
assert_in_out_err(%w[-rcoverage], <<-"end;", ["false", "true", "true", "false"], [])
p Coverage.running?