summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/parser/parser_support.rb2
-rwxr-xr-xspec/integration/parser/functions/require.rb47
-rwxr-xr-xspec/integration/util/autoload.rb81
-rwxr-xr-xspec/integration/util/feature.rb2
-rwxr-xr-xspec/unit/parser/compiler.rb10
-rwxr-xr-xspec/unit/parser/parser.rb30
6 files changed, 128 insertions, 44 deletions
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index 4e47cdef4..68cd3825c 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -114,6 +114,8 @@ class Puppet::Parser::Parser
def find_or_load(namespace, name, type)
method = "find_#{type}"
+ namespace = namespace.downcase
+ name = name.downcase
fullname = (namespace + "::" + name).sub(/^::/, '')
names_to_try = [fullname]
diff --git a/spec/integration/parser/functions/require.rb b/spec/integration/parser/functions/require.rb
index 68a1e0b54..15ff51b95 100755
--- a/spec/integration/parser/functions/require.rb
+++ b/spec/integration/parser/functions/require.rb
@@ -25,3 +25,50 @@ describe "the require function" do
end
end
+
+describe "the include function" do
+ require 'puppet_spec/files'
+ include PuppetSpec::Files
+
+ before :each do
+ @real_dir = Dir.getwd
+ @temp_dir = tmpfile('include_function_integration_test')
+ Dir.mkdir @temp_dir
+ Dir.chdir @temp_dir
+ @parser = Puppet::Parser::Parser.new :Code => ""
+ @node = Puppet::Node.new("mynode")
+ @compiler = Puppet::Parser::Compiler.new(@node, @parser)
+ @compiler.send(:evaluate_main)
+ @scope = @compiler.topscope
+ # preload our functions
+ Puppet::Parser::Functions.function(:include)
+ Puppet::Parser::Functions.function(:require)
+ end
+
+ after :each do
+ Dir.chdir @real_dir
+ Dir.rmdir @temp_dir
+ end
+
+ def with_file(filename,contents)
+ path = File.join(@temp_dir,filename)
+ File.open(path, "w") { |f|f.puts contents }
+ yield
+ File.delete(path)
+ end
+
+ it "should add a relationship between the 'included' class and our class" do
+ with_file('includedclass',"class includedclass {}") {
+ @scope.function_include("includedclass")
+ }
+ @compiler.catalog.edge?(@scope.resource,@compiler.findresource(:class,"includedclass")).should be_true
+ end
+
+ it "should find a file with an all lowercase name given a mixed case name" do
+ with_file('includedclass',"class includedclass {}") {
+ @scope.function_include("includedclass")
+ }
+ @compiler.catalog.edge?(@scope.resource,@compiler.findresource(:class,"IncludedClass")).should be_true
+ end
+
+end
diff --git a/spec/integration/util/autoload.rb b/spec/integration/util/autoload.rb
index d0858abfa..dd9752d01 100755
--- a/spec/integration/util/autoload.rb
+++ b/spec/integration/util/autoload.rb
@@ -24,27 +24,28 @@ require 'puppet_spec/files'
describe Puppet::Util::Autoload do
include PuppetSpec::Files
- def mkfile(name, path)
+ def with_file(name, *path)
+ path = File.join(*path)
# Now create a file to load
- File.open(path, "w") do |f|
- f.puts %{
-AutoloadIntegrator.newthing(:#{name.to_s})
+ File.open(path, "w") { |f|
+ f.puts "\nAutoloadIntegrator.newthing(:#{name.to_s})\n"
}
- end
+ yield
+ File.delete(path)
end
- def mk_loader(name, path)
+ def with_loader(name, path)
dir = tmpfile(name + path)
$: << dir
-
Dir.mkdir(dir)
-
rbdir = File.join(dir, path.to_s)
-
Dir.mkdir(rbdir)
-
loader = Puppet::Util::Autoload.new(name, path)
- return rbdir, loader
+ yield rbdir, loader
+ Dir.rmdir(rbdir)
+ Dir.rmdir(dir)
+ $:.pop
+ AutoloadIntegrator.clear
end
it "should make instances available by the loading class" do
@@ -57,35 +58,51 @@ AutoloadIntegrator.newthing(:#{name.to_s})
end
it "should load and return true when it successfully loads a file" do
- dir, loader = mk_loader("foo", "bar")
- path = File.join(dir, "mything.rb")
- mkfile(:mything, path)
- loader.load(:mything).should be_true
- loader.should be_loaded(:mything)
- AutoloadIntegrator.should be_thing(:mything)
+ with_loader("foo", "bar") { |dir,loader|
+ with_file(:mything, dir, "mything.rb") {
+ loader.load(:mything).should be_true
+ loader.should be_loaded(:mything)
+ AutoloadIntegrator.should be_thing(:mything)
+ }
+ }
+ end
+
+ it "should successfully load a file with a mixed case name" do
+ on_disk = "MyThing.rb"
+ in_code = :mything
+ with_loader("foo", "bar") { |dir,loader|
+ with_file(in_code, dir, on_disk) {
+ loader.load(in_code).should be_true
+ loader.should be_loaded(in_code)
+ AutoloadIntegrator.should be_thing(in_code)
+ }
+ }
end
it "should consider a file loaded when asked for the name without an extension" do
- dir, loader = mk_loader("foo", "bar")
- path = File.join(dir, "noext.rb")
- mkfile(:noext, path)
- loader.load(:noext)
- loader.should be_loaded(:noext)
+ with_loader("foo", "bar") { |dir,loader|
+ with_file(:noext, dir, "noext.rb") {
+ loader.load(:noext)
+ loader.should be_loaded(:noext)
+ }
+ }
end
it "should consider a file loaded when asked for the name with an extension" do
- dir, loader = mk_loader("foo", "bar")
- path = File.join(dir, "withext.rb")
- mkfile(:noext, path)
- loader.load(:withext)
- loader.should be_loaded("withext.rb")
+ with_loader("foo", "bar") { |dir,loader|
+ with_file(:noext, dir, "withext.rb") {
+ loader.load(:withext)
+ loader.should be_loaded("withext.rb")
+ }
+ }
end
it "should register the fact that the instance is loaded with the Autoload base class" do
- dir, loader = mk_loader("foo", "bar")
- path = File.join(dir, "baseload.rb")
- mkfile(:baseload, path)
- loader.load(:baseload)
- Puppet::Util::Autoload.should be_loaded("bar/withext.rb")
+ with_loader("foo", "bar") { |dir,loader|
+ with_file(:baseload, dir, "baseload.rb") {
+ loader.load(:baseload)
+ Puppet::Util::Autoload.should be_loaded("bar/withext.rb")
+ }
+ }
end
end
diff --git a/spec/integration/util/feature.rb b/spec/integration/util/feature.rb
index f1ddd5d43..55a30657a 100755
--- a/spec/integration/util/feature.rb
+++ b/spec/integration/util/feature.rb
@@ -25,7 +25,7 @@ describe Puppet::Util::Feature do
$features.should be_able_to_load
end
-
+ # TODO: Make this a spec test or remove it.
def test_dynamic_loading
$features = @features
cleanup { $features = nil }
diff --git a/spec/unit/parser/compiler.rb b/spec/unit/parser/compiler.rb
index 0cc6e8a17..ad6f351bf 100755
--- a/spec/unit/parser/compiler.rb
+++ b/spec/unit/parser/compiler.rb
@@ -423,6 +423,16 @@ describe Puppet::Parser::Compiler do
@compiler.evaluate_classes(%w{myclass}, @scope, false)
end
+ it "should skip classes previously evaluated with different capitalization" do
+ @compiler.catalog.stubs(:tag)
+ @scope.stubs(:find_hostclass).with("MyClass").returns(@class)
+ @compiler.expects(:class_scope).with(@class).returns("something")
+ @compiler.expects(:add_resource).never
+ @resource.expects(:evaluate).never
+ Puppet::Parser::Resource.expects(:new).never
+ @compiler.evaluate_classes(%w{MyClass}, @scope, false)
+ end
+
it "should return the list of found classes" do
@compiler.catalog.stubs(:tag)
diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
index 75d0c05a3..ff14e205c 100755
--- a/spec/unit/parser/parser.rb
+++ b/spec/unit/parser/parser.rb
@@ -346,32 +346,40 @@ describe Puppet::Parser do
describe Puppet::Parser,"when looking up names" do
before :each do
@loaded_code = mock 'loaded code'
- @loaded_code.stubs(:find_my_type).with('Loaded_namespace', 'Loaded_name').returns(true)
- @loaded_code.stubs(:find_my_type).with('Bogus_namespace', 'Bogus_name' ).returns(false)
+ @loaded_code.stubs(:find_my_type).with('loaded_namespace', 'loaded_name').returns(true)
+ @loaded_code.stubs(:find_my_type).with('bogus_namespace', 'bogus_name' ).returns(false)
@parser = Puppet::Parser::Parser.new :environment => "development",:loaded_code => @loaded_code
end
describe "that are already loaded" do
it "should not try to load anything" do
@parser.expects(:load).never
- @parser.find_or_load("Loaded_namespace","Loaded_name",:my_type)
+ @parser.find_or_load("loaded_namespace","loaded_name",:my_type)
end
it "should return true" do
- @parser.find_or_load("Loaded_namespace","Loaded_name",:my_type).should == true
+ @parser.find_or_load("loaded_namespace","loaded_name",:my_type).should == true
end
end
describe "that aren't already loaded" do
- it "should first attempt to load them with the fully qualified name" do
- @loaded_code.stubs(:find_my_type).with("Foo_namespace","Foo_name").returns(false,true,true)
- @parser.expects(:load).with("Foo_namespace::Foo_name").returns(true).then.raises(Exception)
+ it "should first attempt to load them with the all lowercase fully qualified name" do
+ @loaded_code.stubs(:find_my_type).with("foo_namespace","foo_name").returns(false,true,true)
+ @parser.expects(:load).with("foo_namespace::foo_name").returns(true).then.raises(Exception)
@parser.find_or_load("Foo_namespace","Foo_name",:my_type).should == true
end
- it "should next attempt to load them with the namespace" do
- @loaded_code.stubs(:find_my_type).with("Foo_namespace","Foo_name").returns(false,false,true,true)
- @parser.expects(:load).with("Foo_namespace::Foo_name").returns(false).then.raises(Exception)
- @parser.expects(:load).with("Foo_namespace").returns(true).then.raises(Exception)
+ it "should next attempt to load them with the all lowercase namespace" do
+ @loaded_code.stubs(:find_my_type).with("foo_namespace","foo_name").returns(false,false,true,true)
+ @parser.expects(:load).with("foo_namespace::foo_name").returns(false).then.raises(Exception)
+ @parser.expects(:load).with("foo_namespace" ).returns(true ).then.raises(Exception)
+ @parser.find_or_load("Foo_namespace","Foo_name",:my_type).should == true
+ end
+
+ it "should finally attempt to load them with the all lowercase unqualified name" do
+ @loaded_code.stubs(:find_my_type).with("foo_namespace","foo_name").returns(false,false,false,true,true)
+ @parser.expects(:load).with("foo_namespace::foo_name").returns(false).then.raises(Exception)
+ @parser.expects(:load).with("foo_namespace" ).returns(false).then.raises(Exception)
+ @parser.expects(:load).with( "foo_name").returns(true ).then.raises(Exception)
@parser.find_or_load("Foo_namespace","Foo_name",:my_type).should == true
end