Class: Rake::Coverage::Summarizer

Inherits:
Object
  • Object
show all
Defined in:
lib/test/rake/coverage_summary.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trace_log, output_dir, index_template, page_template) ⇒ Summarizer

Returns a new instance of Summarizer.



12
13
14
15
16
17
# File 'lib/test/rake/coverage_summary.rb', line 12

def initialize( trace_log, output_dir, index_template, page_template )
  @trace_log = trace_log
  @output_dir = output_dir
  @index_template = index_template
  @page_template = page_template
end

Instance Attribute Details

#index_templateObject

Returns the value of attribute index_template.



10
11
12
# File 'lib/test/rake/coverage_summary.rb', line 10

def index_template
  @index_template
end

#output_dirObject

Returns the value of attribute output_dir.



10
11
12
# File 'lib/test/rake/coverage_summary.rb', line 10

def output_dir
  @output_dir
end

#page_templateObject

Returns the value of attribute page_template.



10
11
12
# File 'lib/test/rake/coverage_summary.rb', line 10

def page_template
  @page_template
end

#trace_logObject

Returns the value of attribute trace_log.



10
11
12
# File 'lib/test/rake/coverage_summary.rb', line 10

def trace_log
  @trace_log
end

Instance Method Details

#summarizeObject



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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/test/rake/coverage_summary.rb', line 19

def summarize()
  raise "@trace_log must be set" if @trace_log.nil?
  raise "@output_dir must be set" if @output_dir.nil?

  # stdout.printf("#%d:%s:%d:%s:%s: %s",
  #    get_thread_no,
  #    file,
  #    line,
  #    klass || '',
  #    EVENT_SYMBOL[event],
  #    get_line(file, line))

  puts "Reading trace data #{@trace_log}..."
  files = {}
  File.open( @trace_log, "r" ).each_line do |line|
    data, linedump = line.split(/ /)
    threadno, file, n, classname, eventsym = data.split(/:/)
    files[file] ||= []
    files[file][n.to_i] ||= 0
    files[file][n.to_i] += 1
  end

  page_tmpl = File.read( @page_template )
  index_tmpl = File.read( @index_template )
  
  puts "Outputting to #{@output_dir}..."
  mkdir_p( @output_dir )
  summary = {}
  files.each do |file, linelist|
    s = Summary.new( file )
    lineno = 0
    File.open( file ).each_line do |line|
      lineno += 1
      seen_this = false
      # basic: line was traced
      unless linelist[lineno].nil?
        seen_this = true
      end
      # misc: various comments, blank lines, other "untraceables"
      #  mark them as seen
      if line =~ /^\s*$/
        seen_this = true
      end
      if line =~ /^\s*#/
        seen_this = true
      end
      if line =~ /^\s*(require|class|module|end|else|include|def)/
        seen_this = true
      end
      if line =~ /^\s*(attr_)/
        seen_this = true
      end
      if line =~ /^\s*(private|protected|public)*\s$/
        seen_this = true
      end
      s.seen << seen_this
      if seen_this
        s.covered_lines += 1
      end
      s.total_lines +=1
      s.lines << line
    end
    summary[file] = s
    raise "XXX" if s.nil?
    pretty( page_tmpl, summary[file] )
  end
  index( index_tmpl, summary )
end