Skip to content

Commit

Permalink
Compatability with BINARY internal encoding
Browse files Browse the repository at this point in the history
- Specify the default_internal encoding as UTF-8 when reading source
  files. This fixes Issue #127.
  • Loading branch information
justfalter committed Feb 4, 2013
1 parent 4afc355 commit b9d689f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/simplecov/source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def status

def initialize(filename, coverage)
@filename, @coverage = filename, coverage
File.open(filename, "r:UTF-8") {|f| @src = f.readlines }
File.open(filename, "r:UTF-8:UTF-8") {|f| @src = f.readlines }
end

# Returns all source lines for this file as instances of SimpleCov::SourceFile::Line,
Expand Down
14 changes: 14 additions & 0 deletions test/test_source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ class TestSourceFile < Test::Unit::TestCase
source_file.process_skipped_lines!
end
end

should "handle utf-8 encoded source files when the default_internal encoding is binary" do
original_internal_encoding = Encoding.default_internal
Encoding.default_internal = "BINARY"
begin
source_file = SimpleCov::SourceFile.new(source_fixture('utf-8.rb'), [nil, nil, 1])
ensure
Encoding.default_internal = original_internal_encoding
end

assert_nothing_raised do
source_file.process_skipped_lines!
end
end
end

end
Expand Down

0 comments on commit b9d689f

Please sign in to comment.