|
| 1 | +#!/usr/bin/env ruby |
| 2 | +# vim: set sw=2 sts=2 et tw=80 : |
| 3 | +require 'rspec' |
| 4 | +require 'pry' |
| 5 | + |
| 6 | +#XXX Super ugly hack to keep from starting beaker nodes |
| 7 | +module Kernel |
| 8 | + # make an alias of the original require |
| 9 | + alias_method :original_require, :require |
| 10 | + # rewrite require |
| 11 | + def require name |
| 12 | + original_require name if name != 'spec_helper_acceptance' |
| 13 | + end |
| 14 | +end |
| 15 | +UNSUPPORTED_PLATFORMS = [] |
| 16 | +def fact(*args) [] end |
| 17 | +#XXX End hax |
| 18 | + |
| 19 | +# Get a list of functions for test coverage |
| 20 | +function_list = Dir[File.join(File.dirname(__FILE__),"..","..","lib","puppet","parser","functions","*.rb")].collect do |function_rb| |
| 21 | + File.basename(function_rb,".rb") |
| 22 | +end |
| 23 | + |
| 24 | +## Configure rspec to parse tests |
| 25 | +options = RSpec::Core::ConfigurationOptions.new(['spec/acceptance']) |
| 26 | +configuration = RSpec::configuration |
| 27 | +world = RSpec::world |
| 28 | +options.parse_options |
| 29 | +options.configure(configuration) |
| 30 | +configuration.load_spec_files |
| 31 | + |
| 32 | +## Collect up tests and example groups into a hash |
| 33 | +def get_tests(children) |
| 34 | + children.inject({}) do |memo,c| |
| 35 | + memo[c.description] = Hash.new |
| 36 | + memo[c.description]["groups"] = get_tests(c.children) unless c.children.empty? |
| 37 | + memo[c.description]["tests"] = c.examples.collect { |e| |
| 38 | + e.description unless e.pending? |
| 39 | + }.compact unless c.examples.empty? |
| 40 | + memo[c.description]["pending_tests"] = c.examples.collect { |e| |
| 41 | + e.description if e.pending? |
| 42 | + }.compact unless c.examples.empty? |
| 43 | + memo |
| 44 | + end |
| 45 | +end |
| 46 | + |
| 47 | +# Convert tests hash to csv format |
| 48 | +def to_csv(function_list,tests) |
| 49 | + function_list.collect do |function_name| |
| 50 | + if v = tests["#{function_name} function"] |
| 51 | + positive_tests = v["groups"]["success"] ? v["groups"]["success"]["tests"].length : 0 |
| 52 | + negative_tests = v["groups"]["failure"] ? v["groups"]["failure"]["tests"].length : 0 |
| 53 | + pending_tests = |
| 54 | + (v["groups"]["failure"] ? v["groups"]["success"]["pending_tests"].length : 0) + |
| 55 | + (v["groups"]["failure"] ? v["groups"]["failure"]["pending_tests"].length : 0) |
| 56 | + else |
| 57 | + positive_tests = 0 |
| 58 | + negative_tests = 0 |
| 59 | + pending_tests = 0 |
| 60 | + end |
| 61 | + sprintf("%-25s, %-9d, %-9d, %-9d", function_name,positive_tests,negative_tests,pending_tests) |
| 62 | + end.compact |
| 63 | +end |
| 64 | + |
| 65 | +tests = get_tests(world.example_groups) |
| 66 | +csv = to_csv(function_list,tests) |
| 67 | +percentage_tested = "#{tests.count*100/function_list.count}%" |
| 68 | +printf("%-25s, %-9s, %-9s, %-9s\n","#{percentage_tested} have tests.","Positive","Negative","Pending") |
| 69 | +puts csv |
0 commit comments