summaryrefslogtreecommitdiff
path: root/test/coverage/test_coverage.rb
diff options
context:
space:
mode:
authoryui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-23 00:17:35 +0000
committeryui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-23 00:17:35 +0000
commit7da13f05fdfa25c75e9ee02428d7b2ea175cd09d (patch)
treebfc73ac9ec008fd7e47362cdb3399a465f7f25c7 /test/coverage/test_coverage.rb
parentfb38cfb90fcd467e398cbfc13aa99cf38c569311 (diff)
Enable to take branch coverages for safe method invocations
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/coverage/test_coverage.rb')
-rw-r--r--test/coverage/test_coverage.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/coverage/test_coverage.rb b/test/coverage/test_coverage.rb
index 41a7e93..b9a8dc9 100644
--- a/test/coverage/test_coverage.rb
+++ b/test/coverage/test_coverage.rb
@@ -287,6 +287,27 @@ class TestCoverage < Test::Unit::TestCase
}
end
+ def test_branch_coverage_for_safe_method_invocation
+ Dir.mktmpdir {|tmp|
+ Dir.chdir(tmp) {
+ File.open("test.rb", "w") do |f|
+ f.puts 'a = 10'
+ f.puts 'b = nil'
+ f.puts 'a&.abs'
+ f.puts 'b&.hoo'
+ end
+
+ assert_in_out_err(%w[-W0 -rcoverage], <<-"end;", ["{:branches=>{[:\"&.\", 0, 3]=>{[:then, 1, 3]=>1, [:else, 2, 3]=>0}, [:\"&.\", 3, 4]=>{[:then, 4, 4]=>0, [:else, 5, 4]=>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
+
def test_method_coverage
Dir.mktmpdir {|tmp|
Dir.chdir(tmp) {