module Minitest::CoverageRunner
Constants
- PWD
- VERSION
Public Class Methods
Source
# File lib/minitest/coverage.rb, line 7 def self.coverage_baseline @@coverage_baseline end
Source
# File lib/minitest/coverage.rb, line 11 def self.coverage_baseline= o @@coverage_baseline = o end
Source
# File lib/minitest/coverage.rb, line 19 def self.coverage_data @@coverage_data end
Source
# File lib/minitest/coverage.rb, line 23 def self.coverage_data= o @@coverage_data = o end
Source
# File lib/minitest/coverage.rb, line 104 def output_coverage require "json" cleaned = coverage_data.reject { |path, lines| path.nil? or path.include? RbConfig::CONFIG["libdir"] or not path.start_with? PWD } File.open "coverage.json", "w" do |f| f.puts JSON.pretty_generate cleaned end warn "created coverage.json" end
Public Instance Methods
Source
# File lib/minitest/coverage.rb, line 37 def clean_path path path[Dir.pwd.length+1..-1] end
Source
# File lib/minitest/coverage.rb, line 15 def coverage_baseline @@coverage_baseline end
Source
# File lib/minitest/coverage.rb, line 27 def coverage_data @@coverage_data end
Source
# File lib/minitest/coverage.rb, line 41 def coverage_diff test_name, new, old puts path, lines = find_path_and_lines(new, test_name) return unless path && lines old_lines = old[path] || lines.map { |x| x ? 0 : nil } print " #{clean_path path}" a, b, max = pct(old_lines), pct(lines), max(lines) if (a - b).abs < 0.01 then puts ": no change at %.1f%% of %d lines" % [a, max] else puts ": from %.1f%% to %.1f%% of %d lines" % [a, b, max] end end
Source
# File lib/minitest/coverage.rb, line 62 def find_path_and_lines coverage, test_name impl_re = /\/#{impl_name test_name}$/ coverage.sort.find { |path, lines| # sorting biases towards app and lib next unless path.start_with? PWD path =~ impl_re } end
Source
# File lib/minitest/coverage.rb, line 71 def impl_name test_name unless test_name then p :nil => [test_name, self.name] p caller abort end (test_name[/^([\w:]+?)Test/, 1] || # rails style test_name[/^Test([\w:]+)$/, 1] || # ruby style test_name). # give up gsub(/([a-z])([A-Z])/, '\1_\2'). gsub(/::/, "/"). downcase + "\\.rb" rescue => e p e p test_name p test_name[/^([\w:]+?)Test(?:::)?/, 1] raise e end
Source
# File lib/minitest/coverage.rb, line 94 def merge_coverage new_coverage path, lines = find_path_and_lines new_coverage, self.name if path and lines then coverage_data[path] = lines else # warn "Bad mapping for #{self.name}. Skipping coverage." # TODO end end
Source
# File lib/minitest/coverage.rb, line 122 def pct lines max = max lines n = max - lines.count(0) 100.0*n/max end
Source
# File lib/minitest/coverage.rb, line 128 def run *args return if self.runnable_methods.empty? unless impl_name self.name then warn "BAD NAME: #{self.name} -- can't map to implementation. Skipping" end puts puts "#{self.name}:" super new_coverage = Coverage.peek_result coverage_diff(self.name, new_coverage, coverage_data) merge_coverage new_coverage if Coverage.respond_to? :result= then Coverage.result = coverage_baseline else @@coverage_warning ||= false unless @@coverage_warning then warn "Unable to reset coverage baseline. Numbers will be artificially high." @@coverage_warning = true end end end
Calls superclass method