Added tests to confirm the existance of #2493; improved
    existing autoload tests (removed inter-test interactions)
    and noted (with a TODO) that there was dead code in the
    feature loading test; added analogus case sensitivity tests
    where apropriate.

Signed-off-by: Markus Roberts <[email protected]>
---
 spec/integration/parser/functions/require.rb |   47 +++++++++++++++
 spec/integration/util/autoload.rb            |   81 ++++++++++++++++----------
 spec/integration/util/feature.rb             |    2 +-
 spec/unit/parser/compiler.rb                 |   10 +++
 4 files changed, 107 insertions(+), 33 deletions(-)

diff --git a/spec/integration/parser/functions/require.rb 
b/spec/integration/parser/functions/require.rb
index 68a1e0b..15ff51b 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 d0858ab..dd9752d 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 f1ddd5d..55a3065 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 0cc6e8a..ad6f351 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)
 
-- 
1.6.0.4


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to