summaryrefslogtreecommitdiffstats
path: root/test/other/autoload.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-02-08 05:11:49 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-02-08 05:11:49 +0000
commit1756bec99b9136463e5d35f1de4119b813ce40cc (patch)
tree380c1f37b2238fd37842a3b9934f6be16f36b450 /test/other/autoload.rb
parenta216df2bcb304ad379e152f2f59ef7d942f54f3b (diff)
downloadpuppet-1756bec99b9136463e5d35f1de4119b813ce40cc.tar.gz
puppet-1756bec99b9136463e5d35f1de4119b813ce40cc.tar.xz
puppet-1756bec99b9136463e5d35f1de4119b813ce40cc.zip
Fixing #484. Moving unit tests at the same time.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2181 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/other/autoload.rb')
-rwxr-xr-xtest/other/autoload.rb130
1 files changed, 0 insertions, 130 deletions
diff --git a/test/other/autoload.rb b/test/other/autoload.rb
deleted file mode 100755
index 34f40df24..000000000
--- a/test/other/autoload.rb
+++ /dev/null
@@ -1,130 +0,0 @@
-#!/usr/bin/env ruby
-
-$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
-
-require 'puppet'
-require 'puppet/util/autoload'
-require 'puppettest'
-
-class TestAutoload < Test::Unit::TestCase
- include PuppetTest
- @things = []
- def self.newthing(name)
- @things << name
- end
-
- def self.thing?(name)
- @things.include? name
- end
-
- def self.clear
- @things.clear
- end
-
- def mkfile(name, path)
- # Now create a file to load
- File.open(path, "w") do |f|
- f.puts %{
-TestAutoload.newthing(:#{name.to_s})
- }
- end
- end
-
- def teardown
- super
- self.class.clear
- end
-
- def test_load
- dir = tempfile()
- $: << dir
- cleanup do
- $:.delete(dir)
- end
-
- Dir.mkdir(dir)
-
- rbdir = File.join(dir, "yayness")
-
- Dir.mkdir(rbdir)
-
- # An object for specifying autoload
- klass = self.class
-
- loader = nil
- assert_nothing_raised {
- loader = Puppet::Util::Autoload.new(klass, :yayness)
- }
-
- assert_equal(loader.object_id, Puppet::Util::Autoload[klass].object_id,
- "Did not retrieve loader object by class")
-
- # Make sure we don't fail on missing files
- assert_nothing_raised {
- assert_equal(false, loader.load(:mything),
- "got incorrect return on failed load")
- }
-
- # Now create a couple of files for testing
- path = File.join(rbdir, "mything.rb")
- mkfile(:mything, path)
- opath = File.join(rbdir, "othing.rb")
- mkfile(:othing, opath)
-
- # Now try to actually load it.
- assert_nothing_raised {
- assert_equal(true, loader.load(:mything),
- "got incorrect return on failed load")
- }
-
- assert(loader.loaded?(:mything), "Not considered loaded")
-
- assert(klass.thing?(:mything),
- "Did not get loaded thing")
-
- # Now clear everything, and test loadall
- assert_nothing_raised {
- loader.clear
- }
-
- self.class.clear
-
- assert_nothing_raised {
- loader.loadall
- }
-
- [:mything, :othing].each do |thing|
- assert(loader.loaded?(thing), "#{thing.to_s} not considered loaded")
-
- assert(klass.thing?(thing),
- "Did not get loaded #{thing.to_s}")
- end
- end
-
- # Make sure that autoload dynamically modifies $: with the libdir as
- # appropriate.
- def test_autoload_uses_libdir
- dir = Puppet[:libdir]
- unless FileTest.directory?(dir)
- Dir.mkdir(dir)
- end
-
- loader = File.join(dir, "test")
- Dir.mkdir(loader)
- name = "funtest"
- file = File.join(loader, "funtest.rb")
- File.open(file, "w") do |f|
- f.puts "$loaded = true"
- end
-
- auto = Puppet::Util::Autoload.new(self, "test")
-
- # Now make sure autoloading modifies $: as necessary
- assert(! $:.include?(dir), "search path already includes libdir")
-
- assert_nothing_raised do
- assert(auto.load("funtest"), "did not successfully load funtest")
- end
- assert($:.include?(dir), "libdir did not get added to search path")
- end
-end