@@ -747,118 +747,132 @@ mod tests {
747
747
#[ test]
748
748
async fn windows_path_regkey_type ( ) {
749
749
// per issue #261, setting PATH should use REG_EXPAND_SZ.
750
- let tp = Box :: new ( currentprocess :: TestProcess :: default ( ) ) ;
750
+
751
751
with_saved_path ( & mut || {
752
- currentprocess:: with_tokio ( tp. clone ( ) , async {
753
- let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
754
- let environment = root
755
- . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
756
- . unwrap ( ) ;
757
- environment. delete_value ( "PATH" ) . unwrap ( ) ;
758
-
759
- {
760
- // Can't compare the Results as Eq isn't derived; thanks error-chain.
761
- #![ allow( clippy:: unit_cmp) ]
762
- assert_eq ! ( ( ) , super :: _apply_new_path( Some ( wide( "foo" ) ) ) . unwrap( ) ) ;
763
- }
764
- let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
765
- let environment = root
766
- . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
767
- . unwrap ( ) ;
768
- let path = environment. get_raw_value ( "PATH" ) . unwrap ( ) ;
769
- assert_eq ! ( path. vtype, RegType :: REG_EXPAND_SZ ) ;
770
- assert_eq ! ( super :: to_winreg_bytes( wide( "foo" ) ) , & path. bytes[ ..] ) ;
752
+ let tp = Box :: new ( currentprocess:: TestProcess :: default ( ) ) ;
753
+ Box :: pin ( async move {
754
+ currentprocess:: with_tokio ( tp. clone ( ) , async move {
755
+ let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
756
+ let environment = root
757
+ . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
758
+ . unwrap ( ) ;
759
+ environment. delete_value ( "PATH" ) . unwrap ( ) ;
760
+
761
+ {
762
+ // Can't compare the Results as Eq isn't derived; thanks error-chain.
763
+ #![ allow( clippy:: unit_cmp) ]
764
+ assert_eq ! ( ( ) , super :: _apply_new_path( Some ( wide( "foo" ) ) ) . unwrap( ) ) ;
765
+ }
766
+ let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
767
+ let environment = root
768
+ . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
769
+ . unwrap ( ) ;
770
+ let path = environment. get_raw_value ( "PATH" ) . unwrap ( ) ;
771
+ assert_eq ! ( path. vtype, RegType :: REG_EXPAND_SZ ) ;
772
+ assert_eq ! ( super :: to_winreg_bytes( wide( "foo" ) ) , & path. bytes[ ..] ) ;
773
+ } )
771
774
} )
772
- } ) ;
775
+ } )
776
+ . await ;
773
777
}
774
778
775
779
#[ test]
776
780
async fn windows_path_delete_key_when_empty ( ) {
777
- use std:: io;
778
- // during uninstall the PATH key may end up empty; if so we should
779
- // delete it.
780
- let tp = Box :: new ( currentprocess:: TestProcess :: default ( ) ) ;
781
781
with_saved_path ( & mut || {
782
- currentprocess:: with_tokio ( tp. clone ( ) , async {
783
- let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
784
- let environment = root
785
- . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
786
- . unwrap ( ) ;
787
- environment
788
- . set_raw_value (
789
- "PATH" ,
790
- & RegValue {
791
- bytes : super :: to_winreg_bytes ( wide ( "foo" ) ) ,
792
- vtype : RegType :: REG_EXPAND_SZ ,
793
- } ,
794
- )
795
- . unwrap ( ) ;
796
-
797
- {
798
- // Can't compare the Results as Eq isn't derived; thanks error-chain.
799
- #![ allow( clippy:: unit_cmp) ]
800
- assert_eq ! ( ( ) , super :: _apply_new_path( Some ( Vec :: new( ) ) ) . unwrap( ) ) ;
801
- }
802
- let reg_value = environment. get_raw_value ( "PATH" ) ;
803
- match reg_value {
804
- Ok ( _) => panic ! ( "key not deleted" ) ,
805
- Err ( ref e) if e. kind ( ) == io:: ErrorKind :: NotFound => { }
806
- Err ( ref e) => panic ! ( "error {e}" ) ,
807
- }
782
+ Box :: pin ( async move {
783
+ use std:: io;
784
+ // during uninstall the PATH key may end up empty; if so we should
785
+ // delete it.
786
+ let tp = Box :: new ( currentprocess:: TestProcess :: default ( ) ) ;
787
+
788
+ currentprocess:: with_tokio ( tp. clone ( ) , async {
789
+ let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
790
+ let environment = root
791
+ . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
792
+ . unwrap ( ) ;
793
+ environment
794
+ . set_raw_value (
795
+ "PATH" ,
796
+ & RegValue {
797
+ bytes : super :: to_winreg_bytes ( wide ( "foo" ) ) ,
798
+ vtype : RegType :: REG_EXPAND_SZ ,
799
+ } ,
800
+ )
801
+ . unwrap ( ) ;
802
+
803
+ {
804
+ // Can't compare the Results as Eq isn't derived; thanks error-chain.
805
+ #![ allow( clippy:: unit_cmp) ]
806
+ assert_eq ! ( ( ) , super :: _apply_new_path( Some ( Vec :: new( ) ) ) . unwrap( ) ) ;
807
+ }
808
+ let reg_value = environment. get_raw_value ( "PATH" ) ;
809
+ match reg_value {
810
+ Ok ( _) => panic ! ( "key not deleted" ) ,
811
+ Err ( ref e) if e. kind ( ) == io:: ErrorKind :: NotFound => { }
812
+ Err ( ref e) => panic ! ( "error {e}" ) ,
813
+ }
814
+ } )
808
815
} )
809
- } ) ;
816
+ } )
817
+ . await ;
810
818
}
811
819
812
820
#[ test]
813
821
async fn windows_doesnt_mess_with_a_non_string_path ( ) {
814
- // This writes an error, so we want a sink for it.
815
- let tp = Box :: new ( currentprocess:: TestProcess {
816
- vars : [ ( "HOME" . to_string ( ) , "/unused" . to_string ( ) ) ]
817
- . iter ( )
818
- . cloned ( )
819
- . collect ( ) ,
820
- ..Default :: default ( )
821
- } ) ;
822
822
with_saved_path ( & mut || {
823
- currentprocess:: with_tokio ( tp. clone ( ) , async {
824
- let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
825
- let environment = root
826
- . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
827
- . unwrap ( ) ;
828
- let reg_value = RegValue {
829
- bytes : vec ! [ 0x12 , 0x34 ] ,
830
- vtype : RegType :: REG_BINARY ,
831
- } ;
832
- environment. set_raw_value ( "PATH" , & reg_value) . unwrap ( ) ;
833
- // Ok(None) signals no change to the PATH setting layer
823
+ Box :: pin ( async move {
824
+ // This writes an error, so we want a sink for it.
825
+ let tp = Box :: new ( currentprocess:: TestProcess {
826
+ vars : [ ( "HOME" . to_string ( ) , "/unused" . to_string ( ) ) ]
827
+ . iter ( )
828
+ . cloned ( )
829
+ . collect ( ) ,
830
+ ..Default :: default ( )
831
+ } ) ;
832
+
833
+ currentprocess:: with_tokio ( tp. clone ( ) , async {
834
+ let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
835
+ let environment = root
836
+ . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
837
+ . unwrap ( ) ;
838
+ let reg_value = RegValue {
839
+ bytes : vec ! [ 0x12 , 0x34 ] ,
840
+ vtype : RegType :: REG_BINARY ,
841
+ } ;
842
+ environment. set_raw_value ( "PATH" , & reg_value) . unwrap ( ) ;
843
+ // Ok(None) signals no change to the PATH setting layer
844
+ assert_eq ! (
845
+ None ,
846
+ super :: _with_path_cargo_home_bin( |_, _| panic!( "called" ) ) . unwrap( )
847
+ ) ;
848
+ } ) ;
834
849
assert_eq ! (
835
- None ,
836
- super :: _with_path_cargo_home_bin( |_, _| panic!( "called" ) ) . unwrap( )
850
+ r"warning: the registry key HKEY_CURRENT_USER\Environment\PATH is not a string. Not modifying the PATH variable
851
+ " ,
852
+ String :: from_utf8( tp. get_stderr( ) ) . unwrap( )
837
853
) ;
838
854
} )
839
- } ) ;
840
- assert_eq ! (
841
- r"warning: the registry key HKEY_CURRENT_USER\Environment\PATH is not a string. Not modifying the PATH variable
842
- " ,
843
- String :: from_utf8( tp. get_stderr( ) ) . unwrap( )
844
- ) ;
855
+ } ) . await ;
845
856
}
846
857
847
858
#[ test]
848
859
async fn windows_treat_missing_path_as_empty ( ) {
849
860
// during install the PATH key may be missing; treat it as empty
850
- let tp = Box :: new ( currentprocess:: TestProcess :: default ( ) ) ;
851
861
with_saved_path ( & mut || {
852
- currentprocess:: with_tokio ( tp. clone ( ) , async {
853
- let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
854
- let environment = root
855
- . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
856
- . unwrap ( ) ;
857
- environment. delete_value ( "PATH" ) . unwrap ( ) ;
858
-
859
- assert_eq ! ( Some ( Vec :: new( ) ) , super :: get_windows_path_var( ) . unwrap( ) ) ;
862
+ Box :: pin ( async move {
863
+ let tp = Box :: new ( currentprocess:: TestProcess :: default ( ) ) ;
864
+ currentprocess:: with_tokio ( tp. clone ( ) , async {
865
+ let root = RegKey :: predef ( HKEY_CURRENT_USER ) ;
866
+ let environment = root
867
+ . open_subkey_with_flags ( "Environment" , KEY_READ | KEY_WRITE )
868
+ . unwrap ( ) ;
869
+ environment. delete_value ( "PATH" ) . unwrap ( ) ;
870
+
871
+ assert_eq ! ( Some ( Vec :: new( ) ) , super :: get_windows_path_var( ) . unwrap( ) ) ;
872
+ } )
860
873
} )
861
- } ) ;
874
+ } )
875
+ . await ;
862
876
}
863
877
864
878
#[ test]
0 commit comments