Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into optimize_performanc…
Browse files Browse the repository at this point in the history
…e_for_many_binaries
  • Loading branch information
cltnschlosser committed Apr 22, 2020
2 parents b3598e6 + 985ff0a commit f2b61c4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/slather/profdata_coverage_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ def source_file
end

def source_code_lines
self.source.split("\n")[(path_on_first_line? ? 1 : 0)..-1]
lines = self.source.split("\n")[(path_on_first_line? ? 1 : 0)..-1]
ignore_error_lines(lines)
end

def ignore_error_lines(lines, line_numbers_first = self.line_numbers_first)
if line_numbers_first
lines.reject { |line| line.lstrip.start_with?('|', '--') }
else
lines
end
end

def source_data
Expand Down
21 changes: 21 additions & 0 deletions spec/slather/profdata_coverage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@
end
end

describe '#ignore_error_lines' do
it 'should ignore lines starting with - when line_numbers_first is true' do
expect(profdata_coverage_file.ignore_error_lines(['--------'], true)).to eq([])
expect(profdata_coverage_file.ignore_error_lines(['--------', 'not ignored'], true)).to eq(['not ignored'])
end

it 'should ignore lines starting with | when line_numbers_first is true' do
expect(profdata_coverage_file.ignore_error_lines(['| Unexecuted instantiation'], true)).to eq([])
expect(profdata_coverage_file.ignore_error_lines(['| Unexecuted instantiation', 'not ignored'], true)).to eq(['not ignored'])
end

it 'should not ignore any lines when line_numbers_first is false' do
lines = ['| Unexecuted instantiation', '------']
expect(profdata_coverage_file.ignore_error_lines(lines, false)).to eq(lines)
end
end

describe "#coverage_for_line" do
it "should return the number of hits for the line" do
expect(profdata_coverage_file.coverage_for_line(" 10| 40| func applicationWillTerminate(application: UIApplication) {", false)).to eq(10)
Expand All @@ -116,6 +133,10 @@
expect(profdata_coverage_file.coverage_for_line(" 18| 11.8k| return a + b;", true)).to eq(11800)
expect(profdata_coverage_file.coverage_for_line(" 18| 2.58M| return a + b;", true)).to eq(2580000)
end

it 'should ignore errors in profdata' do
expect(profdata_coverage_file.coverage_for_line('------------------', true)).to eq(nil)
end
end

describe "#num_lines_tested" do
Expand Down

0 comments on commit f2b61c4

Please sign in to comment.