@@ -8,6 +8,8 @@ use crate::mock::clitools::{
8
8
} ;
9
9
use crate :: mock:: { get_path, restore_path} ;
10
10
use lazy_static:: lazy_static;
11
+ use rustup:: utils:: raw;
12
+ use std:: fs;
11
13
use std:: io:: Write ;
12
14
use std:: process:: Stdio ;
13
15
use std:: sync:: Mutex ;
@@ -266,3 +268,84 @@ fn test_warn_if_complete_profile_is_used() {
266
268
) ;
267
269
} ) ;
268
270
}
271
+
272
+ fn create_rustup_sh_metadata ( config : & Config ) {
273
+ let rustup_dir = config. homedir . join ( ".rustup" ) ;
274
+ fs:: create_dir_all ( & rustup_dir) . unwrap ( ) ;
275
+ let version_file = rustup_dir. join ( "rustup-version" ) ;
276
+ raw:: write_file ( & version_file, "" ) . unwrap ( ) ;
277
+ }
278
+
279
+ #[ test]
280
+ fn test_prompt_fail_if_rustup_sh_already_installed_reply_nothing ( ) {
281
+ setup ( & |config| {
282
+ create_rustup_sh_metadata ( & config) ;
283
+ let out = run_input ( config, & [ "rustup-init" ] , "\n " ) ;
284
+ assert ! ( !out. ok) ;
285
+ assert ! ( out
286
+ . stderr
287
+ . contains( "warning: it looks like you have existing rustup.sh metadata" ) ) ;
288
+ assert ! ( out
289
+ . stderr
290
+ . contains( "error: cannot install while rustup.sh is installed" ) ) ;
291
+ assert ! ( out. stdout. contains( "Continue? (y/N)" ) ) ;
292
+ } )
293
+ }
294
+
295
+ #[ test]
296
+ fn test_prompt_fail_if_rustup_sh_already_installed_reply_no ( ) {
297
+ setup ( & |config| {
298
+ create_rustup_sh_metadata ( & config) ;
299
+ let out = run_input ( config, & [ "rustup-init" ] , "no\n " ) ;
300
+ assert ! ( !out. ok) ;
301
+ assert ! ( out
302
+ . stderr
303
+ . contains( "warning: it looks like you have existing rustup.sh metadata" ) ) ;
304
+ assert ! ( out
305
+ . stderr
306
+ . contains( "error: cannot install while rustup.sh is installed" ) ) ;
307
+ assert ! ( out. stdout. contains( "Continue? (y/N)" ) ) ;
308
+ } )
309
+ }
310
+
311
+ #[ test]
312
+ fn test_prompt_succeed_if_rustup_sh_already_installed_reply_yes ( ) {
313
+ setup ( & |config| {
314
+ create_rustup_sh_metadata ( & config) ;
315
+ let out = run_input ( config, & [ "rustup-init" ] , "yes\n \n \n " ) ;
316
+ assert ! ( out. ok) ;
317
+ assert ! ( out
318
+ . stderr
319
+ . contains( "warning: it looks like you have existing rustup.sh metadata" ) ) ;
320
+ assert ! ( out
321
+ . stderr
322
+ . contains( "error: cannot install while rustup.sh is installed" ) ) ;
323
+ assert ! ( out. stdout. contains( "Continue? (y/N)" ) ) ;
324
+ assert ! ( !out. stdout. contains(
325
+ "warning: continuing (because the -y flag is set and the error is ignorable)"
326
+ ) )
327
+ } )
328
+ }
329
+
330
+ #[ test]
331
+ fn test_warn_succeed_if_rustup_sh_already_installed_y_flag ( ) {
332
+ setup ( & |config| {
333
+ create_rustup_sh_metadata ( & config) ;
334
+ let out = run_input ( config, & [ "rustup-init" , "-y" ] , "" ) ;
335
+ assert ! ( out. ok) ;
336
+ assert ! ( out
337
+ . stderr
338
+ . contains( "warning: it looks like you have existing rustup.sh metadata" ) ) ;
339
+ assert ! ( out
340
+ . stderr
341
+ . contains( "error: cannot install while rustup.sh is installed" ) ) ;
342
+ assert ! ( out. stderr. contains(
343
+ "warning: continuing (because the -y flag is set and the error is ignorable)"
344
+ ) ) ;
345
+ assert ! ( !out. stdout. contains( "Continue? (y/N)" ) ) ;
346
+ } )
347
+ }
348
+
349
+ #[ ignore] // Can't test environment variable.
350
+ #[ test]
351
+ fn test_succeed_if_rustup_sh_already_installed_env_var_set ( ) { }
0 commit comments