Skip to content

Commit

Permalink
Merge pull request #74 from domcleal/vesioncmp
Browse files Browse the repository at this point in the history
Use versioncmp to check Puppet version for 4.10.x compatibility
  • Loading branch information
domcleal authored Mar 14, 2017
2 parents b6c04c6 + 5b8944a commit 56bc050
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/puppet-syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module PuppetSyntax
"hiera*.*yaml"
]
@fail_on_deprecation_notices = true
@app_management = Puppet::PUPPETVERSION.to_i >= 5 ? true : false
@app_management = Puppet.version.to_i >= 5 ? true : false
@check_hiera_keys = false

class << self
Expand All @@ -26,7 +26,7 @@ class << self
attr_reader :app_management

def app_management=(app_management)
raise 'app_management cannot be disabled on Puppet 5 or higher' if Puppet::PUPPETVERSION.to_i >= 5 && !app_management
raise 'app_management cannot be disabled on Puppet 5 or higher' if Puppet.version.to_i >= 5 && !app_management
@app_management = app_management
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet-syntax/manifests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def check(filelist)

private
def validate_manifest(file)
Puppet[:parser] = 'future' if PuppetSyntax.future_parser and Puppet::PUPPETVERSION.to_i < 4
Puppet[:app_management] = true if PuppetSyntax.app_management && (Puppet::PUPPETVERSION.to_f >= 4.3 && Puppet::PUPPETVERSION.to_i < 5)
Puppet[:parser] = 'future' if PuppetSyntax.future_parser and Puppet.version.to_i < 4
Puppet[:app_management] = true if PuppetSyntax.app_management && (Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 && Puppet.version.to_i < 5)
Puppet::Face[:parser, :current].validate(file)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet-syntax/tasks/puppet-syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def initialize(*args)

desc 'Syntax check Puppet manifests'
task :manifests do |t|
if Puppet::PUPPETVERSION.to_i >= 4 and PuppetSyntax.future_parser
if Puppet.version.to_i >= 4 and PuppetSyntax.future_parser
$stderr.puts <<-EOS
[INFO] Puppet 4 has been detected and `future_parser` has been set to
'true'. The `future_parser setting will be ignored.
EOS
end
if Puppet::PUPPETVERSION.to_f < 4.3 and PuppetSyntax.app_management
if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') < 0 and PuppetSyntax.app_management
$stderr.puts <<-EOS
[WARNING] Puppet `app_management` has been detected but the Puppet
version is less then 4.3. The `app_management` setting will be ignored.
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet-syntax/templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def check(filelist)
end

def validate_epp(filename)
if Puppet::PUPPETVERSION.to_f < 3.7
if Puppet.version.to_f < 3.7
raise "Cannot validate EPP without Puppet 4 or future parser (3.7+)"
end

Expand Down
12 changes: 6 additions & 6 deletions spec/puppet-syntax/manifests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
files = fixture_manifests('fail_error.pp')
output, has_errors = subject.check(files)

if Puppet::PUPPETVERSION.to_i >= 4
if Puppet.version.to_i >= 4
expect(output.size).to eq(3)
expect(output[2]).to match(/2 errors. Giving up/)
expect(has_errors).to eq(true)
Expand Down Expand Up @@ -72,7 +72,7 @@
output, has_errors = subject.check(files)

expect(has_errors).to eq(true)
if Puppet::PUPPETVERSION.to_i >= 4
if Puppet.version.to_i >= 4
expect(output.size).to eq(5)
expect(output[0]).to match(/This Name has no effect. A Host Class Definition can not end with a value-producing expression without other effect at \S*\/fail_error.pp:2:32$/)
expect(output[1]).to match(/This Name has no effect. A value(-producing expression without other effect may only be placed last in a block\/sequence| was produced and then forgotten.*) at \S*\/fail_error.pp:2:3$/)
Expand Down Expand Up @@ -138,10 +138,10 @@

describe 'app_management' do
after do
PuppetSyntax.app_management = false if Puppet::PUPPETVERSION.to_i < 5
PuppetSyntax.app_management = false if Puppet.version.to_i < 5
end

context 'app_management = false (default)', :if => (Puppet::PUPPETVERSION.to_i < 5) do
context 'app_management = false (default)', :if => (Puppet.version.to_i < 5) do
it 'should fail to parse an application manifest' do

files = fixture_manifests(['test_app.pp'])
Expand All @@ -155,7 +155,7 @@
before(:each) {
PuppetSyntax.app_management = true
}
if Puppet::PUPPETVERSION.to_f >= 4.3
if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0
it 'should successfully parse an application manifest on Puppet >= 4.3.0' do
expect(PuppetSyntax.app_management).to eq(true)

Expand Down Expand Up @@ -211,7 +211,7 @@
PuppetSyntax.future_parser = true
}

if Puppet::Util::Package.versioncmp(Puppet.version, '3.2') >= 0 and Puppet::PUPPETVERSION.to_i < 4
if Puppet::Util::Package.versioncmp(Puppet.version, '3.2') >= 0 and Puppet.version.to_i < 4
context 'Puppet >= 3.2 < 4' do
it 'should pass with future option set to true on future manifest' do
files = fixture_manifests(['future_syntax.pp'])
Expand Down
4 changes: 2 additions & 2 deletions spec/puppet-syntax/templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
expect(res).to match([])
end

if Puppet::PUPPETVERSION.to_f < 3.7
if Puppet.version.to_f < 3.7
context 'on Puppet < 3.7' do
it 'should throw an exception when parsing EPP files' do
file = fixture_templates('pass.epp')
Expand All @@ -87,7 +87,7 @@
end
end

if Puppet::PUPPETVERSION.to_f >= 3.7
if Puppet.version.to_f >= 3.7
context 'on Puppet >= 3.7' do
it 'should return nothing from a valid file' do
files = fixture_templates('pass.epp')
Expand Down
4 changes: 2 additions & 2 deletions spec/puppet-syntax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe PuppetSyntax do
after do
PuppetSyntax.exclude_paths = []
PuppetSyntax.app_management = false if Puppet::PUPPETVERSION.to_i < 5
PuppetSyntax.app_management = false if Puppet.version.to_i < 5
end

it 'should default exclude_paths to empty array' do
Expand All @@ -30,7 +30,7 @@
expect(PuppetSyntax.app_management).to eq(true)
end

it 'should raise error when app_management is disabled on 5.x', :if => (Puppet::PUPPETVERSION.to_i >= 5) do
it 'should raise error when app_management is disabled on 5.x', :if => (Puppet.version.to_i >= 5) do
expect { PuppetSyntax.app_management = false }.to raise_error(/app_management cannot be disabled on Puppet 5 or higher/)
end

Expand Down

0 comments on commit 56bc050

Please sign in to comment.