summaryrefslogtreecommitdiffstats
path: root/spec/lib/puppet_spec/files.rb
diff options
context:
space:
mode:
authorJosh Cooper <josh@puppetlabs.com>2011-07-18 23:05:35 -0700
committerJosh Cooper <josh@puppetlabs.com>2011-07-19 14:06:36 -0700
commit462a95e3d077b1915a919399b846068816c84583 (patch)
treef2e260c6d923d49f20a3d6094796aae36ec240fe /spec/lib/puppet_spec/files.rb
parent45ae5b4a9ced26dfcd3e324391f9a26cb02bf93d (diff)
downloadpuppet-462a95e3d077b1915a919399b846068816c84583.tar.gz
puppet-462a95e3d077b1915a919399b846068816c84583.tar.xz
puppet-462a95e3d077b1915a919399b846068816c84583.zip
Fix tests with "relative" paths on Windows
Absolute paths on Unix, e.g. /foo/bar, are not absolute on Windows, which breaks many test cases. This commit adds a method to PuppetSpec::Files.make_absolute that makes the path absolute in test cases. On Unix (Puppet.features.posix?) it is a no-op. On Windows, (Puppet.features.microsoft_windows?) the drive from the current working directory is prepended. Reviewed-by: Jacob Helwig <jacob@puppetlabs.com>
Diffstat (limited to 'spec/lib/puppet_spec/files.rb')
-rwxr-xr-xspec/lib/puppet_spec/files.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb
index 30fb4fc42..9e75d3142 100755
--- a/spec/lib/puppet_spec/files.rb
+++ b/spec/lib/puppet_spec/files.rb
@@ -31,6 +31,16 @@ module PuppetSpec::Files
end
end
+ def make_absolute(path)
+ return path unless Puppet.features.microsoft_windows?
+ # REMIND UNC
+ return path if path =~ /^[A-Za-z]:/
+
+ pwd = Dir.getwd
+ return "#{pwd[0,2]}#{path}" if pwd.length > 2 and pwd =~ /^[A-Za-z]:/
+ return "C:#{path}"
+ end
+
def tmpfile(name)
# Generate a temporary file, just for the name...
source = Tempfile.new(name)