Skip to content

Commit

Permalink
Adding the ability to surround code with '#:nocov:' comments to have …
Browse files Browse the repository at this point in the history
…it be ignored by rcov
  • Loading branch information
abedra committed Oct 16, 2009
1 parent 6e3075e commit 5da8e3c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
25 changes: 23 additions & 2 deletions lib/rcov/file_statistics.rb
Expand Up @@ -126,8 +126,7 @@ def is_code?(lineno)
end
end
end
@lines[lineno] && !@is_begin_comment[lineno] &&
@lines[lineno] !~ /^\s*(#|$)/
@lines[lineno] && !@is_begin_comment[lineno] && @lines[lineno] !~ /^\s*(#|$)/
end

private
Expand Down Expand Up @@ -163,6 +162,20 @@ def find_multiline_strings
end
end
end

def is_nocov?(line)
line =~ /#:nocov:/
end

def mark_nocov_regions(nocov_line_numbers, coverage)
while nocov_line_numbers.size > 0
begin_line, end_line = nocov_line_numbers.shift, nocov_line_numbers.shift
next unless begin_line && end_line
(begin_line..end_line).each do |line_num|
coverage[line_num] ||= :inferred
end
end
end

def precompute_coverage(comments_run_by_default = true)
changed = false
Expand All @@ -175,7 +188,11 @@ def precompute_coverage(comments_run_by_default = true)
@coverage[i] ||= :inferred
end
end
nocov_line_numbers = []

(0...lines.size).each do |i|
nocov_line_numbers << i if is_nocov?(@lines[i])

next if @coverage[i]
line = @lines[i]
if /^\s*(begin|ensure|else|case)\s*(?:#.*)?$/ =~ line && next_expr_marked?(i) or
Expand All @@ -190,7 +207,11 @@ def precompute_coverage(comments_run_by_default = true)
@coverage[i] ||= :inferred
changed = true
end

end

mark_nocov_regions(nocov_line_numbers, @coverage)

(@lines.size-1).downto(0) do |i|
next if @coverage[i]
if !is_code?(i) and @coverage[i+1]
Expand Down
2 changes: 1 addition & 1 deletion lib/rcov/version.rb
Expand Up @@ -3,7 +3,7 @@
# See LICENSE for licensing information.

module Rcov
VERSION = "0.9.4"
VERSION = "0.9.5"
RELEASE_DATE = "2009-10-16"
RCOVRT_ABI = [2,0,0]
UPSTREAM_URL = "http://github.com/relevance/rcov"
Expand Down
2 changes: 1 addition & 1 deletion rcov-java.gemspec
Expand Up @@ -24,7 +24,7 @@ PKG_FILES = ["bin/rcov", "lib/rcov.rb", "lib/rcov/lowlevel.rb", "lib/rcov/versio

Gem::Specification.new do |s|
s.name = %q{rcov}
s.version = "0.9.4"
s.version = "0.9.5"

s.required_rubygems_version = nil if s.respond_to? :required_rubygems_version=
s.authors = ["Relevance", "Chad Humphries (spicycode)", "Aaron Bedra (abedra)", "Jay McGaffigan", "Mauricio Fernandez"]
Expand Down
2 changes: 1 addition & 1 deletion rcov.gemspec
Expand Up @@ -25,7 +25,7 @@ PKG_FILES = ["bin/rcov", "lib/rcov.rb", "lib/rcov/lowlevel.rb", "lib/rcov/versio

Gem::Specification.new do |s|
s.name = %q{rcov}
s.version = "0.9.4"
s.version = "0.9.5"

s.required_rubygems_version = nil if s.respond_to? :required_rubygems_version=
s.authors = ["Relevance", "Chad Humphries (spicycode)", "Aaron Bedra (abedra)", "Jay McGaffigan", "Mauricio Fernandez"]
Expand Down

0 comments on commit 5da8e3c

Please sign in to comment.