Skip to content
This repository

Encoding issues with iso-8859 encoded files #117

Merged
merged 2 commits into from almost 2 years ago

2 participants

Patrick Helm Christoph Olszowka
Patrick Helm

I had issues using simplecov with an file, that contained something like this:

# localized to Español thus:

Had no chance to edit this file, so I might provide a workaround here, so that simplecov can hande such files.

In one of my projects I use something like this for UTF-8 encoding:

def self.umlauts(text)
  # Read more: http://stackoverflow.com/questions/2982677/ruby-1-9-invalid-byte-sequence-in-utf-8
  # Switch to ruby 1.9 String#encode,  with backward 1.8 compatibility
  if text.respond_to?(:encode!)
    text.encode!('UTF-8', 'UTF-8', :invalid => :replace)
  else
    require 'iconv'
    text = Iconv.conv('ISO_8859-15//IGNORE//TRANSLIT', 'UTF-8', text)
  end
end
Christoph Olszowka colszowka merged commit 3d6554f into from May 10, 2012
Christoph Olszowka colszowka closed this May 10, 2012
Christoph Olszowka
Owner

Sorry I left this lying around for quite a while. Thanks for your effort, merged and will be released in the next version, hopefully today.

Patrick Helm
Deradon commented May 10, 2012

Thanks for your effort maintaining this repo.
I'm really glad to hava a code-coverage tool for ruby 1.9.2+ :)

Jonathan Perkin jperkin referenced this pull request from a commit in joyent/pkgsrc June 02, 2012
Update ruby-simplecov to 0.6.4.
v0.6.4, 2012-05-10 ([changes](colszowka/simplecov@v0.6.3...v0.6.4))
-------------------

  * [BUGFIX] Encoding issues with ISO-8859-encoded source files fixed.
    See colszowka/simplecov#117. (thanks to @Deradon)
  * [BUGFIX] Ensure ZeroDivisionErrors won't occur when calculating the coverage result, which previously
    could happen in certain cases. See colszowka/simplecov#128. (thanks to @japgolly)
  * [REFACTORING] Changed a couple instance variable lookups so SimpleCov does not cause a lot of warnings when
    running ruby at a higher warning level. See colszowka/simplecov#106 and
    colszowka/simplecov#119. (thanks to @mvz and @gioele)


v0.6.3, 2012-05-10 ([changes](colszowka/simplecov@v0.6.2...v0.6.3))
-------------------

  * [BUGFIX] Modified the API-changes for newer multi_json versions introduced with #122 and v0.6.2 so
    they are backwards-compatible with older multi_json gems in order to avoid simplecov polluting
    the multi_json minimum version requirement for entire applications.
    See colszowka/simplecov#132
  * Added appraisal gem to the test setup in order to run the test suite against both 1.0 and 1.3
    multi_json gems and ensure the above actually works :)
0410186
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  lib/simplecov/source_file.rb
@@ -30,6 +30,7 @@ def initialize(src, line_number, coverage)
30 30
         raise ArgumentError, "Only Fixnum and nil accepted for coverage" unless coverage.kind_of?(Fixnum) or coverage.nil?
31 31
         @src, @line_number, @coverage = src, line_number, coverage
32 32
         @skipped = false
  33
+        @src.encode!('UTF-8', 'UTF-8', :invalid => :replace) if @src.respond_to?(:encode!)
33 34
       end
34 35
 
35 36
       # Returns true if this is a line that should have been covered, but was not
@@ -172,3 +173,4 @@ def round_float(float, places)
172 173
     end
173 174
   end
174 175
 end
  176
+
3  test/fixtures/iso-8859.rb
... ...
@@ -0,0 +1,3 @@
  1
+
  2
+# localized to Español thus:
  3
+
9  test/test_source_file.rb
@@ -80,7 +80,16 @@ class TestSourceFile < Test::Unit::TestCase
80 80
           source_file.process_skipped_lines!
81 81
         end
82 82
       end
  83
+
  84
+      should "handle iso-8859 encoded source files" do
  85
+        source_file = SimpleCov::SourceFile.new(source_fixture('iso-8859.rb'), [nil, nil, 1])
  86
+
  87
+        assert_nothing_raised do
  88
+          source_file.process_skipped_lines!
  89
+        end
  90
+      end
83 91
     end
84 92
 
85 93
   end
86 94
 end
  95
+
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.