2 # vim: set sw=2 sts=2 et tw=80 :
5 #XXX Super ugly hack to keep from starting beaker nodes
7 # make an alias of the original require
8 alias_method :original_require, :require
11 original_require name if name != 'spec_helper_acceptance'
14 UNSUPPORTED_PLATFORMS = []
15 def fact(*args) [] end
18 # Get a list of functions for test coverage
19 function_list = Dir[File.join(File.dirname(__FILE__),"..","..","lib","puppet","parser","functions","*.rb")].collect do |function_rb|
20 File.basename(function_rb,".rb")
23 ## Configure rspec to parse tests
24 options = RSpec::Core::ConfigurationOptions.new(['spec/acceptance'])
25 configuration = RSpec::configuration
28 options.configure(configuration)
29 configuration.load_spec_files
31 ## Collect up tests and example groups into a hash
32 def get_tests(children)
33 children.inject({}) do |memo,c|
34 memo[c.description] = Hash.new
35 memo[c.description]["groups"] = get_tests(c.children) unless c.children.empty?
36 memo[c.description]["tests"] = c.examples.collect { |e|
37 e.description unless e.pending?
38 }.compact unless c.examples.empty?
39 memo[c.description]["pending_tests"] = c.examples.collect { |e|
40 e.description if e.pending?
41 }.compact unless c.examples.empty?
46 def count_test_types_in(type,group)
47 return 0 if group.nil?
48 group.inject(0) do |m,(k,v)|
49 m += v.length if k == type
50 m += count_tests_in(v) if v.is_a?(Hash)
54 def count_tests_in(group)
55 count_test_types_in('tests',group)
57 def count_pending_tests_in(group)
58 count_test_types_in('pending_tests',group)
61 # Convert tests hash to csv format
62 def to_csv(function_list,tests)
63 function_list.collect do |function_name|
64 if v = tests["#{function_name} function"]
65 positive_tests = count_tests_in(v["groups"]["success"])
66 negative_tests = count_tests_in(v["groups"]["failure"])
68 count_pending_tests_in(v["groups"]["failure"]) +
69 count_pending_tests_in(v["groups"]["failure"])
75 sprintf("%-25s, %-9d, %-9d, %-9d", function_name,positive_tests,negative_tests,pending_tests)
79 tests = get_tests(world.example_groups)
80 csv = to_csv(function_list,tests)
81 percentage_tested = "#{tests.count*100/function_list.count}%"
82 printf("%-25s, %-9s, %-9s, %-9s\n","#{percentage_tested} have tests.","Positive","Negative","Pending")