33use std:: fs:: { self , OpenOptions } ;
44use std:: io:: prelude:: * ;
55use std:: path:: Path ;
6+ use std:: thread;
67
78use cargo_test_support:: compare;
89use cargo_test_support:: cross_compile;
@@ -11,10 +12,10 @@ use cargo_test_support::registry::{self, registry_path, Package};
1112use cargo_test_support:: {
1213 basic_manifest, cargo_process, no_such_file_err_msg, project, project_in, symlink_supported, t,
1314} ;
14- use cargo_util:: ProcessError ;
15+ use cargo_util:: { ProcessBuilder , ProcessError } ;
1516
1617use cargo_test_support:: install:: {
17- assert_has_installed_exe, assert_has_not_installed_exe, cargo_home,
18+ assert_has_installed_exe, assert_has_not_installed_exe, cargo_home, exe ,
1819} ;
1920use cargo_test_support:: paths:: { self , CargoPathExt } ;
2021use std:: env;
@@ -2508,7 +2509,17 @@ fn install_incompat_msrv() {
25082509 . with_status ( 101 ) . run ( ) ;
25092510}
25102511
2511- #[ cfg( windows) ]
2512+ fn assert_tracker_noexistence ( key : & str ) {
2513+ let v1_data: toml:: Value =
2514+ toml:: from_str ( & fs:: read_to_string ( cargo_home ( ) . join ( ".crates.toml" ) ) . unwrap ( ) ) . unwrap ( ) ;
2515+ let v2_data: serde_json:: Value =
2516+ serde_json:: from_str ( & fs:: read_to_string ( cargo_home ( ) . join ( ".crates2.json" ) ) . unwrap ( ) )
2517+ . unwrap ( ) ;
2518+
2519+ assert ! ( v1_data[ "v1" ] . get( key) . is_none( ) ) ;
2520+ assert ! ( v2_data[ "installs" ] [ key] . is_null( ) ) ;
2521+ }
2522+
25122523#[ cargo_test]
25132524fn uninstall_running_binary ( ) {
25142525 Package :: new ( "foo" , "0.0.1" )
@@ -2553,24 +2564,33 @@ fn uninstall_running_binary() {
25532564 . run ( ) ;
25542565 assert_has_installed_exe ( cargo_home ( ) , "foo" ) ;
25552566
2556- use cargo_util:: ProcessBuilder ;
2557- use std:: thread;
2558- let foo_bin = cargo_test_support:: install:: cargo_home ( )
2559- . join ( "bin" )
2560- . join ( cargo_test_support:: install:: exe ( "foo" ) ) ;
2561-
2567+ let foo_bin = cargo_home ( ) . join ( "bin" ) . join ( exe ( "foo" ) ) ;
25622568 let t = thread:: spawn ( || ProcessBuilder :: new ( foo_bin) . exec ( ) . unwrap ( ) ) ;
2569+ let key = "foo 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" ;
25632570
2564- cargo_process ( "uninstall foo" )
2565- . with_status ( 101 )
2566- . with_stderr_contains ( "[ERROR] failed to remove file `[CWD]/home/.cargo/bin/foo[EXE]`" )
2567- . run ( ) ;
2568- assert_has_installed_exe ( cargo_home ( ) , "foo" ) ;
2571+ #[ cfg( windows) ]
2572+ {
2573+ cargo_process ( "uninstall foo" )
2574+ . with_status ( 101 )
2575+ . with_stderr_contains ( "[ERROR] failed to remove file `[CWD]/home/.cargo/bin/foo[EXE]`" )
2576+ . run ( ) ;
2577+ t. join ( ) . unwrap ( ) ;
2578+ cargo_process ( "uninstall foo" )
2579+ . with_stderr ( "[REMOVING] [CWD]/home/.cargo/bin/foo[EXE]" )
2580+ . run ( ) ;
2581+ } ;
2582+
2583+ #[ cfg( not( windows) ) ]
2584+ {
2585+ cargo_process ( "uninstall foo" )
2586+ . with_stderr ( "[REMOVING] [CWD]/home/.cargo/bin/foo[EXE]" )
2587+ . run ( ) ;
2588+ t. join ( ) . unwrap ( ) ;
2589+ } ;
2590+
2591+ assert_has_not_installed_exe ( cargo_home ( ) , "foo" ) ;
2592+ assert_tracker_noexistence ( key) ;
25692593
2570- t. join ( ) . unwrap ( ) ;
2571- cargo_process ( "uninstall foo" )
2572- . with_stderr ( "[REMOVING] [CWD]/home/.cargo/bin/foo[EXE]" )
2573- . run ( ) ;
25742594 cargo_process ( "install foo" )
25752595 . with_stderr (
25762596 "\
0 commit comments