@@ -5,17 +5,22 @@ extern crate rustup_dist;
55extern crate rustup_utils;
66extern crate rustup_mock;
77extern crate time;
8- use rustup_mock:: clitools:: { self , Config , Scenario ,
8+ extern crate tempdir;
9+
10+ use rustup_mock:: clitools:: { self , Config , Scenario , SanitizedOutput ,
911 expect_stdout_ok, expect_stderr_ok,
1012 expect_ok, expect_err, expect_timeout_ok,
1113 run, this_host_triple} ;
1214use rustup_utils:: { raw, utils} ;
1315
14- use time:: Duration ;
15- use std:: ops:: Sub ;
16+ use std:: io:: Write ;
1617use std:: ops:: Add ;
18+ use std:: ops:: Sub ;
19+ use std:: process:: Stdio ;
1720use std:: time:: Duration as StdDuration ;
1821use std:: env:: consts:: EXE_SUFFIX ;
22+ use tempdir:: TempDir ;
23+ use time:: Duration ;
1924
2025macro_rules! for_host { ( $s: expr) => ( & format!( $s, this_host_triple( ) ) ) }
2126
@@ -429,3 +434,52 @@ fn rls_does_not_exist_in_toolchain() {
429434 this_host_triple( ) , EXE_SUFFIX ) ) ;
430435 } ) ;
431436}
437+
438+ #[ test]
439+ fn install_stops_if_rustc_exists ( ) {
440+ let temp_dir = TempDir :: new ( "fakebin" ) . unwrap ( ) ;
441+ // Create fake executable
442+ let ref fake_exe = temp_dir. path ( ) . join ( & format ! ( "{}{}" , "rustc" , EXE_SUFFIX ) ) ;
443+ raw:: append_file ( fake_exe, "" ) . unwrap ( ) ;
444+ let temp_dir_path = temp_dir. path ( ) . to_str ( ) . unwrap ( ) ;
445+
446+ setup ( & |config| {
447+ let out = run ( config, "rustup-init" , & [ ] ,
448+ & [ ( "RUSTUP_INIT_SKIP_PATH_CHECK" , "no" ) , ( "PATH" , & temp_dir_path) ] ) ;
449+ assert ! ( !out. ok) ;
450+ assert ! ( out. stderr. contains( "it looks like you have an existing installation of Rust at:" ) ) ;
451+ assert ! ( out. stderr. contains( "if this is what you want, restart the installation with `-y'" ) ) ;
452+ } ) ;
453+ }
454+
455+ #[ test]
456+ fn install_stops_if_cargo_exists ( ) {
457+ let temp_dir = TempDir :: new ( "fakebin" ) . unwrap ( ) ;
458+ // Create fake executable
459+ let ref fake_exe = temp_dir. path ( ) . join ( & format ! ( "{}{}" , "cargo" , EXE_SUFFIX ) ) ;
460+ raw:: append_file ( fake_exe, "" ) . unwrap ( ) ;
461+ let temp_dir_path = temp_dir. path ( ) . to_str ( ) . unwrap ( ) ;
462+
463+ setup ( & |config| {
464+ let out = run ( config, "rustup-init" , & [ ] ,
465+ & [ ( "RUSTUP_INIT_SKIP_PATH_CHECK" , "no" ) , ( "PATH" , & temp_dir_path) ] ) ;
466+ assert ! ( !out. ok) ;
467+ assert ! ( out. stderr. contains( "it looks like you have an existing installation of Rust at:" ) ) ;
468+ assert ! ( out. stderr. contains( "if this is what you want, restart the installation with `-y'" ) ) ;
469+ } ) ;
470+ }
471+
472+ #[ test]
473+ fn with_no_prompt_install_succeeds_if_rustc_exists ( ) {
474+ let temp_dir = TempDir :: new ( "fakebin" ) . unwrap ( ) ;
475+ // Create fake executable
476+ let ref fake_exe = temp_dir. path ( ) . join ( & format ! ( "{}{}" , "rustc" , EXE_SUFFIX ) ) ;
477+ raw:: append_file ( fake_exe, "" ) . unwrap ( ) ;
478+ let temp_dir_path = temp_dir. path ( ) . to_str ( ) . unwrap ( ) ;
479+
480+ setup ( & |config| {
481+ let out = run ( config, "rustup-init" , & [ "-y" ] ,
482+ & [ ( "RUSTUP_INIT_SKIP_PATH_CHECK" , "no" ) , ( "PATH" , & temp_dir_path) ] ) ;
483+ assert ! ( out. ok) ;
484+ } ) ;
485+ }
0 commit comments