Skip to content

Commit

Permalink
Merge branch 'master' of github.com:colszowka/simplecov
Browse files Browse the repository at this point in the history
  • Loading branch information
colszowka committed Aug 1, 2011
2 parents 0c95ac6 + 0c66f9a commit e76dac2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
script: "bundle exec rake test"
rvm:
# - 1.8.6
# - 1.8.6 # Has trouble with rake 0.9+ :(
- 1.8.7
- 1.9.2
- ree
- ruby-head
# - ruby-head # Too unstable, leads to unpredictable results
- rbx
- jruby
4 changes: 4 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
= SimpleCov http://travis-ci.org/colszowka/simplecov.png

* Source code: https://github.com/colszowka/simplecov
* API documentation: http://rubydoc.info/gems/simplecov/frames
* Rubygems: http://rubygems.org/gems/simplecov

SimpleCov is a code coverage analysis tool for Ruby 1.9. It uses 1.9's built-in Coverage library to gather code
coverage data, but makes processing it's results much easier by providing a clean API to filter, group, merge, format
and display those results, thus giving you a complete code coverage suite that can be set up with just a couple lines of
Expand Down
2 changes: 1 addition & 1 deletion lib/simplecov/adapters.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Adaptars are glorified SimpleCov configuration procs that can be easily
# Adapters are glorified SimpleCov configuration procs that can be easily
# loaded using SimpleCov.start :rails and defined using
# SimpleCov.adapters.define :foo do
# # SimpleCov configuration here, same as in SimpleCov.configure
Expand Down
10 changes: 8 additions & 2 deletions lib/simplecov/source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ def initialize(filename, coverage)
# and thus including coverage data. Aliased as :source_lines
def lines
return @lines unless @lines.nil?

# Warning to identify condition from Issue #56
if coverage.size > src.size
$stderr.puts "Warning: coverage data provided by Coverage [#{coverage.size}] exceeds number of lines in #{filename} [#{src.size}]"
end

# Initialize lines
@lines = []
coverage.each_with_index do |coverage, i|
@lines << SimpleCov::SourceFile::Line.new(src[i], i+1, coverage, @skipped_line_numbers.include?(i + 1))
src.each_with_index do |src, i|
@lines << SimpleCov::SourceFile::Line.new(src, i+1, coverage[i], @skipped_line_numbers.include?(i + 1))
end
@lines
end
Expand Down
17 changes: 16 additions & 1 deletion test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,19 @@ def default_test
end

require 'shoulda_macros'
Test::Unit::TestCase.send :extend, ShouldaMacros
Test::Unit::TestCase.send :extend, ShouldaMacros

# Taken from http://stackoverflow.com/questions/4459330/how-do-i-temporarily-redirect-stderr-in-ruby
require "stringio"

def capture_stderr
# The output stream must be an IO-like object. In this case we capture it in
# an in-memory IO object so we can return the string value. You can assign any
# IO object here.
previous_stderr, $stderr = $stderr, StringIO.new
yield
$stderr.string
ensure
# Restore the previous value of stderr (typically equal to STDERR).
$stderr = previous_stderr
end
22 changes: 21 additions & 1 deletion test/test_source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

class TestSourceFile < Test::Unit::TestCase
on_ruby '1.9' do
COVERAGE_FOR_SAMPLE_RB = [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, nil, nil, nil, nil, nil, nil]
context "A source file initialized with some coverage data" do
setup do
@source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, nil, nil, nil, nil, nil, nil])
@source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), COVERAGE_FOR_SAMPLE_RB)
end

should "have a filename" do
Expand Down Expand Up @@ -51,5 +52,24 @@ class TestSourceFile < Test::Unit::TestCase
assert_equal 80.0, @source_file.covered_percent
end
end

context "Simulating potential Ruby 1.9 defect -- see Issue #56" do
setup do
@source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), COVERAGE_FOR_SAMPLE_RB + [nil])
end

should "have 16 source lines regardless of extra data in coverage array" do
# Do not litter test output with known warning
capture_stderr { assert_equal 16, @source_file.lines.count }
end

should "print a warning to stderr if coverage array contains more data than lines in the file" do
captured_output = capture_stderr do
@source_file.lines
end

assert_match /^Warning: coverage data provided/, captured_output
end
end
end
end

0 comments on commit e76dac2

Please sign in to comment.