1 # vim: set sw=2 sts=2 et tw=80 :
4 # XXX Super ugly hack to keep from starting beaker nodes
6 # make an alias of the original require
7 alias original_require require
10 original_require name if name != 'spec_helper_acceptance'
13 UNSUPPORTED_PLATFORMS = [].freeze
19 # Get a list of functions for test coverage
20 function_list = Dir[File.join(File.dirname(__FILE__), '..', '..', 'lib', 'puppet', 'parser', 'functions', '*.rb')].map do |function_rb|
21 File.basename(function_rb, '.rb')
24 ## Configure rspec to parse tests
25 options = RSpec::Core::ConfigurationOptions.new(['spec/acceptance'])
26 configuration = RSpec.configuration
29 options.configure(configuration)
30 configuration.load_spec_files
32 ## Collect up tests and example groups into a hash
33 def get_tests(children)
34 children.each_with_object({}) do |c, memo|
35 memo[c.description] = {}
36 memo[c.description]['groups'] = get_tests(c.children) unless c.children.empty?
37 unless c.examples.empty?
38 memo[c.description]['tests'] = c.examples.map { |e|
39 e.description unless e.pending?
42 next if c.examples.empty?
43 memo[c.description]['pending_tests'] = c.examples.map { |e|
44 e.description if e.pending?
49 def count_test_types_in(type, group)
50 return 0 if group.nil?
51 group.reduce(0) do |m, (k, v)|
52 m += v.length if k == type
53 m += count_tests_in(v) if v.is_a?(Hash)
58 def count_tests_in(group)
59 count_test_types_in('tests', group)
62 def count_pending_tests_in(group)
63 count_test_types_in('pending_tests', group)
66 # Convert tests hash to csv format
67 def to_csv(function_list, tests)
68 function_list.map { |function_name|
69 v = tests["#{function_name} function"]
71 positive_tests = count_tests_in(v['groups']['success'])
72 negative_tests = count_tests_in(v['groups']['failure'])
74 count_pending_tests_in(v['groups']['failure']) +
75 count_pending_tests_in(v['groups']['failure'])
81 '%-25s, %-9d, %-9d, %-9d' % [function_name, positive_tests, negative_tests, pending_tests]
85 tests = get_tests(world.example_groups)
86 csv = to_csv(function_list, tests)
87 percentage_tested = "#{tests.count * 100 / function_list.count}%"
88 printf("%-25s, %-9s, %-9s, %-9s\n", "#{percentage_tested} have tests.", 'Positive', 'Negative', 'Pending')