Add Mutant::LineTrace
* Depends on `TracePoint` thus removes 1.9 compatiblity. I do not expect someone is harmed by this.
This commit is contained in:
parent
6f30dbcb39
commit
75164ba31a
7 changed files with 76 additions and 3 deletions
|
@ -3,7 +3,6 @@ script: "bundle exec rake ci"
|
|||
env:
|
||||
- TRAVIS=true
|
||||
rvm:
|
||||
- 1.9.3
|
||||
- 2.0.0
|
||||
- 2.1.4
|
||||
- rbx-2
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
---
|
||||
threshold: 18
|
||||
total_score: 1148
|
||||
total_score: 1161
|
||||
|
|
|
@ -37,6 +37,7 @@ FeatureEnvy:
|
|||
- Mutant::Runner::Master#stop_worker
|
||||
- Mutant::Runner::Worker#run_mutation
|
||||
- Mutant::Runner::Worker#handle
|
||||
- Mutant::Subject#source_lines
|
||||
IrresponsibleModule:
|
||||
enabled: true
|
||||
exclude: []
|
||||
|
|
|
@ -211,6 +211,7 @@ require 'mutant/reporter/cli'
|
|||
require 'mutant/reporter/cli/printer'
|
||||
require 'mutant/reporter/cli/tput'
|
||||
require 'mutant/reporter/cli/format'
|
||||
require 'mutant/line_trace'
|
||||
require 'mutant/zombifier'
|
||||
require 'mutant/zombifier/file'
|
||||
|
||||
|
|
34
lib/mutant/line_trace.rb
Normal file
34
lib/mutant/line_trace.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Mutant
|
||||
# Line tracer
|
||||
class LineTrace
|
||||
include Adamantium::Flat, Concord.new(:contents)
|
||||
|
||||
private_class_method :new
|
||||
|
||||
# Test if trace coveres file at lineno
|
||||
#
|
||||
# @param [String] file
|
||||
# @param [Fixnum] lineno
|
||||
#
|
||||
# @return [Boolean]
|
||||
#
|
||||
def cover?(file, lineno)
|
||||
contents.fetch(file) { return false }.include?(lineno)
|
||||
end
|
||||
|
||||
# Run block
|
||||
#
|
||||
# @return [Traces]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def self.call(&block)
|
||||
traces = Hash.new { |hash, file| hash[file] = Set.new }
|
||||
TracePoint.trace(:return, :line) do |point|
|
||||
traces[point.path] << point.lineno
|
||||
end.tap(&block).disable
|
||||
new(IceNine.deep_freeze(traces))
|
||||
end
|
||||
|
||||
end # LineTrace
|
||||
end # Mutant
|
|
@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
|
|||
gem.extra_rdoc_files = %w[TODO LICENSE]
|
||||
gem.executables = %w[mutant]
|
||||
|
||||
gem.required_ruby_version = '>= 1.9.3'
|
||||
gem.required_ruby_version = '>= 2.0.0'
|
||||
|
||||
gem.add_runtime_dependency('parser', '~> 2.2.pre.7')
|
||||
gem.add_runtime_dependency('ast', '~> 2.0')
|
||||
|
|
38
spec/unit/mutant/line_trace_spec.rb
Normal file
38
spec/unit/mutant/line_trace_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
RSpec.describe Mutant::LineTrace do
|
||||
let(:object) { described_class }
|
||||
|
||||
test_a_line = __LINE__ + 2
|
||||
def test_a
|
||||
test_b
|
||||
end
|
||||
|
||||
test_b_line = __LINE__ + 2
|
||||
def test_b
|
||||
end
|
||||
|
||||
test_c_line = __LINE__ + 2
|
||||
def test_c
|
||||
end
|
||||
|
||||
shared_examples_for 'line trace' do
|
||||
it 'returns correct trace results' do
|
||||
expect(subject.cover?(__FILE__, test_a_line)).to be(true)
|
||||
expect(subject.cover?(__FILE__, test_b_line)).to be(true)
|
||||
expect(subject.cover?(__FILE__, test_c_line)).to be(false)
|
||||
expect(subject.cover?(__FILE__, __LINE__)).to be(false)
|
||||
expect(subject.cover?('/dev/null', test_a_line)).to be(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.cover?' do
|
||||
subject { object.call { test_a } }
|
||||
|
||||
include_examples 'line trace'
|
||||
end
|
||||
|
||||
describe '.call' do
|
||||
subject { object.call { test_a } }
|
||||
|
||||
include_examples 'line trace'
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue