@@ -2376,6 +2376,130 @@ fn only_toml_in_rust_toolchain_toml() {
2376
2376
} ) ;
2377
2377
}
2378
2378
2379
+ /// Checks that `rust-toolchain.toml` configs can be overridden by `rustup override set` or `<proxy> +<toolchain>`.
2380
+ /// See: <https://github.com/rust-lang/rustup/issues/3483>
2381
+ #[ test]
2382
+ fn rust_toolchain_toml_with_rustup_override ( ) {
2383
+ test ( & |config| {
2384
+ config. with_scenario ( Scenario :: SimpleV2 , & |config| {
2385
+ config. expect_ok ( & [ "rustup" , "default" , "stable" ] ) ;
2386
+
2387
+ let stable = "hash-stable-1.1.0" ;
2388
+ config. expect_stdout_ok ( & [ "rustc" , "--version" ] , stable) ;
2389
+
2390
+ config. expect_ok ( & [ "rustup" , "override" , "set" , "beta" ] ) ;
2391
+
2392
+ let cwd = config. current_dir ( ) ;
2393
+ let toolchain_file = cwd. join ( "rust-toolchain.toml" ) ;
2394
+ raw:: write_file (
2395
+ & toolchain_file,
2396
+ r#"
2397
+ [toolchain]
2398
+ channel = "nightly"
2399
+ components = [ "rls" ]
2400
+ "# ,
2401
+ )
2402
+ . unwrap ( ) ;
2403
+
2404
+ let beta = "hash-beta-1.2.0" ;
2405
+ config. expect_stdout_ok ( & [ "rustc" , "--version" ] , beta) ;
2406
+ config. expect_stdout_ok ( & [ "rls" , "--version" ] , beta) ;
2407
+
2408
+ config. expect_stderr_ok ( & [ "rls" , "+stable" , "--version" ] , stable) ;
2409
+ } )
2410
+ } ) ;
2411
+ }
2412
+
2413
+ /// Checks that `rust-toolchain.toml` configs can be overridden by `RUSTUP_TOOLCHAIN`.
2414
+ /// See: <https://github.com/rust-lang/rustup/issues/3483>
2415
+ #[ test]
2416
+ fn rust_toolchain_toml_with_rustup_toolchain ( ) {
2417
+ test ( & |config| {
2418
+ config. with_scenario ( Scenario :: SimpleV2 , & |config| {
2419
+ config. expect_err (
2420
+ & [ "rustc" , "--version" ] ,
2421
+ "rustup could not choose a version of rustc to run" ,
2422
+ ) ;
2423
+
2424
+ let cwd = config. current_dir ( ) ;
2425
+ let toolchain_file = cwd. join ( "rust-toolchain.toml" ) ;
2426
+ raw:: write_file (
2427
+ & toolchain_file,
2428
+ r#"
2429
+ [toolchain]
2430
+ channel = "nightly"
2431
+ components = [ "rls" ]
2432
+ "# ,
2433
+ )
2434
+ . unwrap ( ) ;
2435
+
2436
+ let env = & [ ( "RUSTUP_TOOLCHAIN" , "beta" ) ] ;
2437
+ let beta = "hash-beta-1.2.0" ;
2438
+ config. expect_stdout_ok_with_env ( & [ "rustc" , "--version" ] , env, beta) ;
2439
+ config. expect_stdout_ok_with_env ( & [ "rls" , "--version" ] , env, beta) ;
2440
+
2441
+ // At this point, `nightly` is still NOT installed.
2442
+ config. expect_not_stderr_ok ( & [ "rustup" , "toolchain" , "list" ] , "nightly" ) ;
2443
+ } )
2444
+ } ) ;
2445
+ }
2446
+
2447
+ /// Checks that `rust-toolchain.toml` configs can override `rustup override set` at different directories.
2448
+ /// See: <https://github.com/rust-lang/rustup/issues/3483>
2449
+ #[ test]
2450
+ fn rust_toolchain_toml_with_rustup_override_parent_dir ( ) {
2451
+ test ( & |config| {
2452
+ config. with_scenario ( Scenario :: SimpleV2 , & |config| {
2453
+ config. expect_err (
2454
+ & [ "rustc" , "--version" ] ,
2455
+ "rustup could not choose a version of rustc to run" ,
2456
+ ) ;
2457
+
2458
+ // "." -> nightly, no rls
2459
+ config. expect_ok ( & [ "rustup" , "override" , "set" , "nightly" ] ) ;
2460
+
2461
+ // "./inner" -> beta + rls
2462
+ let inner = & config. current_dir ( ) . join ( "inner" ) ;
2463
+ std:: fs:: create_dir ( inner) . unwrap ( ) ;
2464
+ config. change_dir ( inner, & |config| {
2465
+ let cwd = config. current_dir ( ) ;
2466
+ let toolchain_file = cwd. join ( "rust-toolchain.toml" ) ;
2467
+ raw:: write_file (
2468
+ & toolchain_file,
2469
+ r#"
2470
+ [toolchain]
2471
+ channel = "beta"
2472
+ components = [ "rls" ]
2473
+ "# ,
2474
+ )
2475
+ . unwrap ( ) ;
2476
+
2477
+ let beta = "hash-beta-1.2.0" ;
2478
+ config. expect_stdout_ok ( & [ "rustc" , "--version" ] , beta) ;
2479
+ config. expect_stdout_ok ( & [ "rls" , "--version" ] , beta) ;
2480
+ } ) ;
2481
+
2482
+ // "./inner/inner" -> stable, no rls
2483
+ let inner2 = & inner. join ( "inner" ) ;
2484
+ std:: fs:: create_dir ( inner2) . unwrap ( ) ;
2485
+ config. change_dir ( inner2, & |config| {
2486
+ config. expect_ok ( & [ "rustup" , "override" , "set" , "stable" ] ) ;
2487
+
2488
+ let stable = "hash-stable-1.1.0" ;
2489
+ config. expect_stdout_ok ( & [ "rustc" , "--version" ] , stable) ;
2490
+ // The `rustup override set` in this directory stops
2491
+ // the `rust-toolchain.toml` in the parent directory from working.
2492
+ config. expect_component_not_executable ( "rls" )
2493
+ } ) ;
2494
+
2495
+ // "." -> nightly, no rls
2496
+ let nightly = "hash-nightly-2" ;
2497
+ config. expect_stdout_ok ( & [ "rustc" , "--version" ] , nightly) ;
2498
+ config. expect_component_not_executable ( "rls" ) ;
2499
+ } )
2500
+ } ) ;
2501
+ }
2502
+
2379
2503
/// Checks that a warning occurs if both `rust-toolchain` and `rust-toolchain.toml` files exist
2380
2504
#[ test]
2381
2505
fn warn_on_duplicate_rust_toolchain_file ( ) {
0 commit comments