summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2011-03-25 16:10:03 -0700
committerJesse Wolfe <jes5199@gmail.com>2011-03-25 16:10:03 -0700
commita2ac367c2bea2b94b88f739250edb828da0091d4 (patch)
treec8abe56ae0baf82ef51c5a27a3814bec42a8f890
parent0fec21fcd887685cf8421fdc309b878088f9fc48 (diff)
parent7c60db5d9db8eeda46f7041100759e69aed120a8 (diff)
downloadpuppet-a2ac367c2bea2b94b88f739250edb828da0091d4.tar.gz
puppet-a2ac367c2bea2b94b88f739250edb828da0091d4.tar.xz
puppet-a2ac367c2bea2b94b88f739250edb828da0091d4.zip
Merge branch 'ticket/2.6.next/5477' into 2.6.next
-rw-r--r--lib/puppet/parser/lexer.rb5
-rw-r--r--lib/puppet/parser/parser_support.rb1
-rw-r--r--lib/puppet/resource/type_collection.rb1
-rw-r--r--lib/puppet/simple_graph.rb2
-rwxr-xr-xlib/puppet/util/loadedfile.rb6
-rwxr-xr-xspec/unit/parser/lexer_spec.rb12
-rw-r--r--spec/unit/resource/type_collection_spec.rb31
-rwxr-xr-xspec/unit/util/loadedfile_spec.rb7
-rwxr-xr-xspec/unit/util/rdoc/parser_spec.rb3
9 files changed, 40 insertions, 28 deletions
diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb
index 9a25263f6..71d9440ff 100644
--- a/lib/puppet/parser/lexer.rb
+++ b/lib/puppet/parser/lexer.rb
@@ -312,7 +312,8 @@ class Puppet::Parser::Lexer
def file=(file)
@file = file
@line = 1
- @scanner = StringScanner.new(File.read(file))
+ contents = File.exists?(file) ? File.read(file) : ""
+ @scanner = StringScanner.new(contents)
end
def shift_token
@@ -547,7 +548,7 @@ class Puppet::Parser::Lexer
value,terminator = slurpstring('"$')
token_queue << [TOKENS[token_type[terminator]],preamble+value]
if terminator != '$' or @scanner.scan(/\{/)
- token_queue.shift
+ token_queue.shift
elsif var_name = @scanner.scan(%r{(\w*::)*\w+|[0-9]})
token_queue << [TOKENS[:VARIABLE],var_name]
tokenize_interpolated_string(DQ_continuation_token_types)
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index 7a0aa2601..9e580efb2 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -88,7 +88,6 @@ class Puppet::Parser::Parser
unless file =~ /\.pp$/
file = file + ".pp"
end
- raise Puppet::Error, "Could not find file #{file}" unless FileTest.exist?(file)
end
raise Puppet::AlreadyImportedError, "Import loop detected" if known_resource_types.watching_file?(file)
diff --git a/lib/puppet/resource/type_collection.rb b/lib/puppet/resource/type_collection.rb
index 277d37b18..347e1c0e0 100644
--- a/lib/puppet/resource/type_collection.rb
+++ b/lib/puppet/resource/type_collection.rb
@@ -162,7 +162,6 @@ class Puppet::Resource::TypeCollection
parser.string = code
else
file = Puppet.settings.value(:manifest, environment.to_s)
- return unless File.exist?(file)
parser.file = file
end
parser.parse
diff --git a/lib/puppet/simple_graph.rb b/lib/puppet/simple_graph.rb
index c5dac0f6c..c658b3b92 100644
--- a/lib/puppet/simple_graph.rb
+++ b/lib/puppet/simple_graph.rb
@@ -329,7 +329,7 @@ class Puppet::SimpleGraph
children = other.adjacent(container, :direction => :out)
# MQR TODO: Luke suggests that it should be possible to refactor the system so that
- # container nodes are retained, thus obviating the need for the whit.
+ # container nodes are retained, thus obviating the need for the whit.
children = [whit_class.new(:name => container.name, :catalog => other)] if children.empty?
# First create new edges for each of the :in edges
diff --git a/lib/puppet/util/loadedfile.rb b/lib/puppet/util/loadedfile.rb
index 735dba459..d2f5d0923 100755
--- a/lib/puppet/util/loadedfile.rb
+++ b/lib/puppet/util/loadedfile.rb
@@ -34,10 +34,6 @@ module Puppet
# Create the file. Must be passed the file path.
def initialize(file)
@file = file
- unless FileTest.exists?(@file)
- raise Puppet::NoSuchFile,
- "Can not use a non-existent file for parsing"
- end
@statted = 0
@stamp = nil
@tstamp = stamp
@@ -50,7 +46,7 @@ module Puppet
@statted = Time.now.to_i
begin
@stamp = File.stat(@file).ctime
- rescue Errno::ENOENT
+ rescue Errno::ENOENT, Errno::ENOTDIR
@stamp = Time.now
end
end
diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb
index 4ef242cf5..d144504c5 100755
--- a/spec/unit/parser/lexer_spec.rb
+++ b/spec/unit/parser/lexer_spec.rb
@@ -679,3 +679,15 @@ describe "Puppet::Parser::Lexer in the old tests when lexing example files" do
end
end
end
+
+describe "when trying to lex an non-existent file" do
+ include PuppetSpec::Files
+
+ it "should return an empty list of tokens" do
+ lexer = Puppet::Parser::Lexer.new
+ lexer.file = nofile = tmpfile('lexer')
+ File.exists?(nofile).should == false
+
+ lexer.fullscan.should == [[false,false]]
+ end
+end
diff --git a/spec/unit/resource/type_collection_spec.rb b/spec/unit/resource/type_collection_spec.rb
index ff4c22234..cf7039a51 100644
--- a/spec/unit/resource/type_collection_spec.rb
+++ b/spec/unit/resource/type_collection_spec.rb
@@ -6,6 +6,7 @@ require 'puppet/resource/type_collection'
require 'puppet/resource/type'
describe Puppet::Resource::TypeCollection do
+ include PuppetSpec::Files
before do
@instance = Puppet::Resource::Type.new(:hostclass, "foo")
@code = Puppet::Resource::TypeCollection.new("env")
@@ -276,7 +277,7 @@ describe Puppet::Resource::TypeCollection do
end
end
-
+
it "should not look in the local scope for classes when the name is qualified" do
@loader = Puppet::Resource::TypeCollection.new("env")
@loader.add Puppet::Resource::Type.new(:hostclass, "foo::bar")
@@ -386,16 +387,11 @@ describe Puppet::Resource::TypeCollection do
describe "when performing initial import" do
before do
- @parser = stub 'parser', :file= => nil, :string => nil, :parse => nil
+ @parser = stub 'parser'
Puppet::Parser::Parser.stubs(:new).returns @parser
@code = Puppet::Resource::TypeCollection.new("env")
end
- it "should create a new parser instance" do
- Puppet::Parser::Parser.expects(:new).returns @parser
- @code.perform_initial_import
- end
-
it "should set the parser's string to the 'code' setting and parse if code is available" do
Puppet.settings[:code] = "my code"
@parser.expects(:string=).with "my code"
@@ -404,26 +400,27 @@ describe Puppet::Resource::TypeCollection do
end
it "should set the parser's file to the 'manifest' setting and parse if no code is available and the manifest is available" do
- File.stubs(:expand_path).with("/my/file").returns "/my/file"
- File.expects(:exist?).with("/my/file").returns true
- Puppet.settings[:manifest] = "/my/file"
- @parser.expects(:file=).with "/my/file"
+ filename = tmpfile('myfile')
+ File.open(filename, 'w'){|f| }
+ Puppet.settings[:manifest] = filename
+ @parser.expects(:file=).with filename
@parser.expects(:parse)
@code.perform_initial_import
end
- it "should not attempt to load a manifest if none is present" do
- File.stubs(:expand_path).with("/my/file").returns "/my/file"
- File.expects(:exist?).with("/my/file").returns false
- Puppet.settings[:manifest] = "/my/file"
- @parser.expects(:file=).never
- @parser.expects(:parse).never
+ it "should pass the manifest file to the parser even if it does not exist on disk" do
+ filename = tmpfile('myfile')
+ Puppet.settings[:code] = ""
+ Puppet.settings[:manifest] = filename
+ @parser.expects(:file=).with(filename).once
+ @parser.expects(:parse).once
@code.perform_initial_import
end
it "should fail helpfully if there is an error importing" do
File.stubs(:exist?).returns true
@parser.expects(:parse).raises ArgumentError
+ @parser.stubs(:file=)
lambda { @code.perform_initial_import }.should raise_error(Puppet::Error)
end
end
diff --git a/spec/unit/util/loadedfile_spec.rb b/spec/unit/util/loadedfile_spec.rb
index 3bc26a421..c6fd625fc 100755
--- a/spec/unit/util/loadedfile_spec.rb
+++ b/spec/unit/util/loadedfile_spec.rb
@@ -6,6 +6,7 @@ require 'tempfile'
require 'puppet/util/loadedfile'
describe Puppet::Util::LoadedFile do
+ include PuppetSpec::Files
before(:each) do
@f = Tempfile.new('loadedfile_test')
@f.puts "yayness"
@@ -18,6 +19,12 @@ describe Puppet::Util::LoadedFile do
@fake_now = Time.now + (2 * Puppet[:filetimeout])
end
+ it "should accept files that don't exist" do
+ nofile = tmpfile('testfile')
+ File.exists?(nofile).should == false
+ lambda{ Puppet::Util::LoadedFile.new(nofile) }.should_not raise_error
+ end
+
it "should recognize when the file has not changed" do
# Use fake "now" so that we can be sure changed? actually checks, without sleeping
# for Puppet[:filetimeout] seconds.
diff --git a/spec/unit/util/rdoc/parser_spec.rb b/spec/unit/util/rdoc/parser_spec.rb
index b4453ae86..6ae28b40a 100755
--- a/spec/unit/util/rdoc/parser_spec.rb
+++ b/spec/unit/util/rdoc/parser_spec.rb
@@ -20,8 +20,9 @@ describe RDoc::Parser do
@parser.stubs(:scan_top_level)
parser = stub 'parser'
Puppet::Parser::Parser.stubs(:new).returns(parser)
- parser.expects(:parse)
+ parser.expects(:parse).at_least_once
parser.expects(:file=).with("module/manifests/init.pp")
+ parser.expects(:file=).with("/dev/null/manifests/site.pp")
@parser.scan
end