diff options
author | luke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a> | 2006-06-19 18:12:13 +0000 |
---|---|---|
committer | luke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a> | 2006-06-19 18:12:13 +0000 |
commit | 6ac796d179d115df26cc8323abd357851e4da13e (patch) | |
tree | 5c9448d8399764bdb9c69dc156198445635a9f68 | |
parent | 81f451b17575de74157c2df2adf938f20ac49ea9 (diff) | |
download | facter-6ac796d179d115df26cc8323abd357851e4da13e.tar.gz facter-6ac796d179d115df26cc8323abd357851e4da13e.tar.xz facter-6ac796d179d115df26cc8323abd357851e4da13e.zip |
Fixing #15. Just adding rescue blocks around the load statements.
git-svn-id: http://reductivelabs.com/svn/facter/trunk@136 1f5c1d6a-bddf-0310-8f58-fc49e503516a
-rw-r--r-- | lib/facter.rb | 7 | ||||
-rw-r--r-- | tests/tc_simple.rb | 32 |
2 files changed, 38 insertions, 1 deletions
diff --git a/lib/facter.rb b/lib/facter.rb index 20b94bb..c663c8c 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -914,7 +914,12 @@ class Facter # the facts won't get reloaded if someone calls # "loadfacts". Really only important in testing, but, # well, it's important in testing. - load file + begin + load file + rescue => detail + warn "Could not load %s: %s" % + [file, detail] + end end end end diff --git a/tests/tc_simple.rb b/tests/tc_simple.rb index 5155fde..1c3edd5 100644 --- a/tests/tc_simple.rb +++ b/tests/tc_simple.rb @@ -9,16 +9,22 @@ $:.unshift libdir require 'test/unit' require 'facter' +require 'fileutils' if __FILE__ == $0 Facter.debugging(true) end class TestFacter < Test::Unit::TestCase + def tearhook(&block) + @tearhooks << block + end + def setup Facter.loadfacts @tmpfiles = [] + @tearhooks = [] end def teardown @@ -528,6 +534,32 @@ some random stuff assert(! Facter.kernel?("nosuchkernel"), "Fake kernel matched") } end + + # Make sure that facter doesn't fail when it gets bad files. + def test_ignore_bad_files + # Create a broken file + dir = "/tmp/factertest-brokenfile" + @tmpfiles << dir + libdir = File.join(dir, "facter") + + FileUtils.mkdir_p(libdir) + + $: << libdir + tearhook { $:.delete libdir } + + file = File.join(libdir, "file.rb") + + + File.open(file, "w") do |f| + f.puts "asdflkjaeflkj23rljadflkjasdfuhasd8;;lkjadsf;j24iojlkajsdf" + end + + assert_nothing_raised { + Facter.loadfacts() + } + + + end end # $Id$ |