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