@@ -928,17 +928,19 @@ def test_expand_path_encoding
928928
929929 def test_expand_path_encoding_filesystem
930930 omit "global side effects" if multiple_ractors?
931- home = ENV [ "HOME" ]
932- ENV [ "HOME" ] = "#{ DRIVE } /UserHome"
931+ begin
932+ home = ENV [ "HOME" ]
933+ ENV [ "HOME" ] = "#{ DRIVE } /UserHome"
933934
934- path = "~" . encode ( "US-ASCII" )
935- dir = "C:/" . encode ( "IBM437" )
936- fs = Encoding . find ( "filesystem" )
935+ path = "~" . encode ( "US-ASCII" )
936+ dir = "C:/" . encode ( "IBM437" )
937+ fs = Encoding . find ( "filesystem" )
937938
938- assert_equal fs , File . expand_path ( path ) . encoding
939- assert_equal fs , File . expand_path ( path , dir ) . encoding
940- ensure
941- ENV [ "HOME" ] = home if home
939+ assert_equal fs , File . expand_path ( path ) . encoding
940+ assert_equal fs , File . expand_path ( path , dir ) . encoding
941+ ensure
942+ ENV [ "HOME" ] = home
943+ end
942944 end
943945
944946 UnknownUserHome = "~foo_bar_baz_unknown_user_wahaha" . freeze
@@ -963,31 +965,31 @@ def test_expand_path_home
963965 ENV [ "HOME" ] = "."
964966 assert_raise ( ArgumentError , bug3630 ) { File . expand_path ( "~" ) }
965967 ensure
966- if home
967- ENV [ "HOME" ] = home
968- ENV [ "HOMEDRIVE" ] = home_drive
969- ENV [ "HOMEPATH" ] = home_path
970- ENV [ "USERPROFILE" ] = user_profile
971- end
968+ ENV [ "HOME" ] = home
969+ ENV [ "HOMEDRIVE" ] = home_drive
970+ ENV [ "HOMEPATH" ] = home_path
971+ ENV [ "USERPROFILE" ] = user_profile
972972 end
973973 end
974974
975975 def test_expand_path_home_dir_string
976976 omit "global side effects" if multiple_ractors?
977- home = ENV [ "HOME" ]
978- new_home = "#{ DRIVE } /UserHome"
979- ENV [ "HOME" ] = new_home
980- bug8034 = "[ruby-core:53168]"
981-
982- assert_equal File . join ( new_home , "foo" ) , File . expand_path ( "foo" , "~" ) , bug8034
983- assert_equal File . join ( new_home , "bar" , "foo" ) , File . expand_path ( "foo" , "~/bar" ) , bug8034
984-
985- assert_raise ( ArgumentError ) { File . expand_path ( "." , UnknownUserHome ) }
986- assert_nothing_raised ( ArgumentError ) { File . expand_path ( "#{ DRIVE } /" , UnknownUserHome ) }
987- ENV [ "HOME" ] = "#{ DRIVE } UserHome"
988- assert_raise ( ArgumentError ) { File . expand_path ( "~" ) }
989- ensure
990- ENV [ "HOME" ] = home if home
977+ begin
978+ home = ENV [ "HOME" ]
979+ new_home = "#{ DRIVE } /UserHome"
980+ ENV [ "HOME" ] = new_home
981+ bug8034 = "[ruby-core:53168]"
982+
983+ assert_equal File . join ( new_home , "foo" ) , File . expand_path ( "foo" , "~" ) , bug8034
984+ assert_equal File . join ( new_home , "bar" , "foo" ) , File . expand_path ( "foo" , "~/bar" ) , bug8034
985+
986+ assert_raise ( ArgumentError ) { File . expand_path ( "." , UnknownUserHome ) }
987+ assert_nothing_raised ( ArgumentError ) { File . expand_path ( "#{ DRIVE } /" , UnknownUserHome ) }
988+ ENV [ "HOME" ] = "#{ DRIVE } UserHome"
989+ assert_raise ( ArgumentError ) { File . expand_path ( "~" ) }
990+ ensure
991+ ENV [ "HOME" ] = home
992+ end
991993 end
992994
993995 if /mswin|mingw/ =~ RUBY_PLATFORM
@@ -1110,33 +1112,39 @@ def test_expand_path_converts_a_pathname_which_starts_with_a_slash_using_a_curre
11101112
11111113 def test_expand_path_converts_a_pathname_to_an_absolute_pathname_using_home_as_base
11121114 omit "global side effects" if multiple_ractors?
1113- old_home = ENV [ "HOME" ]
1114- home = ENV [ "HOME" ] = "#{ DRIVE } /UserHome"
1115- assert_equal ( home , File . expand_path ( "~" ) )
1116- assert_equal ( home , File . expand_path ( "~" , "C:/FooBar" ) )
1117- assert_equal ( File . join ( home , "a" ) , File . expand_path ( "~/a" , "C:/FooBar" ) )
1118- ensure
1119- ENV [ "HOME" ] = old_home if old_home
1115+ begin
1116+ old_home = ENV [ "HOME" ]
1117+ home = ENV [ "HOME" ] = "#{ DRIVE } /UserHome"
1118+ assert_equal ( home , File . expand_path ( "~" ) )
1119+ assert_equal ( home , File . expand_path ( "~" , "C:/FooBar" ) )
1120+ assert_equal ( File . join ( home , "a" ) , File . expand_path ( "~/a" , "C:/FooBar" ) )
1121+ ensure
1122+ ENV [ "HOME" ] = old_home
1123+ end
11201124 end
11211125
11221126 def test_expand_path_converts_a_pathname_to_an_absolute_pathname_using_unc_home
11231127 omit "global side effects" if multiple_ractors?
1124- old_home = ENV [ "HOME" ]
1125- unc_home = ENV [ "HOME" ] = "//UserHome"
1126- assert_equal ( unc_home , File . expand_path ( "~" ) )
1127- ensure
1128- ENV [ "HOME" ] = old_home if old_home
1128+ begin
1129+ old_home = ENV [ "HOME" ]
1130+ unc_home = ENV [ "HOME" ] = "//UserHome"
1131+ assert_equal ( unc_home , File . expand_path ( "~" ) )
1132+ ensure
1133+ ENV [ "HOME" ] = old_home
1134+ end
11291135 end if DRIVE
11301136
11311137 def test_expand_path_does_not_modify_a_home_string_argument
11321138 omit "global side effects" if multiple_ractors?
1133- old_home = ENV [ "HOME" ]
1134- home = ENV [ "HOME" ] = "#{ DRIVE } /UserHome"
1135- str = "~/a"
1136- assert_equal ( "#{ home } /a" , File . expand_path ( str ) )
1137- assert_equal ( "~/a" , str )
1138- ensure
1139- ENV [ "HOME" ] = old_home if old_home
1139+ begin
1140+ old_home = ENV [ "HOME" ]
1141+ home = ENV [ "HOME" ] = "#{ DRIVE } /UserHome"
1142+ str = "~/a"
1143+ assert_equal ( "#{ home } /a" , File . expand_path ( str ) )
1144+ assert_equal ( "~/a" , str )
1145+ ensure
1146+ ENV [ "HOME" ] = old_home
1147+ end
11401148 end
11411149
11421150 def test_expand_path_raises_argument_error_for_any_supplied_username
@@ -1157,11 +1165,13 @@ def test_expand_path_error_for_nonexistent_username
11571165
11581166 def test_expand_path_error_for_non_absolute_home
11591167 omit "global side effects" if multiple_ractors?
1160- old_home = ENV [ "HOME" ]
1161- ENV [ "HOME" ] = "./UserHome"
1162- assert_raise_with_message ( ArgumentError , /non-absolute home/ ) { File . expand_path ( "~" ) }
1163- ensure
1164- ENV [ "HOME" ] = old_home if old_home
1168+ begin
1169+ old_home = ENV [ "HOME" ]
1170+ ENV [ "HOME" ] = "./UserHome"
1171+ assert_raise_with_message ( ArgumentError , /non-absolute home/ ) { File . expand_path ( "~" ) }
1172+ ensure
1173+ ENV [ "HOME" ] = old_home
1174+ end
11651175 end
11661176
11671177 def test_expand_path_raises_a_type_error_if_not_passed_a_string_type
0 commit comments