Class: CodeCoverageAction

Inherits:
BuildAction show all
Includes:
LOCCountModule
Defined in:
lib/kwala/actions/code_coverage.rb

Overview

run with ./kwala -p TestProj -d ~/projects/TestProj -a code_coverage -o ~/tmp/builder

Direct Known Subclasses

AggregateCodeCoverageAction

Defined Under Namespace

Classes: CodeCoverageFileData

Constant Summary collapse

RCOV =
'/usr/bin/env rcov'
SUMMARY_COUNT =
30
PERCENT_ERROR =
70
PERCENT_WARNING =
90
DEBUG =
false

Instance Method Summary collapse

Methods included from LOCCountModule

#count_loc

Methods inherited from BuildAction

command_line_action_name, command_line_action_names, create_action_from_command_line_name, detailed_template_file, #score, summary_template_file

Methods included from InheritanceTracker

#get_implementors

Constructor Details

#initializeCodeCoverageAction

Returns a new instance of CodeCoverageAction.



64
65
66
# File 'lib/kwala/actions/code_coverage.rb', line 64

def initialize
  @output_data = Array.new
end

Instance Method Details

#build_action(context) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/kwala/actions/code_coverage.rb', line 68

def build_action(context)
  @ouput_dir = File.expand_path(context.output_directory)
  if !File.exists?("#{@ouput_dir}/coverage")
    FileUtils.mkdir("#{@ouput_dir}/coverage")
  end

  @test_cases_count = context.test_files.size

  run_test_cases(context)

  context.ruby_files.each do |ruby_file|
    test_path = test_index_path(context, ruby_file)
    rcov_index = test_path + "index.html"
    file_cov_path = test_path + file_coverage_filename(context, ruby_file)
    loc = count_loc(ruby_file).first
    if File.exist?(test_path)
      percent = parse_coverage_file(file_cov_path)
      @output_data << CodeCoverageFileData.new(ruby_file, percent,
                                               rcov_index, file_cov_path, loc)
    else
      @output_data << CodeCoverageFileData.new(ruby_file, nil, rcov_index,
                                               file_cov_path, loc)
    end
  end

end

#detailed_display(context) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
# File 'lib/kwala/actions/code_coverage.rb', line 124

def detailed_display(context)
  template = TemplateFile.new(self.class.detailed_template_file)

  context.amrita_data[:code_coverage_details] = {
    :entry =>  entries(@output_data)
  }

  det_res = ProjectBuilderUtils.expand_template(template, context.amrita_data)
  det_file = "#{context.output_directory}/#{context.project_name}_code_coverage.html"
  [det_file, det_res]
end

#summary_display(context) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/kwala/actions/code_coverage.rb', line 96

def summary_display(context)
  template = TemplateFile.new(self.class.summary_template_file)
  unit_base = "#{context.project_name}_code_coverage.html"

  cov_loc_weighted_sum = @output_data.inject(0) do |sum, file_data|
    sum + (file_data.percent.to_i * file_data.loc)
  end
  loc_sum = @output_data.inject(0){|sum, file_data| sum + file_data.loc}

  global_cov = cov_loc_weighted_sum / loc_sum

  context.amrita_data[:code_coverage_results] = {
    :c_num => @test_cases_count,
    :global_cov => global_cov
  }

  output_summary = @output_data.sort do |x, y|
    non_covered_loc(y) <=> non_covered_loc(x)
  end
  context.amrita_data[:code_coverage_summary] = {
    :entry =>  entries(output_summary[0..SUMMARY_COUNT])
  }

  context.amrita_data[:code_coverage_details] =
   (Amrita::e(:a, :href => unit_base) { "Code Coverage Details" })
  summary_expand(template, context)
end