ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: sam.rawlins@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:60922] [ruby-trunk - Feature #9508] Add method coverage and branch coverage metrics
Date: Fri, 21 Feb 2014 05:03:19 +0000	[thread overview]
Message-ID: <redmine.journal-45320.20140221050319.a25d99f98123b7d0@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-9508.20140210182127@ruby-lang.org

Issue #9508 has been updated by Sam Rawlins.

File pull-request-511.patch added

Good call Eric. I've carried out your suggestion [1], and attached the cumulative patch.

[1] this commit: https://github.com/srawlins/ruby/commit/cc50eab44f5ce0a4febdc05bdd99a09708e78b7e

----------------------------------------
Feature #9508: Add method coverage and branch coverage metrics
https://bugs.ruby-lang.org/issues/9508#change-45320

* Author: Sam Rawlins
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
Since the Coverage extension was introduced in Ruby 1.9, Ruby has had built-in line code coverage. Ruby should support more of the basic code coverage metrics [1]. I have a pull request on GitHub ( https://github.com/ruby/ruby/pull/511 ) to add Method Coverage (Function Coverage) and Branch Coverage. I'd love feedback to improve it.

Currently, with this feature, Coverage.result would look like:

    {"/Users/sam/code/ruby/cov_method.rb" => {
      lines: [1, 2, 2, 20, nil, nil, 2, 2, 2, nil, 0, nil, nil, nil, 1, 0, nil, nil, 1, 1, nil, nil, 1],
      methods: {1=>2, 15=>0, 19=>1},
      branches: {8=>2, 11=>0}
    }}

which includes
* the current Ruby line coverage report,
* as well as a method report (The method defined on line 1 was called 2 times; the method on line 15 was called 0 times; ...),
* and a branch report (the branch on line 8 was called 2 times; the branch on line 11 was called 0 times).

Branches
--------

Branches include the bodies of if, elsif, else, unless, and when statements, which are all tracked with this new feature. However, this feature is not aware of void bodies, for example:

    if foo
      :ok
    end

will report that only one branch exists in the file. It would be better to declare that there is a branch body on line 2, and a void branch body on line 3, or perhaps line 1. This would require the keys of the [:branch] Hash to be something other than line numbers. Perhaps label_no? Perhaps nd_type(node) paired with line or label_no?

More Coverage
-------------

I think that Statement Coverage, and Condition Coverage could be added to this feature, using the same techniques.

Caveats
-------

I was not very clear on the bit-arrays used in ruby.h, and just used values for the new macros that seemed to work.

Also, I would much rather use Ranges to identify a branch, so that a Coverage analyzer like SimpleCov won't need any kind of Ruby parser to identify and highlight a full chunk of code as a tested branch, or a not tested branch. I'm trying to find how that could be implemented...

[1] Wikipedia has good definitions: http://en.wikipedia.org/wiki/Code_coverage

---Files--------------------------------
pull-request-511.patch (26.7 KB)
pull-request-511.patch (38.5 KB)


-- 
http://bugs.ruby-lang.org/

  parent reply	other threads:[~2014-02-21  5:11 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-9508.20140210182127@ruby-lang.org>
2014-02-10 18:21 ` [ruby-core:60637] [ruby-trunk - Feature #9508] [Open] Add method coverage and branch coverage metrics sam.rawlins
2014-02-10 18:27 ` [ruby-core:60638] [ruby-trunk - Feature #9508] " sam.rawlins
2014-02-10 21:53   ` [ruby-core:60639] " Eric Wong
2014-02-10 22:01 ` [ruby-core:60640] " normalperson
2014-02-21  5:03 ` sam.rawlins [this message]
2014-02-21  7:57   ` [ruby-core:60931] " Eric Wong
2014-02-21  7:58 ` [ruby-core:60932] " normalperson
2014-02-26  3:22 ` [ruby-core:61097] " sam.rawlins
2014-02-26  3:23 ` [ruby-core:61098] " sam.rawlins
2014-02-26  8:56   ` [ruby-core:61101] " Eric Wong
2014-02-26  9:00 ` [ruby-core:61102] " normalperson
2014-02-26  9:28 ` [ruby-core:61105] " sam.rawlins
2014-03-01 22:34   ` [ruby-core:61203] " Eric Wong
2014-03-01 22:42 ` [ruby-core:61204] " normalperson
2014-03-02  8:02 ` [ruby-core:61222] " sam.rawlins
2014-03-02  9:14   ` [ruby-core:61223] " Eric Wong
2014-03-02  9:21 ` [ruby-core:61224] " normalperson
2014-03-03  4:17 ` [ruby-core:61241] " sam.rawlins
2014-03-03  6:57   ` [ruby-core:61244] " Eric Wong
2014-03-03  7:02 ` [ruby-core:61245] " normalperson
2014-03-03  8:06 ` [ruby-core:61246] " sam.rawlins
2014-03-03  8:49   ` [ruby-core:61248] " Eric Wong
2014-03-03  8:51 ` [ruby-core:61249] " normalperson
2014-03-03 11:05 ` [ruby-core:61253] " mame
2014-03-03 22:06 ` [ruby-core:61270] " sam.rawlins
2014-03-04  8:00   ` [ruby-core:61279] " Eric Wong
2014-03-03 22:28 ` [ruby-core:61271] " sam.rawlins
2014-03-04  8:09 ` [ruby-core:61280] " normalperson
2014-03-06  8:05 ` [ruby-core:61327] " sam.rawlins
2014-03-07 10:43   ` [ruby-core:61364] " Eric Wong
2014-03-07 10:52 ` [ruby-core:61365] " normalperson
2014-05-03 17:01 ` [ruby-core:62329] [ruby-trunk - Feature #9508] [Feedback] " mame
2014-05-09 17:04 ` [ruby-core:62480] [ruby-trunk - Feature #9508] " sam.rawlins
2014-05-10  0:41 ` [ruby-core:62489] [ruby-trunk - Feature #9508] [Assigned] " mame
2014-05-22  2:29 ` [ruby-core:62704] [ruby-trunk - Feature #9508] " sam.rawlins
2019-01-21  8:01 ` [ruby-core:91203] [Ruby trunk Feature#9508] " mame

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-45320.20140221050319.a25d99f98123b7d0@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).