pairing with luke, nagios_command provider skeleton
[vinpup.git] / test / Rakefile
bloba8118c1c5a4b9d01c917588f12a454743f531837
1 # let Emacs know it's -*- ruby -*-
2 begin
3     require 'rake/testtask'
4 rescue LoadError
5     $stderr.puts "You must have 'rake' installed to use this file"
6     exit(1)
7 end
9 require 'find'
11 include Find
12 include FileTest
14 $exclusions = %W(lib data)
15 $test_library_paths = %W(lib ../lib)
17 $: << File.join(Dir.getwd, "lib")
19 require 'rake/puppet_testtask'
21 filemap = Hash.new { |hash, key| hash[key] = [] }
23 allfiles = []
25 # First collect the entire file list.
26 find(".") do |f|
27     # Get rid of the leading ./
28     f = f.sub(/^\.\//, '')
30     file = File.basename(f)
31     dir = File.dirname(f)
33     # Prune . directories and excluded dirs
34     if (file =~ /^\./ and f != ".") or $exclusions.include?(File.basename(file))
35         prune
36         next
37     end
38     next if f == "."
39     next if dir == "."
41     # If we're a ruby script, then add it to the list of files for that dir
42     if file =~ /\.rb$/
43         allfiles << f
44         # Add it to all of the parent dirs, not just our own
45         parts = File.split(dir)
46         if parts[0] == "."
47             parts.shift
48         end
49         parts.each_with_index { |part, i|
50             path = File.join(parts[0..i])
51             filemap[path] << f
52         }
53     end
54 end
56 desc "Run the full test suite"
57 Rake::PuppetTestTask.new :test do |t|
58     t.libs << $test_library_paths
60     # Add every file as a test file to run
61     t.test_files = allfiles
62     t.verbose = true
63 end
65 task :default => :test
67 # Now create a task for every directory
68 filemap.each do |dir, files|
69     ns = dir.gsub "/", ":"
71     # First create a separate task for each file in the namespace.
72     namespace ns do
73         files.each do |file|
74             Rake::PuppetTestTask.new File.basename(file, '.rb').to_sym do |t|
75                 t.libs << $test_library_paths + ['..']
76                 t.test_files = [ file ]
77                 t.verbose = true 
78             end 
79         end
80     end
82     # Then create a task that matches the directory itself.
83     Rake::PuppetTestTask.new dir do |t|
84        t.libs << $test_library_paths
85        if ENV["TESTFILES"]
86            t.test_files = ENV["TESTFILES"].split(/\s+/)
87        else
88            t.test_files = files.sort
89        end
90        t.verbose = true
91     end
93     # And alias it with a slash on the end
94     task(dir + "/" => dir)
95 end
97 # $Id$