Class: AbideDevUtils::Sce::Generate::CoverageReport::OldReport
- Inherits:
-
Object
- Object
- AbideDevUtils::Sce::Generate::CoverageReport::OldReport
- Defined in:
- lib/abide_dev_utils/sce/generate/coverage_report.rb
Class Method Summary collapse
- .class_valid?(manifest_path) ⇒ Boolean
- .find_invalid_classes(all_cap) ⇒ Object
- .find_valid_classes(all_cap, invalid_classes) ⇒ Object
- .generate ⇒ Object
- .generate_uncovered_data(ctrl_list, valid_classes) ⇒ Object
Instance Method Summary collapse
-
#initialize(benchmarks) ⇒ OldReport
constructor
A new instance of OldReport.
Constructor Details
#initialize(benchmarks) ⇒ OldReport
Returns a new instance of OldReport.
154 155 156 |
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 154 def initialize(benchmarks) @benchmarks = benchmarks end |
Class Method Details
.class_valid?(manifest_path) ⇒ Boolean
217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 217 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
209 210 211 212 213 214 215 |
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 209 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
200 201 202 203 204 205 206 207 |
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 200 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 |
.generate ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 158 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
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/abide_dev_utils/sce/generate/coverage_report.rb', line 180 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 |