summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/parser')
-rwxr-xr-xspec/unit/parser/compiler_spec.rb4
-rwxr-xr-xspec/unit/parser/files_spec.rb11
-rwxr-xr-xspec/unit/parser/functions/extlookup_spec.rb9
-rwxr-xr-xspec/unit/parser/functions/sprintf_spec.rb3
-rwxr-xr-xspec/unit/parser/type_loader_spec.rb14
5 files changed, 25 insertions, 16 deletions
diff --git a/spec/unit/parser/compiler_spec.rb b/spec/unit/parser/compiler_spec.rb
index fcce9f6f4..2478d2792 100755
--- a/spec/unit/parser/compiler_spec.rb
+++ b/spec/unit/parser/compiler_spec.rb
@@ -43,6 +43,8 @@ class CompilerTestResource
end
describe Puppet::Parser::Compiler do
+ include PuppetSpec::Files
+
def resource(type, title)
Puppet::Parser::Resource.new(type, title, :scope => @scope)
end
@@ -413,7 +415,7 @@ describe Puppet::Parser::Compiler do
end
it "should fail to add resources that conflict with existing resources" do
- path = Puppet.features.posix? ? "/foo" : "C:/foo"
+ path = make_absolute("/foo")
file1 = Puppet::Type.type(:file).new :path => path
file2 = Puppet::Type.type(:file).new :path => path
diff --git a/spec/unit/parser/files_spec.rb b/spec/unit/parser/files_spec.rb
index 04777f0ec..1bf75e623 100755
--- a/spec/unit/parser/files_spec.rb
+++ b/spec/unit/parser/files_spec.rb
@@ -4,9 +4,10 @@ require 'spec_helper'
require 'puppet/parser/files'
describe Puppet::Parser::Files do
+ include PuppetSpec::Files
before do
- @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath"
+ @basepath = make_absolute("/somepath")
end
it "should have a method for finding a template" do
@@ -77,8 +78,9 @@ describe Puppet::Parser::Files do
it "should accept relative templatedirs" do
FileTest.stubs(:exist?).returns true
Puppet[:templatedir] = "my/templates"
- File.expects(:directory?).with(File.join(Dir.getwd,"my/templates")).returns(true)
- Puppet::Parser::Files.find_template("mytemplate").should == File.join(Dir.getwd,"my/templates/mytemplate")
+ # We expand_path to normalize backslashes and slashes on Windows
+ File.expects(:directory?).with(File.expand_path(File.join(Dir.getwd,"my/templates"))).returns(true)
+ Puppet::Parser::Files.find_template("mytemplate").should == File.expand_path(File.join(Dir.getwd,"my/templates/mytemplate"))
end
it "should use the environment templatedir if no module is found and an environment is specified" do
@@ -158,7 +160,8 @@ describe Puppet::Parser::Files do
end
it "should look for files relative to the current directory" do
- cwd = Dir.getwd
+ # We expand_path to normalize backslashes and slashes on Windows
+ cwd = File.expand_path(Dir.getwd)
Dir.expects(:glob).with("#{cwd}/foobar/init.pp").returns(["#{cwd}/foobar/init.pp"])
Puppet::Parser::Files.find_manifests("foobar/init.pp")[1].should == ["#{cwd}/foobar/init.pp"]
end
diff --git a/spec/unit/parser/functions/extlookup_spec.rb b/spec/unit/parser/functions/extlookup_spec.rb
index f68daaf3f..486e7cb98 100755
--- a/spec/unit/parser/functions/extlookup_spec.rb
+++ b/spec/unit/parser/functions/extlookup_spec.rb
@@ -3,6 +3,8 @@ require 'spec_helper'
require 'tempfile'
describe "the extlookup function" do
+ include PuppetSpec::Files
+
before :all do
Puppet::Parser::Functions.autoloader.loadall
end
@@ -64,9 +66,10 @@ describe "the extlookup function" do
describe "should look in $extlookup_datadir for data files listed by $extlookup_precedence" do
before do
- @scope.stubs(:lookupvar).with('::extlookup_datadir').returns("/tmp")
- File.open("/tmp/one.csv","w"){|one| one.puts "key,value1" }
- File.open("/tmp/two.csv","w") do |two|
+ dir = tmpdir('extlookup_datadir')
+ @scope.stubs(:lookupvar).with('::extlookup_datadir').returns(dir)
+ File.open(File.join(dir, "one.csv"),"w"){|one| one.puts "key,value1" }
+ File.open(File.join(dir, "two.csv"),"w") do |two|
two.puts "key,value2"
two.puts "key2,value_two"
end
diff --git a/spec/unit/parser/functions/sprintf_spec.rb b/spec/unit/parser/functions/sprintf_spec.rb
index bd4863f23..3351c7fb3 100755
--- a/spec/unit/parser/functions/sprintf_spec.rb
+++ b/spec/unit/parser/functions/sprintf_spec.rb
@@ -30,7 +30,8 @@ describe "the sprintf function" do
it "should format large floats" do
result = @scope.function_sprintf(["%+.2e", "27182818284590451"])
- result.should(eql("+2.72e+16"))
+ str = Puppet.features.microsoft_windows? ? "+2.72e+016" : "+2.72e+16"
+ result.should(eql(str))
end
it "should perform more complex formatting" do
diff --git a/spec/unit/parser/type_loader_spec.rb b/spec/unit/parser/type_loader_spec.rb
index 9367b61c8..8b139613a 100755
--- a/spec/unit/parser/type_loader_spec.rb
+++ b/spec/unit/parser/type_loader_spec.rb
@@ -56,8 +56,8 @@ describe Puppet::Parser::TypeLoader do
end
it "should use the directory of the current file if one is set" do
- Puppet::Parser::Files.expects(:find_manifests).with { |pat, opts| opts[:cwd] == "/current" }.returns ["modname", %w{one}]
- @loader.import("myfile", "/current/file")
+ Puppet::Parser::Files.expects(:find_manifests).with { |pat, opts| opts[:cwd] == make_absolute("/current") }.returns ["modname", %w{one}]
+ @loader.import("myfile", make_absolute("/current/file"))
end
it "should pass the environment when looking for files" do
@@ -71,15 +71,15 @@ describe Puppet::Parser::TypeLoader do
end
it "should parse each found file" do
- Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}]
- @loader.expects(:parse_file).with("/one").returns(Puppet::Parser::AST::Hostclass.new(''))
+ Puppet::Parser::Files.expects(:find_manifests).returns ["modname", [make_absolute("/one")]]
+ @loader.expects(:parse_file).with(make_absolute("/one")).returns(Puppet::Parser::AST::Hostclass.new(''))
@loader.import("myfile")
end
it "should make each file qualified before attempting to parse it" do
Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{one}]
- @loader.expects(:parse_file).with("/current/one").returns(Puppet::Parser::AST::Hostclass.new(''))
- @loader.import("myfile", "/current/file")
+ @loader.expects(:parse_file).with(make_absolute("/current/one")).returns(Puppet::Parser::AST::Hostclass.new(''))
+ @loader.import("myfile", make_absolute("/current/file"))
end
it "should not attempt to import files that have already been imported" do
@@ -102,7 +102,7 @@ describe Puppet::Parser::TypeLoader do
@modulebase2 = File.join(@base, "second")
FileUtils.mkdir_p(@modulebase2)
- Puppet[:modulepath] = "#{@modulebase1}:#{@modulebase2}"
+ Puppet[:modulepath] = "#{@modulebase1}#{File::PATH_SEPARATOR}#{@modulebase2}"
end
def mk_module(basedir, name)