diff --git a/lib/puppet/functions/deprecation.rb b/lib/puppet/functions/deprecation.rb index a860aa262..39d9bc7fe 100644 --- a/lib/puppet/functions/deprecation.rb +++ b/lib/puppet/functions/deprecation.rb @@ -8,6 +8,12 @@ end def deprecation(key, message) + if defined? Puppet::Pops::PuppetStack.stacktrace() + stacktrace = Puppet::Pops::PuppetStack.stacktrace() + file = stacktrace[0] + line = stacktrace[1] + message = "#{message} at #{file}:#{line}" + end # depending on configuration setting of strict case Puppet.settings[:strict] when :off diff --git a/spec/acceptance/deprecation_spec.rb b/spec/acceptance/deprecation_spec.rb index ea137008a..7a0b34c46 100644 --- a/spec/acceptance/deprecation_spec.rb +++ b/spec/acceptance/deprecation_spec.rb @@ -82,4 +82,21 @@ it { is_expected.to be_file } end end + + context 'puppet 3 test', if: get_puppet_version =~ /^3/ do + before :all do + @result = on(default, puppet('apply', '--parser=future', '-e', add_file_manifest), acceptable_exit_codes: (0...256)) + end + after :all do + apply_manifest(remove_file_manifest) + end + + it "should return a deprecation error" do + expect(@result.stderr).to match(/Warning: message/) + end + it "should pass without error" do + expect(@result.exit_code).to eq(0) + end + end + end diff --git a/spec/functions/deprecation_spec.rb b/spec/functions/deprecation_spec.rb index 98598339a..cee4f1ca0 100644 --- a/spec/functions/deprecation_spec.rb +++ b/spec/functions/deprecation_spec.rb @@ -41,11 +41,14 @@ } end else + # Puppet version < 4 will use these tests. describe 'deprecation' do after(:all) do ENV.delete('STDLIB_LOG_DEPRECATIONS') end - ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + before(:all) do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + end it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }