-
Notifications
You must be signed in to change notification settings - Fork 36
/
Rakefile
113 lines (93 loc) · 3 KB
/
Rakefile
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require "rake/testtask"
require "bundler/gem_tasks"
require "puppet/version"
require "rubygems"
require "yaml"
require "erb"
desc "Clean workspace"
task :clean do
sh "rm -vrf *.gem pkg/"
sh "rm test/cases/working-with-hiera/hiera.yaml"
sh "rm test/cases/failing-with-hiera/hiera.yaml"
end
desc "Fix permissions"
task :pre_release do
sh "chmod -R a+r lib"
sh "chmod a+r puppet-catalog-test.gemspec"
sh "chmod a+rx bin/puppet-catalog-test"
sh "chmod a+r Rakefile README.md"
puts "=> Don't forget to adjust versions"
sh "grep -r VERSION lib"
sh "grep version puppet-catalog-test.gemspec"
end
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/*_test.rb']
t.verbose = true
end
task :test_integration do
base_dir = Dir.pwd
all_tests_green = true
Dir["test/**/Rakefile"].each do |rf|
supposed_to_fail = rf.include?("failing")
if rf.include?("future-parser")
supposed_to_fail = Gem::Version.new(Puppet.version) > Gem::Version.new('3.2.0')
end
Dir.chdir rf.split("/")[0..-2].join("/")
["catalog:scenarios", "catalog:all"].each do |tc|
tc_name = "#{rf} / #{tc}"
puts " * Running scenario: #{tc_name} ]"
exit_code = -1
captured_output = ""
if FileTest.exist?("hiera.yaml.erb")
template = ERB.new(File.read("hiera.yaml.erb"))
working_directory = File.join(File.dirname(__FILE__), File.dirname(rf))
File.open("hiera.yaml", "w") do |fp|
fp.puts template.result(binding)
end
end
IO.popen("bundle exec rake #{tc}") do |io|
while (line = io.gets)
captured_output << line
end
io.close
exit_code = $?
end
if (supposed_to_fail && exit_code != 0) || (!supposed_to_fail && exit_code == 0)
puts " WORKED (supposed_to_fail = #{supposed_to_fail})"
else
all_tests_green = false
puts "\tScenario: #{tc_name} FAILED (supposed_to_fail = #{supposed_to_fail})"
puts ">>>>>>>>>>>>>"
puts captured_output
puts "<<<<<<<<<<<<<"
end
end
Dir.chdir base_dir
end
if !all_tests_green
fail
end
end
task :generate_test_matrix do
# rbenv doesn't support fuzzy version matching, so we are using a good old mapping table
ruby_version_mapping = {
"1.8.7" => "1.8.7-p374",
"1.9.3" => "1.9.3-p551",
"2.0.0" => "2.0.0-p645"
}
config = YAML.load_file(".travis.yml")
checks = []
config["rvm"].each do |ruby_version|
config["env"].each do |env_var|
if !config["matrix"]["exclude"].detect { |ex| ex["rvm"] == ruby_version && ex["env"] == env_var }
puppet_version = env_var.match(/^PUPPET_VERSION=(.*)$/)[1]
mapped_ruby_version = ruby_version_mapping[ruby_version] || ruby_version
checks << "check #{mapped_ruby_version} #{puppet_version}"
end
end
end
template = ERB.new(File.read("run-all-tests.erb"))
File.open("run-all-tests", "w+") { |fp| fp.puts template.result(binding) }
end
task :default => [:test, :test_integration]