From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id E88D117D5F39 for ; Mon, 3 Mar 2014 13:24:00 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (smtp.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 842ADB5D86F for ; Mon, 3 Mar 2014 13:18:15 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 0991697A820 for ; Mon, 3 Mar 2014 13:18:17 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Authentication-Results: funfun.nagaokaut.ac.jp (amavisd-new); dkim=fail (1024-bit key) reason="fail (message has been altered)" header.d=sendgrid.me Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ji8CsV85Qrtk for ; Mon, 3 Mar 2014 13:18:16 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 83A5297A826 for ; Mon, 3 Mar 2014 13:18:16 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id F2FB3952408 for ; Mon, 3 Mar 2014 13:18:13 +0900 (JST) Received: from [221.186.184.76] (unknown [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 60E211205FA; Mon, 3 Mar 2014 13:18:00 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with SMTP id B557C120527 for ; Mon, 3 Mar 2014 13:17:57 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=25fFCLG1suVnD6wDhIaeoDdlRNQ=; b=VZqmIQNSTEcJUR5cib GcME+tUp23TxTtmInOyYSyE0KwnAq/hBYhOwMqH2pfzpnorVCadj7LQvag9LK6FX YM/0Go02NRA40nOuv0OY5EWA5vdkVOQc2AYlaDMtkXfdLFabMtQ7kUYNFQZSiaK9 jGUE7+Rewq3CVGwAiIYlVg/Vg= Received: by mf178.sendgrid.net with SMTP id mf178.18552.531402724 Mon, 03 Mar 2014 04:17:54 +0000 (UTC) Received: from herokuapp.com (ec2-54-227-201-91.compute-1.amazonaws.com [54.227.201.91]) by ismtpd-021 (SG) with ESMTP id 14486298eec.3125.4aac6e Mon, 03 Mar 2014 04:17:54 +0000 (GMT) Date: Mon, 03 Mar 2014 04:17:54 +0000 From: sam.rawlins@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 35065 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 9508 X-Redmine-Issue-Author: srawlins X-Redmine-Sender: srawlins X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: OOF Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4YLoSZfJ/6rKgbmJ/XqM0hmW3QdiHlNK/e1XdgLYB/aL7b8Cndae8ahtL3ociB3GA/xCRJT/0oRPEv89dskHcWCd9cedf+BitvElDZGRjrhttbUcaZOLdnIKc6ta/5nXg= X-ML-Name: ruby-core X-Mail-Count: 61241 Subject: [ruby-core:61241] [ruby-trunk - Feature #9508] Add method coverage and branch coverage metrics X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #9508 has been updated by Sam Rawlins. Hi Eric, great find! It turns out the bug here was when requiring Shared Objects (etc.so in this case). I've fixed that in the last commit. Cumulative patch available at the pull request: https://github.com/ruby/ruby/pull/511.patch ---------------------------------------- Feature #9508: Add method coverage and branch coverage metrics https://bugs.ruby-lang.org/issues/9508#change-45585 * 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) pull-request-511.patch (57 KB) -- http://bugs.ruby-lang.org/