[前][次][番号順一覧][スレッド一覧]

ruby-changes:47759

From: mame <ko1@a...>
Date: Thu, 14 Sep 2017 12:36:10 +0900 (JST)
Subject: [ruby-changes:47759] mame:r59877 (trunk): Add branch coverage for while and until statements

mame	2017-09-14 12:36:05 +0900 (Thu, 14 Sep 2017)

  New Revision: 59877

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59877

  Log:
    Add branch coverage for while and until statements

  Modified files:
    trunk/compile.c
    trunk/test/coverage/test_coverage.rb
Index: test/coverage/test_coverage.rb
===================================================================
--- test/coverage/test_coverage.rb	(revision 59876)
+++ test/coverage/test_coverage.rb	(revision 59877)
@@ -202,4 +202,28 @@ class TestCoverage < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/coverage/test_coverage.rb#L202
       }
     }
   end
+
+  def test_branch_coverage_for_while_statement
+    Dir.mktmpdir {|tmp|
+      Dir.chdir(tmp) {
+        File.open("test.rb", "w") do |f|
+          f.puts 'x = 3'
+          f.puts 'while x > 0'
+          f.puts '  x -= 1'
+          f.puts 'end'
+          f.puts 'until x == 10'
+          f.puts '  x += 1'
+          f.puts 'end'
+        end
+
+        assert_in_out_err(%w[-W0 -rcoverage], <<-"end;", ["{:branches=>{[:while, 0, 2]=>{[:body, 1, 3]=>3}, [:until, 2, 5]=>{[:body, 3, 6]=>10}}}"], [])
+          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
Index: compile.c
===================================================================
--- compile.c	(revision 59876)
+++ compile.c	(revision 59877)
@@ -4389,6 +4389,7 @@ compile_loop(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L4389
     LABEL *prev_end_label = ISEQ_COMPILE_DATA(iseq)->end_label;
     LABEL *prev_redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label;
     int prev_loopval_popped = ISEQ_COMPILE_DATA(iseq)->loopval_popped;
+    VALUE branches;
 
     struct iseq_compile_data_ensure_node_stack enl;
 
@@ -4419,6 +4420,8 @@ compile_loop(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L4420
     if (tmp_label) ADD_LABEL(ret, tmp_label);
 
     ADD_LABEL(ret, redo_label);
+    DECL_BRANCH_BASE(branches, line, type == NODE_WHILE ? "while" : "until");
+    ADD_TRACE_BRANCH_COVERAGE(ret, node->nd_body ? nd_line(node->nd_body) : line, "body", branches);
     CHECK(COMPILE_POPPED(ret, "while body", node->nd_body));
     ADD_LABEL(ret, next_label);	/* next */
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]