mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
54163e2b52
line is out of the way. rb_sourceline() is unreliable when source code is big. [ruby-dev:44413] * test/coverage/test_coverage.rb: add a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
64 lines
1.4 KiB
Ruby
64 lines
1.4 KiB
Ruby
require "test/unit"
|
|
require "coverage"
|
|
require "tmpdir"
|
|
|
|
class TestCoverage < Test::Unit::TestCase
|
|
def test_result_without_start
|
|
assert_raise(RuntimeError) {Coverage.result}
|
|
end
|
|
def test_result_with_nothing
|
|
Coverage.start
|
|
result = Coverage.result
|
|
assert_kind_of(Hash, result)
|
|
result.each do |key, val|
|
|
assert_kind_of(String, key)
|
|
assert_kind_of(Array, val)
|
|
end
|
|
end
|
|
|
|
def test_restarting_coverage
|
|
loaded_features = $".dup
|
|
|
|
Dir.mktmpdir {|tmp|
|
|
Dir.chdir(tmp) {
|
|
File.open("test.rb", "w") do |f|
|
|
f.puts <<-EOS
|
|
def coverage_test_method
|
|
:ok
|
|
end
|
|
EOS
|
|
end
|
|
|
|
Coverage.start
|
|
require tmp + '/test.rb'
|
|
assert_equal 3, Coverage.result[tmp + '/test.rb'].size
|
|
Coverage.start
|
|
coverage_test_method
|
|
assert_equal 0, Coverage.result[tmp + '/test.rb'].size
|
|
}
|
|
}
|
|
ensure
|
|
$".replace loaded_features
|
|
end
|
|
|
|
def test_big_code
|
|
loaded_features = $".dup
|
|
|
|
Dir.mktmpdir {|tmp|
|
|
Dir.chdir(tmp) {
|
|
File.open("test.rb", "w") do |f|
|
|
f.puts "p\n" * 10000
|
|
f.puts "def ignore(x); end"
|
|
f.puts "ignore([1"
|
|
f.puts "])"
|
|
end
|
|
|
|
Coverage.start
|
|
require tmp + '/test.rb'
|
|
assert_equal 10003, Coverage.result[tmp + '/test.rb'].size
|
|
}
|
|
}
|
|
ensure
|
|
$".replace loaded_features
|
|
end
|
|
end
|