Skip to content

Commit

Permalink
Merge pull request #12 from viteinfinite/feature-re-encode-develop
Browse files Browse the repository at this point in the history
Re-encode llvm-cov output to prevent potential "invalid byte sequence" issue
  • Loading branch information
viteinfinite committed Dec 17, 2015
2 parents 57c8850 + c05b0c0 commit ad9b9eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/slather/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def binary_file_for_static_lib(xctest_bundle_file)
Dir["#{xctest_bundle_file}/**/#{xctest_bundle_file_name_noext}"].first
end

def profdata_llvm_cov_output
def unsafe_profdata_llvm_cov_output
profdata_coverage_dir = self.profdata_coverage_dir
binary_file_arg = binary_file

Expand All @@ -168,9 +168,15 @@ def profdata_llvm_cov_output
puts "\nProcessing coverage file: #{profdata_file_arg}"
puts "Against binary file: #{binary_file_arg}\n\n"


llvm_cov_args = %W(show -instr-profile #{profdata_file_arg} #{binary_file_arg})
`xcrun llvm-cov #{llvm_cov_args.shelljoin}`
end
private :unsafe_profdata_llvm_cov_output

def profdata_llvm_cov_output
unsafe_profdata_llvm_cov_output.encode!('UTF-8', 'binary', :invalid => :replace, undef: :replace)
end
private :profdata_llvm_cov_output

def dedupe(coverage_files)
Expand Down
15 changes: 15 additions & 0 deletions spec/slather/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ class SpecXcode7CoverageFile < Slather::ProfdataCoverageFile
end
end

describe "#invalid_characters" do
it "should correctly encode invalid characters" do
fixtures_project.stub(:input_format).and_return("profdata")
fixtures_project.stub(:ignore_list).and_return([])
Dir.stub(:[]).with("#{fixtures_project.build_directory}/**/Coverage.profdata").and_return(["/some/path/Coverage.profdata"])
fixtures_project.stub(:unsafe_profdata_llvm_cov_output).and_return("#{FIXTURES_SWIFT_FILE_PATH}:
1| 8| func application(application: \255, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1| 9| return true
0| 14|}")
fixtures_project.extend(Slather::CoverageService::HtmlOutput)
profdata_coverage_files = fixtures_project.send(:profdata_coverage_files)
expect(profdata_coverage_files.count).to eq(1)
end
end

describe "#binary_file" do

let(:build_directory) do
Expand Down

0 comments on commit ad9b9eb

Please sign in to comment.