diff options
author | Ashley Penney <ashley.penney@puppetlabs.com> | 2014-04-28 14:55:29 -0400 |
---|---|---|
committer | Ashley Penney <ashley.penney@puppetlabs.com> | 2014-04-28 14:55:29 -0400 |
commit | f8bfe46bbfa4a4737cef9a20cfe1bed04aee4bdc (patch) | |
tree | 3f9e8ee134c0ed8375d3e80987c0801971f32736 /spec/acceptance/build_csv.rb | |
parent | 0b59dfe64299abd0c7e9a72dd381341cb9a5c260 (diff) | |
parent | 90222959b14a10c3519c88f74e244b13b07fd78b (diff) | |
download | puppet-stdlib-f8bfe46bbfa4a4737cef9a20cfe1bed04aee4bdc.tar.gz puppet-stdlib-f8bfe46bbfa4a4737cef9a20cfe1bed04aee4bdc.tar.bz2 |
Merge pull request #243 from hunner/add_beaker
Add beaker tests for functions.
Diffstat (limited to 'spec/acceptance/build_csv.rb')
-rw-r--r-- | spec/acceptance/build_csv.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/acceptance/build_csv.rb b/spec/acceptance/build_csv.rb new file mode 100644 index 0000000..556d1f8 --- /dev/null +++ b/spec/acceptance/build_csv.rb @@ -0,0 +1,69 @@ +#!/usr/bin/env ruby +# vim: set sw=2 sts=2 et tw=80 : +require 'rspec' +require 'pry' + +#XXX Super ugly hack to keep from starting beaker nodes +module Kernel + # make an alias of the original require + alias_method :original_require, :require + # rewrite require + def require name + original_require name if name != 'spec_helper_acceptance' + end +end +UNSUPPORTED_PLATFORMS = [] +def fact(*args) [] end +#XXX End hax + +# Get a list of functions for test coverage +function_list = Dir[File.join(File.dirname(__FILE__),"..","..","lib","puppet","parser","functions","*.rb")].collect do |function_rb| + File.basename(function_rb,".rb") +end + +## Configure rspec to parse tests +options = RSpec::Core::ConfigurationOptions.new(['spec/acceptance']) +configuration = RSpec::configuration +world = RSpec::world +options.parse_options +options.configure(configuration) +configuration.load_spec_files + +## Collect up tests and example groups into a hash +def get_tests(children) + children.inject({}) do |memo,c| + memo[c.description] = Hash.new + memo[c.description]["groups"] = get_tests(c.children) unless c.children.empty? + memo[c.description]["tests"] = c.examples.collect { |e| + e.description unless e.pending? + }.compact unless c.examples.empty? + memo[c.description]["pending_tests"] = c.examples.collect { |e| + e.description if e.pending? + }.compact unless c.examples.empty? + memo + end +end + +# Convert tests hash to csv format +def to_csv(function_list,tests) + function_list.collect do |function_name| + if v = tests["#{function_name} function"] + positive_tests = v["groups"]["success"] ? v["groups"]["success"]["tests"].length : 0 + negative_tests = v["groups"]["failure"] ? v["groups"]["failure"]["tests"].length : 0 + pending_tests = + (v["groups"]["failure"] ? v["groups"]["success"]["pending_tests"].length : 0) + + (v["groups"]["failure"] ? v["groups"]["failure"]["pending_tests"].length : 0) + else + positive_tests = 0 + negative_tests = 0 + pending_tests = 0 + end + sprintf("%-25s, %-9d, %-9d, %-9d", function_name,positive_tests,negative_tests,pending_tests) + end.compact +end + +tests = get_tests(world.example_groups) +csv = to_csv(function_list,tests) +percentage_tested = "#{tests.count*100/function_list.count}%" +printf("%-25s, %-9s, %-9s, %-9s\n","#{percentage_tested} have tests.","Positive","Negative","Pending") +puts csv |