diff --git a/lib/simplecov/source_file.rb b/lib/simplecov/source_file.rb index 428f0972..6fa8d74d 100644 --- a/lib/simplecov/source_file.rb +++ b/lib/simplecov/source_file.rb @@ -77,7 +77,8 @@ def status alias_method :source, :src def initialize(filename, coverage) - @filename, @coverage, @src = filename, coverage, File.readlines(filename) + @filename, @coverage = filename, coverage + File.open(filename, "r:UTF-8") {|f| @src = f.readlines } end # Returns all source lines for this file as instances of SimpleCov::SourceFile::Line, diff --git a/test/fixtures/utf-8.rb b/test/fixtures/utf-8.rb new file mode 100644 index 00000000..7afa3501 --- /dev/null +++ b/test/fixtures/utf-8.rb @@ -0,0 +1,3 @@ +# encoding: utf-8 + +puts '135°C' diff --git a/test/test_source_file.rb b/test/test_source_file.rb index d66eea55..0689d33a 100644 --- a/test/test_source_file.rb +++ b/test/test_source_file.rb @@ -71,5 +71,16 @@ class TestSourceFile < Test::Unit::TestCase assert_match /^Warning: coverage data provided/, captured_output end end + + context "Encoding" do + should "handle utf-8 encoded source files" do + source_file = SimpleCov::SourceFile.new(source_fixture('utf-8.rb'), [nil, nil, 1]) + + assert_nothing_raised do + source_file.process_skipped_lines! + end + end + end + end end