lib/covered/source.rb in covered-0.7.0 vs lib/covered/source.rb in covered-0.8.0

- old
+ new

@@ -21,10 +21,12 @@ require_relative 'eval' require_relative 'wrapper' require 'thread' +require 'parser/current' + module Covered # The source map, loads the source file, parses the AST to generate which lines contain executable code. class Source < Wrapper EXECUTABLE = /(.?CALL|.VAR|.ASGN|DEFN)/.freeze @@ -68,26 +70,25 @@ @paths[filename] = string end end def executable?(node) - node.type.to_s =~ @executable + node.type == :send end def ignore?(node) - # NODE_ARGS Ruby doesn't report execution of arguments in :line tracepoint. - node.nil? or node.type.to_s =~ @ignore + node.nil? or node.type == :arg end def expand(node, coverage, level = 0) - if node.is_a? RubyVM::AbstractSyntaxTree::Node + if node.is_a? Parser::AST::Node if ignore?(node) - coverage.annotate(node.first_lineno, "ignoring #{node.type}") + coverage.annotate(node.location.line, "ignoring #{node.type}") else if executable?(node) # coverage.annotate(node.first_lineno, "executable #{node.type}") - coverage.counts[node.first_lineno] ||= 0 + coverage.counts[node.location.line] ||= 0 else # coverage.annotate(node.first_lineno, "not executable #{node.type}") end expand(node.children, coverage, level + 1) @@ -101,12 +102,12 @@ end end def parse(path) if source = @paths[path] - RubyVM::AbstractSyntaxTree.parse(source) + Parser::CurrentRuby.parse(source) elsif File.exist?(path) - RubyVM::AbstractSyntaxTree.parse_file(path) + Parser::CurrentRuby.parse_file(path) else warn "Couldn't parse #{path}, file doesn't exist?" end end