Skip to content

Commit a1b3b73

Browse files
committed
Adjust tests reg. previous commit and symlinks on Windows
This adjust symlink tests on Windows to succeed with developer mode enabled and disabled. Move `symlink_supported?` to be available for other tests. Return `true` only if symlink permission is granted (developer mode enabled).
1 parent 0365027 commit a1b3b73

5 files changed

Lines changed: 58 additions & 42 deletions

File tree

.github/workflows/rubygems.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ on:
44
pull_request:
55

66
push:
7-
branches:
8-
- master
97

108
concurrency:
119
group: ci-${{ github.ref }}-${{ github.workflow }}

test/rubygems/helper.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,24 @@ def nmake_found?
12381238
system("nmake /? 1>NUL 2>&1")
12391239
end
12401240

1241+
@@symlink_supported = nil
1242+
1243+
# This is needed for Windows environment without symlink support enabled (the default
1244+
# for non admin) to be able to skip test for features using symlinks.
1245+
def symlink_supported?
1246+
if @@symlink_supported.nil?
1247+
begin
1248+
File.symlink(File.join(@tempdir, "a"), File.join(@tempdir, "b"))
1249+
File.unlink(File.join(@tempdir, "b"))
1250+
rescue NotImplementedError, SystemCallError
1251+
@@symlink_supported = false
1252+
else
1253+
@@symlink_supported = true
1254+
end
1255+
end
1256+
@@symlink_supported
1257+
end
1258+
12411259
# In case we're building docs in a background process, this method waits for
12421260
# that process to exit (or if it's already been reaped, or never happened,
12431261
# swallows the Errno::ECHILD error).

test/rubygems/installer_test_case.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -238,20 +238,4 @@ def test_ensure_writable_dir_creates_missing_parent_directories
238238
assert_directory_exists target_dir, "Target directory should exist now"
239239
end
240240

241-
@@symlink_supported = nil
242-
243-
# This is needed for Windows environment without symlink support enabled (the default
244-
# for non admin) to be able to skip test for features using symlinks.
245-
def symlink_supported?
246-
if @@symlink_supported.nil?
247-
begin
248-
File.symlink("", "")
249-
rescue Errno::ENOENT, Errno::EEXIST
250-
@@symlink_supported = true
251-
rescue NotImplementedError, SystemCallError
252-
@@symlink_supported = false
253-
end
254-
end
255-
@@symlink_supported
256-
end
257241
end

test/rubygems/test_gem_installer.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,8 +759,12 @@ def test_generate_bin_with_dangling_symlink
759759

760760
errors = @ui.error.split("\n")
761761
assert_equal "WARNING: ascii_binder-0.1.10.1 ships with a dangling symlink named bin/ascii_binder pointing to missing bin/asciibinder file. Ignoring", errors.shift
762-
assert_empty errors
763-
762+
if symlink_supported?
763+
assert_empty errors
764+
else
765+
assert_match(/Unable to use symlinks, installing wrapper/i,
766+
errors.to_s)
767+
end
764768
assert_empty @ui.output
765769
end
766770

test/rubygems/test_gem_package.rb

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def test_add_files_symlink
190190
File.symlink("../lib/code.rb", "lib/code_sym2.rb")
191191
rescue Errno::EACCES => e
192192
if Gem.win_platform?
193-
pend "symlink - must be admin with no UAC on Windows"
193+
pend "symlink - developer mode must be enabled on Windows"
194194
else
195195
raise e
196196
end
@@ -583,25 +583,45 @@ def test_extract_tar_gz_symlink_relative_path
583583
tar.add_symlink "lib/foo.rb", "../relative.rb", 0o644
584584
end
585585

586-
begin
587-
package.extract_tar_gz tgz_io, @destination
588-
rescue Errno::EACCES => e
589-
if Gem.win_platform?
590-
pend "symlink - must be admin with no UAC on Windows"
591-
else
592-
raise e
593-
end
594-
end
586+
package.extract_tar_gz tgz_io, @destination
595587

596588
extracted = File.join @destination, "lib/foo.rb"
597589
assert_path_exist extracted
598-
assert_equal "../relative.rb",
599-
File.readlink(extracted)
590+
if symlink_supported?
591+
assert_equal "../relative.rb",
592+
File.readlink(extracted)
593+
end
600594
assert_equal "hi",
595+
File.read(extracted),
596+
"should read file content either by following symlink or on Windows by reading copy"
597+
end
598+
599+
def test_extract_tar_gz_symlink_directory
600+
package = Gem::Package.new @gem
601+
package.verify
602+
603+
tgz_io = util_tar_gz do |tar|
604+
tar.add_symlink "link", "lib/orig", 0o644
605+
tar.mkdir "lib", 0o755
606+
tar.mkdir "lib/orig", 0o755
607+
tar.add_file "lib/orig/file.rb", 0o644 do |io|
608+
io.write "ok"
609+
end
610+
end
611+
612+
package.extract_tar_gz tgz_io, @destination
613+
extracted = File.join @destination, "link/file.rb"
614+
assert_path_exist extracted
615+
if symlink_supported?
616+
assert_equal "lib/orig",
617+
File.readlink(File.dirname(extracted))
618+
end
619+
assert_equal "ok",
601620
File.read(extracted)
602621
end
603622

604623
def test_extract_symlink_into_symlink_dir
624+
pend "Symlinks not supported or not enabled" unless symlink_supported?
605625
package = Gem::Package.new @gem
606626
tgz_io = util_tar_gz do |tar|
607627
tar.mkdir "lib", 0o755
@@ -665,14 +685,10 @@ def test_extract_symlink_parent
665685
destination_subdir = File.join @destination, "subdir"
666686
FileUtils.mkdir_p destination_subdir
667687

668-
expected_exceptions = Gem.win_platform? ? [Gem::Package::SymlinkError, Errno::EACCES] : [Gem::Package::SymlinkError]
669-
670-
e = assert_raise(*expected_exceptions) do
688+
e = assert_raise(Gem::Package::SymlinkError) do
671689
package.extract_tar_gz tgz_io, destination_subdir
672690
end
673691

674-
pend "symlink - must be admin with no UAC on Windows" if Errno::EACCES === e
675-
676692
assert_equal("installing symlink 'lib/link' pointing to parent path #{@destination} of " \
677693
"#{destination_subdir} is not allowed", e.message)
678694

@@ -700,14 +716,10 @@ def test_extract_symlink_parent_doesnt_delete_user_dir
700716
tar.add_symlink "link/dir", ".", 16_877
701717
end
702718

703-
expected_exceptions = Gem.win_platform? ? [Gem::Package::SymlinkError, Errno::EACCES] : [Gem::Package::SymlinkError]
704-
705-
e = assert_raise(*expected_exceptions) do
719+
e = assert_raise(Gem::Package::SymlinkError) do
706720
package.extract_tar_gz tgz_io, destination_subdir
707721
end
708722

709-
pend "symlink - must be admin with no UAC on Windows" if Errno::EACCES === e
710-
711723
assert_equal("installing symlink 'link' pointing to parent path #{destination_user_dir} of " \
712724
"#{destination_subdir} is not allowed", e.message)
713725

0 commit comments

Comments
 (0)