Skip to content

Commit

Permalink
Merge pull request #179 from ksuther/thousands-and-millions
Browse files Browse the repository at this point in the history
Support thousands and millions of hit lines with llvm-cov.
  • Loading branch information
neonichu committed Apr 5, 2016
2 parents 8f677fd + 3d5537c commit 0279138
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
[Boris Bügling](https://github.com/neonichu)
[#180](https://github.com/SlatherOrg/slather/pull/180)

* Show lines that are hit thousands or millions of time in llvm-cov
[Kent Sutherland](https://github.com/ksuther)
[#179](https://github.com/SlatherOrg/slather/pull/179)

## v2.0.2

* Escape the link to file names properly
Expand Down
30 changes: 20 additions & 10 deletions lib/slather/profdata_coverage_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,27 @@ def coverage_for_line(line)
line =~ /^(\s*)(\d*)\|/

if $2 == nil
return nil
end
# Check for thousands or millions (llvm-cov outputs hit counts as 25.3k or 3.8M)
did_match = line =~ /^(\s*)(\d+\.\d+)(k|M)\|/

if did_match
count = $2.strip
units = $3 == 'k' ? 1000 : 1000000

match = $2.strip
case match
when /[0-9]+/
match.to_i
when /#+/
0
when "-"
nil
count.to_f * units
else
return nil
end
else
match = $2.strip
case match
when /[0-9]+/
match.to_i
when /#+/
0
when "-"
nil
end
end
end

Expand Down
12 changes: 12 additions & 0 deletions spec/slather/profdata_coverage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@
it "should return the number of hits for the line" do
expect(profdata_coverage_file.coverage_for_line(" 10| 40| func applicationWillTerminate(application: UIApplication) {")).to eq(10)
end

it "should return the number of hits for a line in thousands" do
expect(profdata_coverage_file.coverage_for_line(" 11.8k| 49| return result;")).to eq(11800)
end

it "should return the number of hits for a line in millions" do
expect(profdata_coverage_file.coverage_for_line(" 2.58M| 49| return result;")).to eq(2580000)
end

it "should return the number of hits for an uncovered line" do
expect(profdata_coverage_file.coverage_for_line(" 0| 49| return result;")).to eq(0)
end
end

describe "#num_lines_tested" do
Expand Down

0 comments on commit 0279138

Please sign in to comment.