aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--README.md6
-rw-r--r--tests/common.rb3
-rw-r--r--tests/ruby18_hacks.rb55
-rwxr-xr-xtests/stress_test.rb4
-rwxr-xr-xtests/test_bindfs.rb108
-rwxr-xr-xtests/test_concurrent.rb5
7 files changed, 133 insertions, 52 deletions
diff --git a/ChangeLog b/ChangeLog
index 4f7b1a3..e98fd91 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-03-12 Martin Pärtel <martin dot partel at gmail dot com>
+
+ * Made tests work with Ruby 1.8.7 and FUSE 2.8 again (issue #49).
+
2017-02-04 Martin Pärtel <martin dot partel at gmail dot com>
* Deprecated -n as an alias to --no-allow-other (issue #48).
diff --git a/README.md b/README.md
index 8f544f7..601aa7b 100644
--- a/README.md
+++ b/README.md
@@ -56,9 +56,9 @@ The test suite has two kinds of tests: those that have to be run as root and
those that have to be run as non-root. To run all of the tests, do
`make check` both as root and as non-root.
-The test suite requires Ruby 2.0+ (1.9+ might also work). If you're using
-[RVM](https://rvm.io/) then you may need to use `rvmsudo` instead of plain
-`sudo` to run the root tests.
+The test suite requires Ruby 1.8.7+. If you're using [RVM](https://rvm.io/)
+then you may need to use `rvmsudo` instead of plain `sudo` to run the root
+tests.
## License ##
diff --git a/tests/common.rb b/tests/common.rb
index 81d45fc..b3a14e4 100644
--- a/tests/common.rb
+++ b/tests/common.rb
@@ -18,8 +18,9 @@
# along with bindfs. If not, see <http://www.gnu.org/licenses/>.
#
+require 'ruby18_hacks.rb'
+require 'shellwords' unless $ruby_18_hacks_enabled # Ruby 1.8 doesn't have shellwords
require 'fileutils'
-require 'shellwords'
include FileUtils
# Set the default umask for all tests
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
diff --git a/tests/stress_test.rb b/tests/stress_test.rb
index 88804ba..70bf767 100755
--- a/tests/stress_test.rb
+++ b/tests/stress_test.rb
@@ -1,6 +1,8 @@
#!/usr/bin/env ruby
-require './common.rb'
+# if we are being run by make check it will set srcdir and we should use it
+$LOAD_PATH << (ENV['srcdir'] || '.')
+require 'common.rb'
require 'shellwords'
if ARGV.length == 0 || ['-h', '--help'].include?(ARGV[0])
diff --git a/tests/test_bindfs.rb b/tests/test_bindfs.rb
index 96d6660..2badd30 100755
--- a/tests/test_bindfs.rb
+++ b/tests/test_bindfs.rb
@@ -19,12 +19,20 @@
#
# if we are being run by make check it will set srcdir and we should use it
-localsrc_path = ENV['srcdir'] || '.'
+$LOAD_PATH << (ENV['srcdir'] || '.')
-require localsrc_path + '/common.rb'
+require 'common.rb'
include Errno
+$have_fuse_29 = Proc.new do
+ v = `pkg-config --modversion fuse`.split('.')
+ raise "failed to get FUSE version with pkg-config" if v.size < 2
+ v = v.map(&:to_i)
+ v = [2, 8, 0]
+ v[0] > 2 || (v[0] == 2 && v[1] >= 9)
+end.call
+
# FileUtils.chown turned out to be quite buggy in Ruby 1.8.7,
# so we'll use File.chown instead.
def chown(user, group, list)
@@ -619,62 +627,70 @@ testenv("", :title => "many files in a directory") do
assert { Dir.entries('mnt/dir').sort == expected_entries.sort }
end
-testenv("--enable-lock-forwarding --multithreaded", :title => "lock forwarding") do
- File.write('src/file', 'some contents for fcntl lockng')
- # (this test passes with an empty file as well, but this way is clearer)
+if $have_fuse_29
+ testenv("--enable-lock-forwarding --multithreaded", :title => "lock forwarding") do
+ File.write('src/file', 'some contents for fcntl lockng')
+ # (this test passes with an empty file as well, but this way is clearer)
- # flock
- File.open('mnt/file') do |f1|
- File.open('src/file') do |f2|
- assert { f1.flock(File::LOCK_EX | File::LOCK_NB) }
- assert { !f2.flock(File::LOCK_EX | File::LOCK_NB) }
- assert { f1.flock(File::LOCK_UN) }
+ # flock
+ File.open('mnt/file') do |f1|
+ File.open('src/file') do |f2|
+ assert { f1.flock(File::LOCK_EX | File::LOCK_NB) }
+ assert { !f2.flock(File::LOCK_EX | File::LOCK_NB) }
+ assert { f1.flock(File::LOCK_UN) }
- assert { f2.flock(File::LOCK_EX | File::LOCK_NB) }
- assert { !f1.flock(File::LOCK_EX | File::LOCK_NB) }
+ assert { f2.flock(File::LOCK_EX | File::LOCK_NB) }
+ assert { !f1.flock(File::LOCK_EX | File::LOCK_NB) }
+ end
+ assert { f1.flock(File::LOCK_EX | File::LOCK_NB) }
end
- assert { f1.flock(File::LOCK_EX | File::LOCK_NB) }
- end
- # fcntl locking
- system("#{$tests_dir}/fcntl_locker src/file mnt/file")
- raise "fcntl lock sharing test failed" unless $?.success?
-end
+ # fcntl locking
+ system("#{$tests_dir}/fcntl_locker src/file mnt/file")
+ raise "fcntl lock sharing test failed" unless $?.success?
+ end
-testenv("--disable-lock-forwarding", :title => "no lock forwarding") do
- File.write('src/file', 'some contents for fcntl lockng')
+ testenv("--disable-lock-forwarding", :title => "no lock forwarding") do
+ File.write('src/file', 'some contents for fcntl lockng')
- # flock
- File.open('mnt/file') do |f1|
- File.open('src/file') do |f2|
- assert { f1.flock(File::LOCK_EX | File::LOCK_NB) }
- assert { f2.flock(File::LOCK_EX | File::LOCK_NB) }
- end
- File.open('mnt/file') do |f2|
- assert { !f2.flock(File::LOCK_EX | File::LOCK_NB) }
+ # flock
+ File.open('mnt/file') do |f1|
+ File.open('src/file') do |f2|
+ assert { f1.flock(File::LOCK_EX | File::LOCK_NB) }
+ assert { f2.flock(File::LOCK_EX | File::LOCK_NB) }
+ end
+ File.open('mnt/file') do |f2|
+ assert { !f2.flock(File::LOCK_EX | File::LOCK_NB) }
+ end
end
- end
- # fcntl locking
- system("#{$tests_dir}/fcntl_locker src/file mnt/file")
- raise "fcntl lock sharing test failed" unless $?.exitstatus == 1
-end
+ # fcntl locking
+ system("#{$tests_dir}/fcntl_locker src/file mnt/file")
+ raise "fcntl lock sharing test failed" unless $?.exitstatus == 1
+ end
+end # have_fuse_29
# Issue #37
-# Valgrind disabled for ioctl tests since it seems to give a false negative
+#
+# Valgrind is disabled for ioctl tests since it seems to give a false negative
# about a null parameter to ioctl.
-root_testenv("--enable-ioctl", :title => "append-only ioctl", :valgrind => false) do
- touch('mnt/file')
- system('chattr +a mnt/file')
- raise 'chattr +a failed' unless $?.success?
- begin
- File.open('mnt/file', 'a') do |f|
- f.write('stuff')
+#
+# This test is also disabled for old (FUSE < 2.9) systems.
+# TODO: figure out why it doesn't work.
+if $have_fuse_29
+ root_testenv("--enable-ioctl", :title => "append-only ioctl", :valgrind => false) do
+ touch('mnt/file')
+ system('chattr +a mnt/file')
+ raise 'chattr +a failed' unless $?.success?
+ begin
+ File.open('mnt/file', 'a') do |f|
+ f.write('stuff')
+ end
+ assert { File.read('mnt/file') == 'stuff' }
+ assert_exception(EPERM) { File.write('mnt/file', 'newstuff') }
+ ensure
+ system('chattr -a mnt/file')
end
- assert { File.read('mnt/file') == 'stuff' }
- assert_exception(EPERM) { File.write('mnt/file', 'newstuff') }
- ensure
- system('chattr -a mnt/file')
end
end
diff --git a/tests/test_concurrent.rb b/tests/test_concurrent.rb
index f981332..a966139 100755
--- a/tests/test_concurrent.rb
+++ b/tests/test_concurrent.rb
@@ -17,7 +17,10 @@
# You should have received a copy of the GNU General Public License
# along with bindfs. If not, see <http://www.gnu.org/licenses/>.
#
-require './common.rb'
+
+# if we are being run by make check it will set srcdir and we should use it
+$LOAD_PATH << (ENV['srcdir'] || '.')
+require 'common.rb'
raise "Please run this as root" unless Process.uid == 0