Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Encoding issues with iso-8859 encoded files #117

Merged
merged 2 commits into from

2 participants

@Deradon

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
@colszowka colszowka was assigned
@colszowka colszowka merged commit 3d6554f into colszowka:master
@colszowka
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.

@Deradon

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

@jperkin jperkin referenced this pull request from a commit in joyent/pkgsrc
taca 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
@jsonn jsonn referenced this pull request from a commit in jsonn/pkgsrc
taca 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 :)
93cae9a
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.
View
2  lib/simplecov/source_file.rb
@@ -30,6 +30,7 @@ def initialize(src, line_number, coverage)
raise ArgumentError, "Only Fixnum and nil accepted for coverage" unless coverage.kind_of?(Fixnum) or coverage.nil?
@src, @line_number, @coverage = src, line_number, coverage
@skipped = false
+ @src.encode!('UTF-8', 'UTF-8', :invalid => :replace) if @src.respond_to?(:encode!)
end
# Returns true if this is a line that should have been covered, but was not
@@ -172,3 +173,4 @@ def round_float(float, places)
end
end
end
+
View
3  test/fixtures/iso-8859.rb
@@ -0,0 +1,3 @@
+
+# localized to Español thus:
+
View
9 test/test_source_file.rb
@@ -80,7 +80,16 @@ class TestSourceFile < Test::Unit::TestCase
source_file.process_skipped_lines!
end
end
+
+ should "handle iso-8859 encoded source files" do
+ source_file = SimpleCov::SourceFile.new(source_fixture('iso-8859.rb'), [nil, nil, 1])
+
+ assert_nothing_raised do
+ source_file.process_skipped_lines!
+ end
+ end
end
end
end
+
Something went wrong with that request. Please try again.