diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-14 03:25:36 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-14 03:25:36 +0000 |
commit | ce570370f0f1e2aaf8c58d4b6629a627b7e7085b (patch) | |
tree | c0824cbcc23b9aacf694750e6f83b8b780da828d /test/coverage | |
parent | c171ca1efdbc5553f9ba94e9ce4e7d868f3cb298 (diff) | |
download | ruby-ce570370f0f1e2aaf8c58d4b6629a627b7e7085b.tar.gz |
Add branch coverage for if statement
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/coverage')
-rw-r--r-- | test/coverage/test_coverage.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/coverage/test_coverage.rb b/test/coverage/test_coverage.rb index 2858260646..5ed838e627 100644 --- a/test/coverage/test_coverage.rb +++ b/test/coverage/test_coverage.rb @@ -175,4 +175,31 @@ class TestCoverage < Test::Unit::TestCase end end; end + + def test_branch_coverage_for_if_statement + Dir.mktmpdir {|tmp| + Dir.chdir(tmp) { + File.open("test.rb", "w") do |f| + f.puts 'def foo(x)' + f.puts ' if x == 0' + f.puts ' 0' + f.puts ' else' + f.puts ' 1' + f.puts ' end' + f.puts 'end' + f.puts 'foo(0)' + f.puts 'foo(0)' + f.puts 'foo(1)' + end + + assert_in_out_err(%w[-W0 -rcoverage], <<-"end;", ["{:branches=>{[:if, 0, 2]=>{[:then, 1, 3]=>2, [:else, 2, 5]=>1}}}"], []) + ENV["COVERAGE_EXPERIMENTAL_MODE"] = "true" + Coverage.start(branches: true) + tmp = Dir.pwd + require tmp + '/test.rb' + p Coverage.result[tmp + "/test.rb"] + end; + } + } + end end |