aboutsummaryrefslogtreecommitdiffstats
path: root/tests/ruby18_hacks.rb
diff options
context:
space:
mode:
authorMartin Pärtel <martin.partel@gmail.com>2017-03-12 01:03:55 +0000
committerMartin Pärtel <martin.partel@gmail.com>2017-03-12 01:03:55 +0000
commit8437e3fc441ba5e38c57c571ba477237a72ea66d (patch)
tree56d1a4617cbd86e1b80410ee2aba1f8c282050fa /tests/ruby18_hacks.rb
parent040989a14ad2265f4835121fd138654f6424150f (diff)
downloadbindfs-8437e3fc441ba5e38c57c571ba477237a72ea66d.tar.gz
Hacked tests to work with Ruby 1.8.7 and FUSE 2.8 again.
The test suite now passes under Ubuntu 12.04 and CentOS 6. Fixes #49
Diffstat (limited to 'tests/ruby18_hacks.rb')
-rw-r--r--tests/ruby18_hacks.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/ruby18_hacks.rb b/tests/ruby18_hacks.rb
new file mode 100644
index 0000000..fe7ea8c
--- /dev/null
+++ b/tests/ruby18_hacks.rb
@@ -0,0 +1,55 @@
+# Backwards-compatibility hacks for old systems running Ruby 1.8
+
+$ruby_18_hacks_enabled = (RUBY_VERSION =~ /1\.8\..*/)
+
+if $ruby_18_hacks_enabled
+ require 'fileutils'
+ require 'pathname'
+
+ module FileUtils
+ alias_method :original_chmod, :chmod
+ def chmod(perms, path)
+ if perms.is_a?(String)
+ system("chmod " + Shellwords.escape(perms) + " " + Shellwords.escape(path))
+ else
+ original_chmod(perms, path)
+ end
+ end
+ end
+
+ class File
+ def self.realpath(path)
+ Pathname.new(path).realpath.to_s
+ end
+
+ def self.write(path, contents)
+ File.open(path, "wb") do |f|
+ f.write(contents)
+ end
+ end
+ end
+
+ module Shellwords
+ # Copied from http://svn.ruby-lang.org/repos/ruby/trunk/lib/shellwords.rb (GPLv2)
+ # on 2017-03-11
+ def self.escape(str)
+ str = str.to_s
+
+ # An empty argument will be skipped, so return empty quotes.
+ return "''".dup if str.empty?
+
+ str = str.dup
+
+ # Treat multibyte characters as is. It is the caller's responsibility
+ # to encode the string in the right encoding for the shell
+ # environment.
+ str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\1")
+
+ # A LF cannot be escaped with a backslash because a backslash + LF
+ # combo is regarded as a line continuation and simply ignored.
+ str.gsub!(/\n/, "'\n'")
+
+ return str
+ end
+ end
+end