free_mutant/lib/mutant/line_trace.rb
Markus Schirp 75164ba31a Add Mutant::LineTrace
* Depends on `TracePoint` thus removes 1.9 compatiblity.
  I do not expect someone is harmed by this.
2014-12-07 21:05:49 +00:00

34 lines
739 B
Ruby

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