@@ -175,6 +175,9 @@ def test_add_files
175175 end
176176
177177 def test_add_files_symlink
178+ unless symlink_supported?
179+ omit ( "symlink - developer mode must be enabled on Windows" )
180+ end
178181 spec = Gem ::Specification . new
179182 spec . files = %w[ lib/code.rb lib/code_sym.rb lib/code_sym2.rb ]
180183
@@ -185,16 +188,8 @@ def test_add_files_symlink
185188 end
186189
187190 # NOTE: 'code.rb' is correct, because it's relative to lib/code_sym.rb
188- begin
189- File . symlink ( "code.rb" , "lib/code_sym.rb" )
190- File . symlink ( "../lib/code.rb" , "lib/code_sym2.rb" )
191- rescue Errno ::EACCES => e
192- if Gem . win_platform?
193- pend "symlink - must be admin with no UAC on Windows"
194- else
195- raise e
196- end
197- end
191+ File . symlink ( "code.rb" , "lib/code_sym.rb" )
192+ File . symlink ( "../lib/code.rb" , "lib/code_sym2.rb" )
198193
199194 package = Gem ::Package . new "bogus.gem"
200195 package . spec = spec
@@ -583,25 +578,45 @@ def test_extract_tar_gz_symlink_relative_path
583578 tar . add_symlink "lib/foo.rb" , "../relative.rb" , 0o644
584579 end
585580
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
581+ package . extract_tar_gz tgz_io , @destination
595582
596583 extracted = File . join @destination , "lib/foo.rb"
597584 assert_path_exist extracted
598- assert_equal "../relative.rb" ,
599- File . readlink ( extracted )
585+ if symlink_supported?
586+ assert_equal "../relative.rb" ,
587+ File . readlink ( extracted )
588+ end
600589 assert_equal "hi" ,
590+ File . read ( extracted ) ,
591+ "should read file content either by following symlink or on Windows by reading copy"
592+ end
593+
594+ def test_extract_tar_gz_symlink_directory
595+ package = Gem ::Package . new @gem
596+ package . verify
597+
598+ tgz_io = util_tar_gz do |tar |
599+ tar . add_symlink "link" , "lib/orig" , 0o644
600+ tar . mkdir "lib" , 0o755
601+ tar . mkdir "lib/orig" , 0o755
602+ tar . add_file "lib/orig/file.rb" , 0o644 do |io |
603+ io . write "ok"
604+ end
605+ end
606+
607+ package . extract_tar_gz tgz_io , @destination
608+ extracted = File . join @destination , "link/file.rb"
609+ assert_path_exist extracted
610+ if symlink_supported?
611+ assert_equal "lib/orig" ,
612+ File . readlink ( File . dirname ( extracted ) )
613+ end
614+ assert_equal "ok" ,
601615 File . read ( extracted )
602616 end
603617
604618 def test_extract_symlink_into_symlink_dir
619+ omit "Symlinks not supported or not enabled" unless symlink_supported?
605620 package = Gem ::Package . new @gem
606621 tgz_io = util_tar_gz do |tar |
607622 tar . mkdir "lib" , 0o755
@@ -665,14 +680,10 @@ def test_extract_symlink_parent
665680 destination_subdir = File . join @destination , "subdir"
666681 FileUtils . mkdir_p destination_subdir
667682
668- expected_exceptions = Gem . win_platform? ? [ Gem ::Package ::SymlinkError , Errno ::EACCES ] : [ Gem ::Package ::SymlinkError ]
669-
670- e = assert_raise ( *expected_exceptions ) do
683+ e = assert_raise ( Gem ::Package ::SymlinkError ) do
671684 package . extract_tar_gz tgz_io , destination_subdir
672685 end
673686
674- pend "symlink - must be admin with no UAC on Windows" if Errno ::EACCES === e
675-
676687 assert_equal ( "installing symlink 'lib/link' pointing to parent path #{ @destination } of " \
677688 "#{ destination_subdir } is not allowed" , e . message )
678689
@@ -700,14 +711,10 @@ def test_extract_symlink_parent_doesnt_delete_user_dir
700711 tar . add_symlink "link/dir" , "." , 16_877
701712 end
702713
703- expected_exceptions = Gem . win_platform? ? [ Gem ::Package ::SymlinkError , Errno ::EACCES ] : [ Gem ::Package ::SymlinkError ]
704-
705- e = assert_raise ( *expected_exceptions ) do
714+ e = assert_raise ( Gem ::Package ::SymlinkError ) do
706715 package . extract_tar_gz tgz_io , destination_subdir
707716 end
708717
709- pend "symlink - must be admin with no UAC on Windows" if Errno ::EACCES === e
710-
711718 assert_equal ( "installing symlink 'link' pointing to parent path #{ destination_user_dir } of " \
712719 "#{ destination_subdir } is not allowed" , e . message )
713720
0 commit comments