From ccc869ea48397235d7ba2a5695424eee4923cb9d Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Thu, 10 Jun 2010 22:51:12 -0700 Subject: Part 2 of fix for #1175 (functions in environments) Jesse and I are shooting for the minimal viable fix here, with the idea that a great deal of refactoring is needed but isn't appropriate at this time. The changes in this commit are: * Index the function-holding modules by environment * We need to know the "current environment" when we're defining a function so we can attach it to the proper module, and this information isn't dynamically available when user-defined functions are being created (we're being called by user written code that doesn't "know" about environments) so we cheat and stash the value in Puppet::Node::Environment * since we must do this anyway, it turns out to be cleaner & safer to do the same when we are evaluating a functon. This is the main change from the prior version of this patch. * Add a special *root* environment for the built in functions, and extend all scopes with it. * Index the function characteristics (name, type, docstring, etc.) by environment * Make the autoloader environment aware, so that it uses the modulepath for the specified environment rather than the default * Turn off caching of the modulepath since it potentially changes for each node * Tweak tests that weren't environment aware --- spec/unit/parser/functions/defined.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/unit/parser/functions') diff --git a/spec/unit/parser/functions/defined.rb b/spec/unit/parser/functions/defined.rb index 0da8c4a31..03b0ef9dd 100755 --- a/spec/unit/parser/functions/defined.rb +++ b/spec/unit/parser/functions/defined.rb @@ -5,9 +5,9 @@ require File.dirname(__FILE__) + '/../../../spec_helper' describe "the 'defined' function" do before :each do - @scope = Puppet::Parser::Scope.new() + Puppet::Node::Environment.stubs(:current).returns(nil) @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo")) - @scope.compiler = @compiler + @scope = Puppet::Parser::Scope.new(:compiler => @compiler) end it "should exist" do -- cgit