Class: Rcov::FullTextReport

Inherits:
BaseFormatter show all
Defined in:
lib/rcov/formatters/full_text_report.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_OPTS =
{:textmode => :coverage}

Instance Method Summary collapse

Methods inherited from BaseFormatter

#add_file, #code_coverage, #each_file_pair_sorted, #mangle_filename, #normalize_filename, #num_code_lines, #num_lines, #sorted_file_pairs, #total_coverage

Constructor Details

#initialize(opts = {}) ⇒ FullTextReport

Returns a new instance of FullTextReport.



5
6
7
8
9
10
# File 'lib/rcov/formatters/full_text_report.rb', line 5

def initialize(opts = {})
  options = DEFAULT_OPTS.clone.update(opts)
  @textmode = options[:textmode]
  @color = options[:color]
  super(options)
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rcov/formatters/full_text_report.rb', line 12

def execute
  each_file_pair_sorted do |filename, fileinfo|
    puts "=" * 80
    puts filename
    puts "=" * 80
    lines = SCRIPT_LINES__[filename]

    unless lines
      # try to get the source code from the global code coverage
      # analyzer
      re = /#{Regexp.escape(filename)}\z/
      if $rcov_code_coverage_analyzer and
        (data = $rcov_code_coverage_analyzer.data_matching(re))
        lines = data[0]
      end
    end

    (lines || []).each_with_index do |line, i|
      case @textmode
      when :counts
        puts "%-70s| %6d" % [line.chomp[0,70], fileinfo.counts[i]]
      when :gcc
        puts "%s:%d:%s" % [filename, i+1, line.chomp] unless fileinfo.coverage[i]
      when :coverage
        if @color
          prefix = fileinfo.coverage[i] ? "\e[32;40m" : "\e[31;40m"
          puts "#{prefix}%s\e[37;40m" % line.chomp
        else
          prefix = fileinfo.coverage[i] ? "   " : "!! "
          puts "#{prefix}#{line}"
        end
      end
    end
  end
end