From 839ba4031902264f08e0e5d16ebf52ee6bba6773 Mon Sep 17 00:00:00 2001 From: Christoph Olszowka Date: Thu, 23 Jun 2011 22:25:38 -0700 Subject: [PATCH 1/6] Edited README.rdoc via GitHub --- README.rdoc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rdoc b/README.rdoc index f5b535eb..8ea3ccdd 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,5 +1,8 @@ = SimpleCov http://travis-ci.org/colszowka/simplecov.png +Source code: https://github.com/colszowka/simplecov +API documentation: http://rubydoc.info/gems/simplecov/frames + 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 From 9a182081aad902965015d63fd84b905363296af5 Mon Sep 17 00:00:00 2001 From: Christoph Olszowka Date: Thu, 23 Jun 2011 22:26:02 -0700 Subject: [PATCH 2/6] Updated github and rdoc references --- README.rdoc | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rdoc b/README.rdoc index 8ea3ccdd..fe19af5a 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,6 +1,7 @@ = SimpleCov http://travis-ci.org/colszowka/simplecov.png Source code: https://github.com/colszowka/simplecov + API documentation: http://rubydoc.info/gems/simplecov/frames SimpleCov is a code coverage analysis tool for Ruby 1.9. It uses 1.9's built-in Coverage library to gather code From 33105dc092a1e130e6d07cbfaf6a47c4bf8b0753 Mon Sep 17 00:00:00 2001 From: Christoph Olszowka Date: Thu, 23 Jun 2011 22:26:32 -0700 Subject: [PATCH 3/6] Edited README.rdoc via GitHub --- README.rdoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rdoc b/README.rdoc index fe19af5a..bc8da8ac 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,8 +1,8 @@ = SimpleCov http://travis-ci.org/colszowka/simplecov.png -Source code: https://github.com/colszowka/simplecov - -API documentation: http://rubydoc.info/gems/simplecov/frames +* 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 From 7bab159609b21a13d08ce5c6d90a514c3bcaeb57 Mon Sep 17 00:00:00 2001 From: Christoph Olszowka Date: Thu, 23 Jun 2011 22:31:22 -0700 Subject: [PATCH 4/6] Updated travis config --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 51254142..b2e3832a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 \ No newline at end of file From 25dffd0b2b3b3a28e67519ef623fc681a022282d Mon Sep 17 00:00:00 2001 From: Christoph Olszowka Date: Mon, 27 Jun 2011 07:42:15 -0700 Subject: [PATCH 5/6] Fixed typo. --- lib/simplecov/adapters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/simplecov/adapters.rb b/lib/simplecov/adapters.rb index 00e6fff5..4ba347e2 100644 --- a/lib/simplecov/adapters.rb +++ b/lib/simplecov/adapters.rb @@ -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 From 5d2eb623338ba82284c13bf554c9f71a760b0cbc Mon Sep 17 00:00:00 2001 From: Scott Pfister Date: Thu, 28 Jul 2011 11:18:34 -0500 Subject: [PATCH 6/6] Workaround for potential Ruby 1.9.x defect identified in Issue #56 --- lib/simplecov/source_file.rb | 10 ++++++++-- test/helper.rb | 17 ++++++++++++++++- test/test_source_file.rb | 22 +++++++++++++++++++++- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/lib/simplecov/source_file.rb b/lib/simplecov/source_file.rb index 5fb702c8..ae55182e 100644 --- a/lib/simplecov/source_file.rb +++ b/lib/simplecov/source_file.rb @@ -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 diff --git a/test/helper.rb b/test/helper.rb index aac2662b..487a3b61 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -18,4 +18,19 @@ def default_test end require 'shoulda_macros' -Test::Unit::TestCase.send :extend, ShouldaMacros \ No newline at end of file +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 diff --git a/test/test_source_file.rb b/test/test_source_file.rb index 8af50fe8..675a7e80 100644 --- a/test/test_source_file.rb +++ b/test/test_source_file.rb @@ -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 @@ -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