source: other-projects/hathitrust/vagrant-hadoop-cluster/trunk/modules/stdlib/spec/acceptance/build_csv.rb@ 30903

Last change on this file since 30903 was 30903, checked in by davidb, 7 years ago

Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details

  • Property svn:executable set to *
File size: 2.5 KB
Line 
1#!/usr/bin/env ruby
2# vim: set sw=2 sts=2 et tw=80 :
3require 'rspec'
4
5#XXX Super ugly hack to keep from starting beaker nodes
6module Kernel
7 # make an alias of the original require
8 alias_method :original_require, :require
9 # rewrite require
10 def require name
11 original_require name if name != 'spec_helper_acceptance'
12 end
13end
14UNSUPPORTED_PLATFORMS = []
15def fact(*args) [] end
16#XXX End hax
17
18# Get a list of functions for test coverage
19function_list = Dir[File.join(File.dirname(__FILE__),"..","..","lib","puppet","parser","functions","*.rb")].collect do |function_rb|
20 File.basename(function_rb,".rb")
21end
22
23## Configure rspec to parse tests
24options = RSpec::Core::ConfigurationOptions.new(['spec/acceptance'])
25configuration = RSpec::configuration
26world = RSpec::world
27options.parse_options
28options.configure(configuration)
29configuration.load_spec_files
30
31## Collect up tests and example groups into a hash
32def 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?
42 memo
43 end
44end
45
46def 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)
51 m
52 end
53end
54def count_tests_in(group)
55 count_test_types_in('tests',group)
56end
57def count_pending_tests_in(group)
58 count_test_types_in('pending_tests',group)
59end
60
61# Convert tests hash to csv format
62def 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"])
67 pending_tests =
68 count_pending_tests_in(v["groups"]["failure"]) +
69 count_pending_tests_in(v["groups"]["failure"])
70 else
71 positive_tests = 0
72 negative_tests = 0
73 pending_tests = 0
74 end
75 sprintf("%-25s, %-9d, %-9d, %-9d", function_name,positive_tests,negative_tests,pending_tests)
76 end.compact
77end
78
79tests = get_tests(world.example_groups)
80csv = to_csv(function_list,tests)
81percentage_tested = "#{tests.count*100/function_list.count}%"
82printf("%-25s, %-9s, %-9s, %-9s\n","#{percentage_tested} have tests.","Positive","Negative","Pending")
83puts csv
Note: See TracBrowser for help on using the repository browser.