@@ -730,7 +730,7 @@ mod tests {
730
730
731
731
use rustup_macros:: unit_test as test;
732
732
733
- use crate :: currentprocess:: { self , Process } ;
733
+ use crate :: currentprocess:: TestProcess ;
734
734
use crate :: test:: with_saved_path;
735
735
736
736
fn wide ( str : & str ) -> Vec < u16 > {
@@ -771,28 +771,25 @@ mod tests {
771
771
#[ test]
772
772
fn windows_path_regkey_type ( ) {
773
773
// per issue #261, setting PATH should use REG_EXPAND_SZ.
774
- let tp = currentprocess:: TestProcess :: default ( ) ;
775
774
with_saved_path ( & mut || {
776
- currentprocess:: with ( tp. clone ( ) . into ( ) , || {
777
- let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
778
- let environment = root
779
- . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
780
- . unwrap ( ) ;
781
- environment. delete_value ( "PATH" ) . unwrap ( ) ;
782
-
783
- {
784
- // Can't compare the Results as Eq isn't derived; thanks error-chain.
785
- #![ allow( clippy:: unit_cmp) ]
786
- assert_eq ! ( ( ) , super :: _apply_new_path( Some ( wide( "foo" ) ) ) . unwrap( ) ) ;
787
- }
788
- let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
789
- let environment = root
790
- . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
791
- . unwrap ( ) ;
792
- let path = environment. get_raw_value ( "PATH" ) . unwrap ( ) ;
793
- assert_eq ! ( path. vtype, RegType :: REG_EXPAND_SZ ) ;
794
- assert_eq ! ( super :: to_winreg_bytes( wide( "foo" ) ) , & path. bytes[ ..] ) ;
795
- } )
775
+ let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
776
+ let environment = root
777
+ . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
778
+ . unwrap ( ) ;
779
+ environment. delete_value ( "PATH" ) . unwrap ( ) ;
780
+
781
+ {
782
+ // Can't compare the Results as Eq isn't derived; thanks error-chain.
783
+ #![ allow( clippy:: unit_cmp) ]
784
+ assert_eq ! ( ( ) , super :: _apply_new_path( Some ( wide( "foo" ) ) ) . unwrap( ) ) ;
785
+ }
786
+ let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
787
+ let environment = root
788
+ . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
789
+ . unwrap ( ) ;
790
+ let path = environment. get_raw_value ( "PATH" ) . unwrap ( ) ;
791
+ assert_eq ! ( path. vtype, RegType :: REG_EXPAND_SZ ) ;
792
+ assert_eq ! ( super :: to_winreg_bytes( wide( "foo" ) ) , & path. bytes[ ..] ) ;
796
793
} ) ;
797
794
}
798
795
@@ -801,87 +798,78 @@ mod tests {
801
798
use std:: io;
802
799
// during uninstall the PATH key may end up empty; if so we should
803
800
// delete it.
804
- let tp = currentprocess:: TestProcess :: default ( ) ;
805
801
with_saved_path ( & mut || {
806
- currentprocess:: with ( tp. clone ( ) . into ( ) , || {
807
- let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
808
- let environment = root
809
- . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
810
- . unwrap ( ) ;
811
- environment
812
- . set_raw_value (
813
- "PATH" ,
814
- & RegValue {
815
- bytes : super :: to_winreg_bytes ( wide ( "foo" ) ) ,
816
- vtype : RegType :: REG_EXPAND_SZ ,
817
- } ,
818
- )
819
- . unwrap ( ) ;
820
-
821
- {
822
- // Can't compare the Results as Eq isn't derived; thanks error-chain.
823
- #![ allow( clippy:: unit_cmp) ]
824
- assert_eq ! ( ( ) , super :: _apply_new_path( Some ( Vec :: new( ) ) ) . unwrap( ) ) ;
825
- }
826
- let reg_value = environment. get_raw_value ( "PATH" ) ;
827
- match reg_value {
828
- Ok ( _) => panic ! ( "key not deleted" ) ,
829
- Err ( ref e) if e. kind ( ) == io:: ErrorKind :: NotFound => { }
830
- Err ( ref e) => panic ! ( "error {e}" ) ,
831
- }
832
- } )
802
+ let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
803
+ let environment = root
804
+ . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
805
+ . unwrap ( ) ;
806
+ environment
807
+ . set_raw_value (
808
+ "PATH" ,
809
+ & RegValue {
810
+ bytes : super :: to_winreg_bytes ( wide ( "foo" ) ) ,
811
+ vtype : RegType :: REG_EXPAND_SZ ,
812
+ } ,
813
+ )
814
+ . unwrap ( ) ;
815
+
816
+ {
817
+ // Can't compare the Results as Eq isn't derived; thanks error-chain.
818
+ #![ allow( clippy:: unit_cmp) ]
819
+ assert_eq ! ( ( ) , super :: _apply_new_path( Some ( Vec :: new( ) ) ) . unwrap( ) ) ;
820
+ }
821
+ let reg_value = environment. get_raw_value ( "PATH" ) ;
822
+ match reg_value {
823
+ Ok ( _) => panic ! ( "key not deleted" ) ,
824
+ Err ( ref e) if e. kind ( ) == io:: ErrorKind :: NotFound => { }
825
+ Err ( ref e) => panic ! ( "error {e}" ) ,
826
+ }
833
827
} ) ;
834
828
}
835
829
836
830
#[ test]
837
831
fn windows_doesnt_mess_with_a_non_string_path ( ) {
838
832
// This writes an error, so we want a sink for it.
839
- let tp = currentprocess :: TestProcess :: with_vars (
833
+ let tp = TestProcess :: with_vars (
840
834
[ ( "HOME" . to_string ( ) , "/unused" . to_string ( ) ) ]
841
835
. iter ( )
842
836
. cloned ( )
843
837
. collect ( ) ,
844
838
) ;
845
- let process = Process :: from ( tp. clone ( ) ) ;
846
839
with_saved_path ( & mut || {
847
- currentprocess:: with ( tp. clone ( ) . into ( ) , || {
848
- let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
849
- let environment = root
850
- . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
851
- . unwrap ( ) ;
852
- let reg_value = RegValue {
853
- bytes : vec ! [ 0x12 , 0x34 ] ,
854
- vtype : RegType :: REG_BINARY ,
855
- } ;
856
- environment. set_raw_value ( "PATH" , & reg_value) . unwrap ( ) ;
857
- // Ok(None) signals no change to the PATH setting layer
858
- assert_eq ! (
859
- None ,
860
- super :: _with_path_cargo_home_bin( |_, _| panic!( "called" ) , & process) . unwrap( )
861
- ) ;
862
- } )
840
+ let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
841
+ let environment = root
842
+ . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
843
+ . unwrap ( ) ;
844
+ let reg_value = RegValue {
845
+ bytes : vec ! [ 0x12 , 0x34 ] ,
846
+ vtype : RegType :: REG_BINARY ,
847
+ } ;
848
+ environment. set_raw_value ( "PATH" , & reg_value) . unwrap ( ) ;
849
+ // Ok(None) signals no change to the PATH setting layer
850
+ assert_eq ! (
851
+ None ,
852
+ super :: _with_path_cargo_home_bin( |_, _| panic!( "called" ) , & tp. process) . unwrap( )
853
+ ) ;
863
854
} ) ;
864
855
assert_eq ! (
865
856
r"warning: the registry key HKEY_CURRENT_USER\Environment\PATH is not a string. Not modifying the PATH variable
866
857
" ,
867
- String :: from_utf8( tp. get_stderr ( ) ) . unwrap( )
858
+ String :: from_utf8( tp. stderr ( ) ) . unwrap( )
868
859
) ;
869
860
}
870
861
871
862
#[ test]
872
863
fn windows_treat_missing_path_as_empty ( ) {
873
864
// during install the PATH key may be missing; treat it as empty
874
- let tp = currentprocess:: TestProcess :: default ( ) ;
875
865
with_saved_path ( & mut || {
876
- currentprocess:: with ( tp. clone ( ) . into ( ) , || {
877
- let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
878
- let environment = root
879
- . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
880
- . unwrap ( ) ;
881
- environment. delete_value ( "PATH" ) . unwrap ( ) ;
882
-
883
- assert_eq ! ( Some ( Vec :: new( ) ) , super :: get_windows_path_var( ) . unwrap( ) ) ;
884
- } )
866
+ let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
867
+ let environment = root
868
+ . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
869
+ . unwrap ( ) ;
870
+ environment. delete_value ( "PATH" ) . unwrap ( ) ;
871
+
872
+ assert_eq ! ( Some ( Vec :: new( ) ) , super :: get_windows_path_var( ) . unwrap( ) ) ;
885
873
} ) ;
886
874
}
887
875
0 commit comments