puppet-syntax 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -4
- data/CHANGELOG.md +12 -0
- data/lib/puppet-syntax/tasks/puppet-syntax.rb +10 -3
- data/lib/puppet-syntax/templates.rb +41 -15
- data/lib/puppet-syntax/version.rb +1 -1
- data/spec/puppet-syntax/templates_spec.rb +28 -20
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d56b393f1a0a60742b7c0600dd39568eb232cee2bae2400b169fee499cb12a6
|
4
|
+
data.tar.gz: 3b641f2e4ad9f5ab9fa8f91853bfc557b6573e871caeae2228b17f2446d96270
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4cf5aff0b7abe2e3dc4f07f6a3fec2704c637c063f076e08d9c4812f8fdb8b68fc4d65277982d12008914dca799cf45e8bf6ec5120827b3485abc569755b6c3
|
7
|
+
data.tar.gz: 63e40dd6206c72b2dfddbc85dd0efff6c4fffcd748277e15cacf1aaa54c79a1d62b67da751842ee190856b01e333c391197e22393372d54851306b67639b12bf
|
data/.travis.yml
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
---
|
2
|
+
os: linux
|
2
3
|
dist: bionic
|
3
4
|
language: ruby
|
4
5
|
# Workaround https://github.com/bundler/bundler/issues/3558
|
@@ -9,14 +10,16 @@ rvm:
|
|
9
10
|
- 2.4.4
|
10
11
|
- 2.5.1
|
11
12
|
- 2.6.5
|
13
|
+
- 2.7
|
12
14
|
env:
|
13
15
|
- PUPPET_VERSION="~> 5.5.10"
|
14
|
-
- PUPPET_VERSION="~> 6.
|
15
|
-
- PUPPET_VERSION="~> 6.2.0"
|
16
|
-
- PUPPET_VERSION="~> 6.5.0"
|
16
|
+
- PUPPET_VERSION="~> 6.5"
|
17
17
|
- PUPPET_VERSION=">= 0"
|
18
18
|
- PUPPET_VERSION="git://github.com/puppetlabs/puppet.git#master"
|
19
|
-
|
19
|
+
jobs:
|
20
|
+
exclude:
|
21
|
+
- rvm: 2.7
|
22
|
+
env: PUPPET_VERSION="~> 5.5.10"
|
20
23
|
allow_failures:
|
21
24
|
- env: PUPPET_VERSION=">= 0"
|
22
25
|
- env: PUPPET_VERSION="git://github.com/puppetlabs/puppet.git#master"
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## [v3.1.0](https://github.com/voxpupuli/puppet-syntax/tree/v3.1.0) (2020-06-24)
|
6
|
+
|
7
|
+
[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v3.0.1...v3.1.0)
|
8
|
+
|
9
|
+
**Implemented enhancements:**
|
10
|
+
|
11
|
+
- print actual template errors on $stderr [\#125](https://github.com/voxpupuli/puppet-syntax/pull/125) ([foxxx0](https://github.com/foxxx0))
|
12
|
+
|
13
|
+
**Merged pull requests:**
|
14
|
+
|
15
|
+
- Add ruby2.7 testing, replacing multiple obsolete puppet6 versions [\#124](https://github.com/voxpupuli/puppet-syntax/pull/124) ([DavidS](https://github.com/DavidS))
|
16
|
+
|
5
17
|
## [v3.0.1](https://github.com/voxpupuli/puppet-syntax/tree/v3.0.1) (2020-05-27)
|
6
18
|
|
7
19
|
[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v3.0.0...v3.0.1)
|
@@ -48,9 +48,16 @@ module PuppetSyntax
|
|
48
48
|
$stderr.puts "---> #{t.name}"
|
49
49
|
|
50
50
|
c = PuppetSyntax::Templates.new
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
result = c.check(filelist_templates)
|
52
|
+
unless result[:warnings].empty?
|
53
|
+
$stdout.puts "WARNINGS:"
|
54
|
+
$stdout.puts result[:warnings].join("\n")
|
55
|
+
end
|
56
|
+
unless result[:errors].empty?
|
57
|
+
$stderr.puts "ERRORS:"
|
58
|
+
$stderr.puts result[:errors].join("\n")
|
59
|
+
exit 1
|
60
|
+
end
|
54
61
|
end
|
55
62
|
|
56
63
|
desc 'Syntax check Hiera config files'
|
@@ -9,38 +9,64 @@ module PuppetSyntax
|
|
9
9
|
|
10
10
|
# We now have to redirect STDERR in order to capture warnings.
|
11
11
|
$stderr = warnings = StringIO.new()
|
12
|
-
|
12
|
+
result = { warnings: [], errors: [] }
|
13
13
|
|
14
14
|
filelist.each do |file|
|
15
15
|
if File.extname(file) == '.epp' or PuppetSyntax.epp_only
|
16
|
-
|
16
|
+
tmp = validate_epp(file)
|
17
17
|
elsif File.extname(file) == '.erb'
|
18
|
-
|
18
|
+
tmp = validate_erb(file)
|
19
19
|
end
|
20
|
+
result.merge!(tmp) { |k, a, b| a.concat(b) } unless tmp.nil?
|
20
21
|
end
|
21
22
|
|
22
23
|
$stderr = STDERR
|
23
|
-
|
24
|
-
errors.map! { |e| e.to_s }
|
24
|
+
result[:warnings] << warnings.string unless warnings.string.empty?
|
25
25
|
|
26
|
-
errors
|
26
|
+
result[:errors].map! { |e| e.to_s }
|
27
|
+
result[:warnings].map! { |w| w.to_s }
|
28
|
+
|
29
|
+
result
|
27
30
|
end
|
28
31
|
|
29
32
|
def validate_epp(filename)
|
30
33
|
require 'puppet/pops'
|
31
|
-
|
34
|
+
result = { warnings: [], errors: [] }
|
35
|
+
formatter = Puppet::Pops::Validation::DiagnosticFormatterPuppetStyle.new
|
36
|
+
evaluating_parser = Puppet::Pops::Parser::EvaluatingParser::EvaluatingEppParser.new()
|
37
|
+
parser = evaluating_parser.parser()
|
32
38
|
begin
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
39
|
+
parse_result = parser.parse_file(filename)
|
40
|
+
validation_result = evaluating_parser.validate(parse_result.model)
|
41
|
+
|
42
|
+
# print out any warnings
|
43
|
+
validation_result.warnings.each do |warn|
|
44
|
+
message = formatter.format_message(warn)
|
45
|
+
file = warn.file
|
46
|
+
line = warn.source_pos.line
|
47
|
+
column = warn.source_pos.pos
|
48
|
+
result[:warnings] << "#{file}:#{line}:#{column}: #{message}"
|
49
|
+
end
|
50
|
+
|
51
|
+
# collect errors and return them in order to indicate validation failure
|
52
|
+
validation_result.errors.each do |err|
|
53
|
+
message = formatter.format_message(err)
|
54
|
+
file = err.file
|
55
|
+
line = err.source_pos.line
|
56
|
+
column = err.source_pos.pos
|
57
|
+
result[:errors] << "#{file}:#{line}:#{column}: #{message}"
|
58
|
+
end
|
59
|
+
rescue Puppet::ParseError, SyntaxError => exc
|
60
|
+
result[:errors] << exc
|
61
|
+
rescue => exc
|
62
|
+
result[:errors] << exc
|
37
63
|
end
|
38
64
|
|
39
|
-
|
65
|
+
result
|
40
66
|
end
|
41
67
|
|
42
68
|
def validate_erb(filename)
|
43
|
-
|
69
|
+
result = { warnings: [], errors: [] }
|
44
70
|
|
45
71
|
begin
|
46
72
|
erb = ERB.new(File.read(filename), nil, '-')
|
@@ -53,10 +79,10 @@ module PuppetSyntax
|
|
53
79
|
# This is normal because we don't have the variables that would
|
54
80
|
# ordinarily be bound by the parent Puppet manifest.
|
55
81
|
rescue SyntaxError => error
|
56
|
-
errors << error
|
82
|
+
result[:errors] << error
|
57
83
|
end
|
58
84
|
|
59
|
-
|
85
|
+
result
|
60
86
|
end
|
61
87
|
end
|
62
88
|
end
|
@@ -18,91 +18,99 @@ describe PuppetSyntax::Templates do
|
|
18
18
|
files = fixture_templates('pass.erb')
|
19
19
|
res = subject.check(files)
|
20
20
|
|
21
|
-
expect(res).to match([])
|
21
|
+
expect(res[:warnings]).to match([])
|
22
|
+
expect(res[:errors]).to match([])
|
22
23
|
end
|
23
24
|
|
24
25
|
it 'should ignore NameErrors from unbound variables' do
|
25
26
|
files = fixture_templates('pass_unbound_var.erb')
|
26
27
|
res = subject.check(files)
|
27
28
|
|
28
|
-
expect(res).to match([])
|
29
|
+
expect(res[:warnings]).to match([])
|
30
|
+
expect(res[:errors]).to match([])
|
29
31
|
end
|
30
32
|
|
31
33
|
it 'should catch SyntaxError' do
|
32
34
|
files = fixture_templates('fail_error.erb')
|
33
35
|
res = subject.check(files)
|
34
36
|
|
35
|
-
expect(res.size).to eq(1)
|
36
|
-
expect(res[0]).to match(/2: syntax error, unexpected/)
|
37
|
+
expect(res[:errors].size).to eq(1)
|
38
|
+
expect(res[:errors][0]).to match(/2: syntax error, unexpected/)
|
37
39
|
end
|
38
40
|
|
39
41
|
it 'should catch Ruby warnings' do
|
40
42
|
files = fixture_templates('fail_warning.erb')
|
41
43
|
res = subject.check(files)
|
42
44
|
|
43
|
-
expect(res.size).to eq(1)
|
44
|
-
expect(res[0]).to match(conditional_warning_regex)
|
45
|
+
expect(res[:warnings].size).to eq(1)
|
46
|
+
expect(res[:warnings][0]).to match(conditional_warning_regex)
|
45
47
|
end
|
46
48
|
|
47
49
|
it 'should read more than one valid file' do
|
48
50
|
files = fixture_templates(['pass.erb', 'pass_unbound_var.erb'])
|
49
51
|
res = subject.check(files)
|
50
52
|
|
51
|
-
expect(res).to match([])
|
53
|
+
expect(res[:warnings]).to match([])
|
54
|
+
expect(res[:errors]).to match([])
|
52
55
|
end
|
53
56
|
|
54
57
|
it 'should continue after finding an error in the first file' do
|
55
58
|
files = fixture_templates(['fail_error.erb', 'fail_warning.erb'])
|
56
59
|
res = subject.check(files)
|
57
60
|
|
58
|
-
expect(res.size).to eq(
|
59
|
-
expect(res[
|
60
|
-
expect(res[
|
61
|
+
expect(res[:warnings].size).to eq(1)
|
62
|
+
expect(res[:errors].size).to eq(1)
|
63
|
+
expect(res[:errors][0]).to match(/2: syntax error, unexpected/)
|
64
|
+
expect(res[:warnings][0]).to match(conditional_warning_regex)
|
61
65
|
end
|
62
66
|
|
63
67
|
it 'should ignore a TypeError' do
|
64
68
|
files = fixture_templates('typeerror_shouldwin.erb')
|
65
69
|
res = subject.check(files)
|
66
70
|
|
67
|
-
expect(res).to match([])
|
71
|
+
expect(res[:warnings]).to match([])
|
72
|
+
expect(res[:errors]).to match([])
|
68
73
|
end
|
69
74
|
|
70
75
|
it 'should ignore files without .erb extension' do
|
71
76
|
files = fixture_templates('ignore.tpl')
|
72
77
|
res = subject.check(files)
|
73
78
|
|
74
|
-
expect(res).to match([])
|
79
|
+
expect(res[:warnings]).to match([])
|
80
|
+
expect(res[:errors]).to match([])
|
75
81
|
end
|
76
82
|
|
77
83
|
it 'should return nothing from a valid file' do
|
78
84
|
files = fixture_templates('pass.epp')
|
79
85
|
res = subject.check(files)
|
80
86
|
|
81
|
-
expect(res).to match([])
|
87
|
+
expect(res[:warnings]).to match([])
|
88
|
+
expect(res[:errors]).to match([])
|
82
89
|
end
|
83
90
|
|
84
91
|
it 'should catch SyntaxError' do
|
85
92
|
files = fixture_templates('fail_error.epp')
|
86
93
|
res = subject.check(files)
|
87
94
|
|
88
|
-
expect(res.size).to eq(1)
|
89
|
-
expect(res[0]).to match(/This Type-Name has no effect/)
|
95
|
+
expect(res[:errors].size).to eq(1)
|
96
|
+
expect(res[:errors][0]).to match(/This Type-Name has no effect/)
|
90
97
|
end
|
91
98
|
|
92
99
|
it 'should read more than one valid file' do
|
93
100
|
files = fixture_templates(['pass.epp', 'pass_also.epp'])
|
94
101
|
res = subject.check(files)
|
95
102
|
|
96
|
-
expect(res).to match([])
|
103
|
+
expect(res[:warnings]).to match([])
|
104
|
+
expect(res[:errors]).to match([])
|
97
105
|
end
|
98
106
|
|
99
107
|
it 'should continue after finding an error in the first file' do
|
100
108
|
files = fixture_templates(['fail_error.epp', 'fail_error_also.epp'])
|
101
109
|
res = subject.check(files)
|
102
110
|
|
103
|
-
expect(res.size).to eq(2)
|
104
|
-
expect(res[0]).to match(/This Type-Name has no effect/)
|
105
|
-
expect(res[1]).to match(/Syntax error at '}' \(file: \S*\/fail_error_also.epp, line: 2, column: 4\)/)
|
111
|
+
expect(res[:errors].size).to eq(2)
|
112
|
+
expect(res[:errors][0]).to match(/This Type-Name has no effect/)
|
113
|
+
expect(res[:errors][1]).to match(/Syntax error at '}' \(file: \S*\/fail_error_also.epp, line: 2, column: 4\)/)
|
106
114
|
end
|
107
115
|
|
108
116
|
context "when the 'epp_only' options is set" do
|
@@ -114,7 +122,7 @@ describe PuppetSyntax::Templates do
|
|
114
122
|
files = fixture_templates('pass.erb')
|
115
123
|
res = subject.check(files)
|
116
124
|
|
117
|
-
expect(res.size).to eq(1)
|
125
|
+
expect(res[:errors].size).to eq(1)
|
118
126
|
end
|
119
127
|
end
|
120
128
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-syntax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vox Pupuli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|