This repository has been archived by the owner on May 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Rakefile
85 lines (74 loc) · 2.55 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
require 'rake'
require 'puppet-lint/tasks/puppet-lint'
require 'puppet-syntax/tasks/puppet-syntax'
require 'pathname'
require 'shellwords'
require 'json'
require './spec/lib/finder'
require './spec/lib/spec_runner'
PuppetLint.configuration.fail_on_warnings = true
PuppetLint.configuration.send('disable_arrow_alignment')
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.send('disable_140chars')
PuppetLint.configuration.send('disable_documentation')
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
PuppetLint.configuration.send('disable_parameter_order')
PuppetLint.configuration.send('disable_variable_is_lowercase')
PuppetLint.configuration.send('disable_arrow_on_right_operand_line')
PuppetLint.configuration.send('disable_single_quote_string_with_variables')
PuppetLint.configuration.ignore_paths = %w(**/templates/**/*.pp vendor/**/*.pp)
PuppetSyntax.exclude_paths = %w(**/templates/**/*.pp vendor/**/*.pp)
class SpecRunnerTask
def self.execute(specs)
runner = PuppetModules::SpecRunner.new
runner.on :output do |data|
$stderr.print data
end
runner.filter_os_list = ENV['os'].split(/,\s*/) if ENV['os']
runner.add_specs(specs)
result = runner.run
puts result.summary
exit(result.success?)
end
end
root_dir = Pathname.new('./')
finder = PuppetModules::Finder.new(root_dir.join('modules'))
desc 'Run all specs'
task :spec do
SpecRunnerTask.execute(finder.specs)
end
namespace :spec do
finder.puppet_modules.each do |puppet_module|
specs = puppet_module.specs
desc "Run #{puppet_module.name} specs"
task puppet_module.name do
SpecRunnerTask.execute(specs)
end
next unless specs.length > 1
specs.each do |spec|
desc "Run #{spec.name} spec"
task spec.name do
SpecRunnerTask.execute([spec])
end
end
end
desc 'Run all specs affected between `branch` and HEAD'
task :changes_from_branch, [:branch] do |task, args|
args.with_defaults(:branch => 'master')
file_list = `git diff --name-only #{args.branch.shellescape}`.split("\n")
module_list = file_list.map do |file|
Regexp.last_match(1) if Regexp.new('^modules/(.+?)/').match(file)
end
module_list.compact!
module_list.uniq!
module_list.select! { |module_name| finder.puppet_module?(module_name) }
specs = module_list.map do |module_name|
finder.puppet_module(module_name).specs
end
specs.flatten!
SpecRunnerTask.execute(specs)
end
task :cleanup do
Komenda.run(['vagrant', 'halt', '--force'], fail_on_fail: true)
end
end