From a49b9300b0ec8652a837004d9186735d135a7f25 Mon Sep 17 00:00:00 2001 From: Mihai Parv Date: Wed, 4 May 2016 15:53:18 +0300 Subject: [PATCH 1/2] Fix for Corrupted cobertura file format #196 - added pattern to match line numbers when llvm-cov output includes thousands as 25.3k and millions as 3.8M --- lib/slather/profdata_coverage_file.rb | 11 +++++++++++ spec/slather/profdata_coverage_spec.rb | 10 +++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/slather/profdata_coverage_file.rb b/lib/slather/profdata_coverage_file.rb index 6e30d348..0bfca2f0 100644 --- a/lib/slather/profdata_coverage_file.rb +++ b/lib/slather/profdata_coverage_file.rb @@ -61,6 +61,17 @@ def line_number_in_line(line) when /[0-9]+/ return match.to_i end + else + # llvm-cov outputs hit counts as 25.3k or 3.8M, so check this pattern as well + did_match = line =~ /^(\s*)(\d+\.\d+)(k|M)\|(\s*)(\d+)\|/ + + if did_match + match = $5.strip + case match + when /[0-9]+/ + return match.to_i + end + end end 0 end diff --git a/spec/slather/profdata_coverage_spec.rb b/spec/slather/profdata_coverage_spec.rb index 09f86baa..a33df457 100644 --- a/spec/slather/profdata_coverage_spec.rb +++ b/spec/slather/profdata_coverage_spec.rb @@ -70,9 +70,17 @@ end describe "#line_number_in_line" do - it "should return the correct line number" do + it "should return the correct line number for coverage represented as decimals" do expect(profdata_coverage_file.line_number_in_line(" 0| 40| func applicationWillTerminate(application: UIApplication) {")).to eq(40) end + + it "should return the correct line number for coverage represented as thousands" do + expect(profdata_coverage_file.line_number_in_line(" 11.8k| 41| func applicationWillTerminate(application: UIApplication) {")).to eq(41) + end + + it "should return the correct line number for coverage represented as milions" do + expect(profdata_coverage_file.line_number_in_line(" 2.58M| 42| func applicationWillTerminate(application: UIApplication) {")).to eq(42) + end end describe "#coverage_for_line" do From af7721127f667273e24cde95911d62e0b813c06b Mon Sep 17 00:00:00 2001 From: Mihai Parv Date: Thu, 5 May 2016 09:51:08 +0300 Subject: [PATCH 2/2] Updated change log for #202 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a016265c..fed8d11f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master +* Fix for correct line number for lines that are hit thousands or millions of time in llvm-cov. + [Mihai Parv](https://github.com/mihaiparv) + [#202](https://github.com/SlatherOrg/slather/pull/202), [#196](https://github.com/SlatherOrg/slather/issues/196) + * Generate coverate for multiple binaries by passing multiple `--binary-basename` or `--binary-file` arguments, or by using an array in `.slather.yml` [Kent Sutherland](https://github.com/ksuther) [#188](https://github.com/SlatherOrg/slather/pull/188)