From 2fd71112fb5b1aafa5b243c7ac5713cfae7fc23c Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Mon, 12 Oct 2020 21:26:05 +0900 Subject: Make the test suite pass on real Android/Termux environment Attempting to create a hard link raises EACCES --- test/fileutils/test_fileutils.rb | 9 +++++++-- test/pathname/test_pathname.rb | 20 +++++++++++++++++++- test/ruby/test_file_exhaustive.rb | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index 8a546ccf1b..fbc8e3dd83 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -72,8 +72,13 @@ class TestFileUtils < Test::Unit::TestCase end def check_have_hardlink? - File.link nil, nil - rescue NotImplementedError + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + File.write "dummy", "dummy" + File.link "dummy", "hardlink" + end + end + rescue NotImplementedError, Errno::EACCES return false rescue return true diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb index dadcd1398c..43cef4849f 100644 --- a/test/pathname/test_pathname.rb +++ b/test/pathname/test_pathname.rb @@ -345,9 +345,26 @@ class TestPathname < Test::Unit::TestCase def has_symlink? begin File.symlink("", "") - rescue NotImplementedError, Errno::EACCES + rescue NotImplementedError return false rescue Errno::ENOENT + return false + rescue Errno::EACCES + return false + end + return true + end + + def has_hardlink? + begin + with_tmpchdir("rubytest-pathname") {|dir| + File.write("dummy", "dummy") + File.link("dummy", "hardlink") + } + rescue NotImplementedError + return false + rescue Errno::EACCES + return false end return true end @@ -886,6 +903,7 @@ class TestPathname < Test::Unit::TestCase end def test_make_link + return if !has_hardlink? with_tmpchdir('rubytest-pathname') {|dir| open("a", "w") {|f| f.write "abc" } Pathname("l").make_link(Pathname("a")) diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb index 975bcb6bc2..ac11e0cc85 100644 --- a/test/ruby/test_file_exhaustive.rb +++ b/test/ruby/test_file_exhaustive.rb @@ -130,7 +130,7 @@ class TestFileExhaustive < Test::Unit::TestCase @hardlinkfile = make_tmp_filename("hardlinkfile") begin File.link(regular_file, @hardlinkfile) - rescue NotImplementedError, Errno::EINVAL # EINVAL for Windows Vista + rescue NotImplementedError, Errno::EINVAL, Errno::EACCES # EINVAL for Windows Vista, EACCES for Android Termux @hardlinkfile = nil end @hardlinkfile -- cgit v1.2.3