diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-07-10 04:00:28 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-07-10 04:00:28 +0000 |
commit | 7befe1bc5ac9d4524c4c43514a24f1bb19b74727 (patch) | |
tree | 430487cd060d719ab037e1778e1176e163086386 /test/util/autoload.rb | |
parent | eabe0d1c31052c1fa3cb67cd8950d964cb137a19 (diff) | |
download | puppet-7befe1bc5ac9d4524c4c43514a24f1bb19b74727.tar.gz puppet-7befe1bc5ac9d4524c4c43514a24f1bb19b74727.tar.xz puppet-7befe1bc5ac9d4524c4c43514a24f1bb19b74727.zip |
Changing some of the internals of autoloading so that there is a class-level method to query whether a given file has been loaded.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2668 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/util/autoload.rb')
-rwxr-xr-x | test/util/autoload.rb | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/test/util/autoload.rb b/test/util/autoload.rb index 4be6b3930..493fd7f60 100755 --- a/test/util/autoload.rb +++ b/test/util/autoload.rb @@ -30,12 +30,7 @@ TestAutoload.newthing(:#{name.to_s}) end end - def teardown - super - self.class.clear - end - - def test_load + def mk_loader(name) dir = tempfile() $: << dir cleanup do @@ -44,19 +39,26 @@ TestAutoload.newthing(:#{name.to_s}) Dir.mkdir(dir) - rbdir = File.join(dir, "yayness") + rbdir = File.join(dir, name.to_s) Dir.mkdir(rbdir) - # An object for specifying autoload - klass = self.class - loader = nil assert_nothing_raised { - loader = Puppet::Util::Autoload.new(klass, :yayness) + loader = Puppet::Util::Autoload.new(self.class, name) } + return rbdir, loader + end + + def teardown + super + Puppet::Util::Autoload.clear + end + + def test_load + dir, loader = mk_loader(:yayness) - assert_equal(loader.object_id, Puppet::Util::Autoload[klass].object_id, + assert_equal(loader.object_id, Puppet::Util::Autoload[self.class].object_id, "Did not retrieve loader object by class") # Make sure we don't fail on missing files @@ -66,9 +68,9 @@ TestAutoload.newthing(:#{name.to_s}) } # Now create a couple of files for testing - path = File.join(rbdir, "mything.rb") + path = File.join(dir, "mything.rb") mkfile(:mything, path) - opath = File.join(rbdir, "othing.rb") + opath = File.join(dir, "othing.rb") mkfile(:othing, opath) # Now try to actually load it. @@ -79,12 +81,12 @@ TestAutoload.newthing(:#{name.to_s}) assert(loader.loaded?(:mything), "Not considered loaded") - assert(klass.thing?(:mything), + assert(self.class.thing?(:mything), "Did not get loaded thing") # Now clear everything, and test loadall assert_nothing_raised { - loader.clear + Puppet::Util::Autoload.clear } self.class.clear @@ -95,10 +97,23 @@ TestAutoload.newthing(:#{name.to_s}) [:mything, :othing].each do |thing| assert(loader.loaded?(thing), "#{thing.to_s} not considered loaded") + assert(loader.loaded?("%s.rb" % thing), "#{thing.to_s} not considered loaded with .rb") + assert(Puppet::Util::Autoload.loaded?("yayness/%s" % thing), "%s not considered loaded by the main class" % thing) + assert(Puppet::Util::Autoload.loaded?("yayness/%s.rb" % thing), "%s not considered loaded by the main class with .rb" % thing) - assert(klass.thing?(thing), + loaded = Puppet::Util::Autoload.loaded?("yayness/%s.rb" % thing) + assert_equal("%s/%s.rb" % [dir, thing], loaded[:file], "File path was not set correctly in loaded store") + assert_equal(self.class, loaded[:autoloader], "Loader was not set correctly in loaded store") + + assert(self.class.thing?(thing), "Did not get loaded #{thing.to_s}") end + + Puppet::Util::Autoload.clear + [:mything, :othing].each do |thing| + assert(! loader.loaded?(thing), "#{thing.to_s} considered loaded after clear") + assert(! Puppet::Util::Autoload.loaded?("yayness/%s" % thing), "%s considered loaded by the main class after clear" % thing) + end end # Make sure that autoload dynamically modifies $: with the libdir as |