puppet-syntax 1.4.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -2,10 +2,8 @@
2
2
  language: ruby
3
3
  script: bundle exec rake
4
4
  rvm:
5
- - 1.8.7
6
5
  - 1.9.3
7
6
  env:
8
- - PUPPET_VERSION="~> 2.7.0"
9
7
  - PUPPET_VERSION="~> 3.0.0"
10
8
  - PUPPET_VERSION="~> 3.1.0"
11
9
  - PUPPET_VERSION="~> 3.2.0"
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 2015-02-25 Release 2.0.0
2
+ - Removed support for Puppet version 2.7.x
3
+ - New option, fail_on_deprecation_notices, which defaults to true (compatible
4
+ with previous behaviour); thanks @pcfens
5
+ - PuppetSyntax::Manifests#check now has two return arguments
6
+
1
7
  2015-01-08 Release 1.4.1
2
8
  - Support appending to config arrays, thanks @domcleal
3
9
 
@@ -5,7 +5,7 @@ module PuppetSyntax
5
5
  require 'puppet'
6
6
  require 'puppet/face'
7
7
 
8
- errors = []
8
+ output = []
9
9
 
10
10
  # FIXME: We shouldn't need to do this. puppet/face should. See:
11
11
  # - http://projects.puppetlabs.com/issues/15529
@@ -15,7 +15,7 @@ module PuppetSyntax
15
15
  end
16
16
 
17
17
  # Catch syntax warnings.
18
- Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(errors))
18
+ Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(output))
19
19
  Puppet::Util::Log.level = :warning
20
20
 
21
21
  filelist.each do |puppet_file|
@@ -24,19 +24,26 @@ module PuppetSyntax
24
24
  rescue SystemExit
25
25
  # Disregard exit(1) from face.
26
26
  rescue => error
27
- errors << error
27
+ output << error
28
28
  end
29
29
  end
30
30
 
31
31
  Puppet::Util::Log.close_all
32
- errors.map! { |e| e.to_s }
32
+ output.map! { |e| e.to_s }
33
33
 
34
34
  # Exported resources will raise warnings when outside a puppetmaster.
35
- errors.reject! { |e|
35
+ output.reject! { |e|
36
36
  e =~ /^You cannot collect( exported resources)? without storeconfigs being set/
37
37
  }
38
38
 
39
- errors
39
+ deprecations = output.select { |e|
40
+ e =~ /^Deprecation notice:|is deprecated/
41
+ }
42
+
43
+ # Errors exist if there is any output that isn't a deprecation notice.
44
+ has_errors = (output != deprecations)
45
+
46
+ return output, has_errors
40
47
  end
41
48
 
42
49
  private
@@ -36,8 +36,9 @@ to puppetlabs_spec_helper >= 0.8.0 which now uses puppet-syntax.
36
36
  files = files.exclude(*PuppetSyntax.exclude_paths)
37
37
 
38
38
  c = PuppetSyntax::Manifests.new
39
- errors = c.check(files)
40
- fail errors.join("\n") unless errors.empty?
39
+ output, has_errors = c.check(files)
40
+ print "#{output.join("\n")}\n" unless output.empty?
41
+ fail if has_errors || ( output.any? && PuppetSyntax.fail_on_deprecation_notices )
41
42
  end
42
43
 
43
44
  desc 'Syntax check Puppet templates'
@@ -1,3 +1,3 @@
1
1
  module PuppetSyntax
2
- VERSION = "1.4.1"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/puppet-syntax.rb CHANGED
@@ -7,8 +7,9 @@ module PuppetSyntax
7
7
  @exclude_paths = []
8
8
  @future_parser = false
9
9
  @hieradata_paths = ["**/data/**/*.yaml", "hieradata/**/*.yaml", "hiera*.yaml"]
10
+ @fail_on_deprecation_notices = true
10
11
 
11
12
  class << self
12
- attr_accessor :exclude_paths, :future_parser, :hieradata_paths
13
+ attr_accessor :exclude_paths, :future_parser, :hieradata_paths, :fail_on_deprecation_notices
13
14
  end
14
15
  end
@@ -0,0 +1,6 @@
1
+ node test inherits default {
2
+ import 'pass.pp'
3
+ notify { 'this should give a deprecation notice':
4
+ message => 'inheritance is gone in the future parser',
5
+ }
6
+ }
@@ -10,50 +10,96 @@ describe PuppetSyntax::Manifests do
10
10
 
11
11
  it 'should return nothing from a valid file' do
12
12
  files = fixture_manifests('pass.pp')
13
- res = subject.check(files)
13
+ output, has_errors = subject.check(files)
14
14
 
15
- expect(res).to eq([])
15
+ expect(output).to eq([])
16
+ expect(has_errors).to eq(false)
16
17
  end
17
18
 
18
19
  it 'should return an error from an invalid file' do
19
20
  files = fixture_manifests('fail_error.pp')
20
- res = subject.check(files)
21
+ output, has_errors = subject.check(files)
21
22
 
22
- expect(res.size).to eq(1)
23
- expect(res[0]).to match(/Syntax error at .*:3$/)
23
+ expect(output.size).to eq(1)
24
+ expect(output[0]).to match(/Syntax error at .*:3$/)
25
+ expect(has_errors).to eq(true)
24
26
  end
25
27
 
26
28
  it 'should return a warning from an invalid file' do
27
29
  files = fixture_manifests('fail_warning.pp')
28
- res = subject.check(files)
30
+ output, has_errors = subject.check(files)
29
31
 
30
- expect(res.size).to eq(2)
31
- expect(res[0]).to match(/Unrecognised escape sequence '\\\[' .* at line 3$/)
32
- expect(res[1]).to match(/Unrecognised escape sequence '\\\]' .* at line 3$/)
32
+ expect(output.size).to eq(2)
33
+ expect(output[0]).to match(/Unrecognised escape sequence '\\\[' .* at line 3$/)
34
+ expect(output[1]).to match(/Unrecognised escape sequence '\\\]' .* at line 3$/)
35
+ expect(has_errors).to eq(true)
33
36
  end
34
37
 
35
38
  it 'should ignore warnings about storeconfigs' do
36
39
  files = fixture_manifests('pass_storeconfigs.pp')
37
- res = subject.check(files)
40
+ output, has_errors = subject.check(files)
41
+
42
+ expect(output).to eq([])
43
+ expect(has_errors).to eq(false)
38
44
 
39
- expect(res).to eq([])
40
45
  end
41
46
 
42
47
  it 'should read more than one valid file' do
43
48
  files = fixture_manifests(['pass.pp', 'pass_storeconfigs.pp'])
44
- res = subject.check(files)
49
+ output, has_errors = subject.check(files)
45
50
 
46
- expect(res).to eq([])
51
+ expect(output).to eq([])
52
+ expect(has_errors).to eq(false)
47
53
  end
48
54
 
49
55
  it 'should continue after finding an error in the first file' do
50
56
  files = fixture_manifests(['fail_error.pp', 'fail_warning.pp'])
51
- res = subject.check(files)
57
+ output, has_errors = subject.check(files)
58
+
59
+ expect(output.size).to eq(3)
60
+ expect(output[0]).to match(/Syntax error at '\}' .*:3$/)
61
+ expect(output[1]).to match(/Unrecognised escape sequence '\\\[' .* at line 3$/)
62
+ expect(output[2]).to match(/Unrecognised escape sequence '\\\]' .* at line 3$/)
63
+ expect(has_errors).to eq(true)
64
+ end
52
65
 
53
- expect(res.size).to eq(3)
54
- expect(res[0]).to match(/Syntax error at '\}' .*:3$/)
55
- expect(res[1]).to match(/Unrecognised escape sequence '\\\[' .* at line 3$/)
56
- expect(res[2]).to match(/Unrecognised escape sequence '\\\]' .* at line 3$/)
66
+ describe 'deprecation notices' do
67
+ # These tests should fail in Puppet 4, but we need to wait for the release
68
+ # before we'll know exactly how to test it.
69
+ if Puppet::Util::Package.versioncmp(Puppet.version, '3.7') >= 0
70
+ context 'on puppet >= 3.7' do
71
+ it 'should return deprecation notices as warnings' do
72
+ files = fixture_manifests('deprecation_notice.pp')
73
+ output, has_errors = subject.check(files)
74
+
75
+ expect(has_errors).to eq(false)
76
+ expect(output.size).to eq(2)
77
+ expect(output[0]).to match(/The use of 'import' is deprecated/)
78
+ expect(output[1]).to match(/Deprecation notice:/)
79
+ end
80
+ end
81
+ elsif Puppet::Util::Package.versioncmp(Puppet.version, '3.5') >= 0
82
+ context 'on puppet 3.5 and 3.6' do
83
+ it 'should return deprecation notices as warnings' do
84
+ files = fixture_manifests('deprecation_notice.pp')
85
+ output, has_errors = subject.check(files)
86
+
87
+ expect(has_errors).to eq(false)
88
+ expect(output.size).to eq(1)
89
+ expect(output[0]).to match(/The use of 'import' is deprecated/)
90
+ end
91
+ end
92
+ elsif Puppet::Util::Package.versioncmp(Puppet.version, '3.5') < 0
93
+ context 'on puppet < 3.5' do
94
+ it 'should not print deprecation notices' do
95
+ files = fixture_manifests('deprecation_notice.pp')
96
+ output, has_errors = subject.check(files)
97
+
98
+ expect(output).to eq([])
99
+ expect(has_errors).to eq(false)
100
+ end
101
+ end
102
+ end
57
103
  end
58
104
 
59
105
  describe 'future_parser' do
@@ -62,10 +108,11 @@ describe PuppetSyntax::Manifests do
62
108
  expect(PuppetSyntax.future_parser).to eq(false)
63
109
 
64
110
  files = fixture_manifests(['future_syntax.pp'])
65
- res = subject.check(files)
111
+ output, has_errors = subject.check(files)
66
112
 
67
- expect(res.size).to eq(1)
68
- expect(res[0]).to match(/Syntax error at '='; expected '\}' .*:2$/)
113
+ expect(output.size).to eq(1)
114
+ expect(output[0]).to match(/Syntax error at '='; expected '\}' .*:2$/)
115
+ expect(has_errors).to eq(true)
69
116
  end
70
117
  end
71
118
 
@@ -78,19 +125,34 @@ describe PuppetSyntax::Manifests do
78
125
  context 'Puppet >= 3.2' do
79
126
  it 'should pass with future option set to true on future manifest' do
80
127
  files = fixture_manifests(['future_syntax.pp'])
81
- res = subject.check(files)
128
+ output, has_errors = subject.check(files)
82
129
 
83
- expect(res.size).to eq(0)
130
+ expect(output).to eq([])
131
+ expect(has_errors).to eq(false)
132
+ end
133
+ end
134
+ context 'Puppet >= 3.7' do
135
+ # Certain elements of the future parser weren't added until 3.7
136
+ if Puppet::Util::Package.versioncmp(Puppet.version, '3.7') >= 0
137
+ it 'should fail on what were deprecation notices in the non-future parser' do
138
+ files = fixture_manifests('deprecation_notice.pp')
139
+ output, has_errors = subject.check(files)
140
+
141
+ expect(output.size).to eq(1)
142
+ expect(output[0]).to match(/Node inheritance is not supported/)
143
+ expect(has_errors).to eq(true)
144
+ end
84
145
  end
85
146
  end
86
147
  else
87
- context 'Puppet <= 3.2' do
148
+ context 'Puppet < 3.2' do
88
149
  it 'should return an error that the parser option is not supported' do
89
150
  files = fixture_manifests(['future_syntax.pp'])
90
- res = subject.check(files)
151
+ output, has_errors = subject.check(files)
91
152
 
92
- expect(res.size).to eq(1)
93
- expect(res[0]).to match("Attempt to assign a value to unknown configuration parameter :parser")
153
+ expect(output.size).to eq(1)
154
+ expect(output[0]).to match("Attempt to assign a value to unknown configuration parameter :parser")
155
+ expect(has_errors).to eq(true)
94
156
  end
95
157
  end
96
158
  end
@@ -24,4 +24,9 @@ describe PuppetSyntax do
24
24
  expect(PuppetSyntax.future_parser).to eq(true)
25
25
  end
26
26
 
27
+ it 'should support a fail_on_deprecation_notices setting' do
28
+ PuppetSyntax.fail_on_deprecation_notices = false
29
+ expect(PuppetSyntax.fail_on_deprecation_notices).to eq(false)
30
+ end
31
+
27
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-syntax
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-08 00:00:00.000000000 Z
12
+ date: 2015-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -84,6 +84,7 @@ files:
84
84
  - spec/fixtures/hiera/hiera_bad.yaml
85
85
  - spec/fixtures/hiera/hiera_bad_18.yaml
86
86
  - spec/fixtures/hiera/hiera_good.yaml
87
+ - spec/fixtures/test_module/manifests/deprecation_notice.pp
87
88
  - spec/fixtures/test_module/manifests/fail_error.pp
88
89
  - spec/fixtures/test_module/manifests/fail_warning.pp
89
90
  - spec/fixtures/test_module/manifests/future_syntax.pp
@@ -115,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
116
  version: '0'
116
117
  segments:
117
118
  - 0
118
- hash: -3142815382772503907
119
+ hash: 2080509366784508245
119
120
  required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  none: false
121
122
  requirements:
@@ -124,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  version: '0'
125
126
  segments:
126
127
  - 0
127
- hash: -3142815382772503907
128
+ hash: 2080509366784508245
128
129
  requirements: []
129
130
  rubyforge_project:
130
131
  rubygems_version: 1.8.23.2
@@ -135,6 +136,7 @@ test_files:
135
136
  - spec/fixtures/hiera/hiera_bad.yaml
136
137
  - spec/fixtures/hiera/hiera_bad_18.yaml
137
138
  - spec/fixtures/hiera/hiera_good.yaml
139
+ - spec/fixtures/test_module/manifests/deprecation_notice.pp
138
140
  - spec/fixtures/test_module/manifests/fail_error.pp
139
141
  - spec/fixtures/test_module/manifests/fail_warning.pp
140
142
  - spec/fixtures/test_module/manifests/future_syntax.pp