diff options
author | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-16 18:49:26 +0900 |
---|---|---|
committer | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-30 00:39:06 +0900 |
commit | fcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch) | |
tree | 64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/test/coverage |
Fresh start
Diffstat (limited to 'jni/ruby/test/coverage')
-rw-r--r-- | jni/ruby/test/coverage/test_coverage.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/jni/ruby/test/coverage/test_coverage.rb b/jni/ruby/test/coverage/test_coverage.rb new file mode 100644 index 0000000..f4f192a --- /dev/null +++ b/jni/ruby/test/coverage/test_coverage.rb @@ -0,0 +1,64 @@ +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 "__id__\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 |