Class: AbideDevUtils::CEM::Generate::CoverageReport::OldReport

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/cem/generate/coverage_report.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(benchmarks) ⇒ OldReport

Returns a new instance of OldReport.



151
152
153
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 151

def initialize(benchmarks)
  @benchmarks = benchmarks
end

Class Method Details

.class_valid?(manifest_path) ⇒ Boolean

Returns:

  • (Boolean)


214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 214

def self.class_valid?(manifest_path)
  compiler = Puppet::Pal::Compiler.new(nil)
  ast = compiler.parse_file(manifest_path)
  ast.body.body.statements.each do |s|
    next unless s.respond_to?(:arguments)
    next unless s.arguments.respond_to?(:each)

    s.arguments.each do |i|
      return false if i.value == 'Not implemented'
    end
  end
  true
end

.find_invalid_classes(all_cap) ⇒ Object



206
207
208
209
210
211
212
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 206

def self.find_invalid_classes(all_cap)
  invalid_classes = []
  all_cap.each do |cap|
    invalid_classes << cap[0] unless class_valid?(cap[1])
  end
  invalid_classes
end

.find_valid_classes(all_cap, invalid_classes) ⇒ Object



197
198
199
200
201
202
203
204
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 197

def self.find_valid_classes(all_cap, invalid_classes)
  all_classes = all_cap.dup.transpose[0]
  return [] if all_classes.nil?

  return all_classes - invalid_classes unless invalid_classes.nil?

  all_classes
end

.generateObject



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 155

def self.generate
  coverage = {}
  coverage['classes'] = {}
  all_cap = ClassUtils.find_all_classes_and_paths(puppet_class_dir)
  invalid_classes = find_invalid_classes(all_cap)
  valid_classes = find_valid_classes(all_cap, invalid_classes)
  coverage['classes']['invalid'] = invalid_classes
  coverage['classes']['valid'] = valid_classes
  hiera = YAML.safe_load(File.open(hiera_path))
  profile&.gsub!(/^profile_/, '') unless profile.nil?

  matcher = profile.nil? ? /^profile_/ : /^profile_#{profile}/
  hiera.each do |k, v|
    key_base = k.split('::')[-1]
    coverage['benchmark'] = v if key_base == 'title'
    next unless key_base.match?(matcher)

    coverage[key_base] = generate_uncovered_data(v, valid_classes)
  end
  coverage
end

.generate_uncovered_data(ctrl_list, valid_classes) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/abide_dev_utils/cem/generate/coverage_report.rb', line 177

def self.generate_uncovered_data(ctrl_list, valid_classes)
  out_hash = {}
  out_hash[:num_total] = ctrl_list.length
  out_hash[:uncovered] = []
  out_hash[:covered] = []
  ctrl_list.each do |c|
    if valid_classes.include?(c)
      out_hash[:covered] << c
    else
      out_hash[:uncovered] << c
    end
  end
  out_hash[:num_covered] = out_hash[:covered].length
  out_hash[:num_uncovered] = out_hash[:uncovered].length
  out_hash[:coverage] = Float(
    (Float(out_hash[:num_covered]) / Float(out_hash[:num_total])) * 100.0
  ).floor(3)
  out_hash
end