@@ -2376,6 +2376,127 @@ fn only_toml_in_rust_toolchain_toml() {
23762376 } ) ;
23772377}
23782378
2379+ /// Checks that `rust-toolchain.toml` configs can be overridden by `rustup override set`.
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_err (
2386+ & [ "rustc" , "--version" ] ,
2387+ "rustup could not choose a version of rustc to run" ,
2388+ ) ;
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+ } ) ;
2409+ }
2410+
2411+ /// Checks that `rust-toolchain.toml` configs can override `rustup override set` at different directories.
2412+ /// See: <https://github.com/rust-lang/rustup/issues/3483>
2413+ #[ test]
2414+ fn rust_toolchain_toml_with_rustup_override_parent_dir ( ) {
2415+ test ( & |config| {
2416+ config. with_scenario ( Scenario :: SimpleV2 , & |config| {
2417+ config. expect_err (
2418+ & [ "rustc" , "--version" ] ,
2419+ "rustup could not choose a version of rustc to run" ,
2420+ ) ;
2421+
2422+ // "." -> nightly
2423+ config. expect_ok ( & [ "rustup" , "override" , "set" , "nightly" ] ) ;
2424+
2425+ // "./inner" -> beta + rls
2426+ let inner = & config. current_dir ( ) . join ( "inner" ) ;
2427+ std:: fs:: create_dir ( inner) . unwrap ( ) ;
2428+ config. change_dir ( inner, & |config| {
2429+ let cwd = config. current_dir ( ) ;
2430+ let toolchain_file = cwd. join ( "rust-toolchain.toml" ) ;
2431+ raw:: write_file (
2432+ & toolchain_file,
2433+ r#"
2434+ [toolchain]
2435+ channel = "beta"
2436+ components = [ "rls" ]
2437+ "# ,
2438+ )
2439+ . unwrap ( ) ;
2440+
2441+ let beta = "hash-beta-1.2.0" ;
2442+ config. expect_stdout_ok ( & [ "rustc" , "--version" ] , beta) ;
2443+ config. expect_stdout_ok ( & [ "rls" , "--version" ] , beta) ;
2444+ } ) ;
2445+
2446+ // "./inner" -> beta + rls
2447+ // "./inner/inner" -> (beta + rls) | stable = stable + rls
2448+ let inner2 = & inner. join ( "inner" ) ;
2449+ std:: fs:: create_dir ( inner2) . unwrap ( ) ;
2450+ config. change_dir ( inner2, & |config| {
2451+ config. expect_ok ( & [ "rustup" , "override" , "set" , "stable" ] ) ;
2452+
2453+ let stable = "hash-stable-1.1.0" ;
2454+ config. expect_stdout_ok ( & [ "rustc" , "--version" ] , stable) ;
2455+ config. expect_stdout_ok ( & [ "rls" , "--version" ] , stable) ;
2456+ } ) ;
2457+
2458+ // "." -> nightly, no rls
2459+ let nightly = "hash-nightly-2" ;
2460+ config. expect_stdout_ok ( & [ "rustc" , "--version" ] , nightly) ;
2461+ config. expect_component_not_executable ( "rls" ) ;
2462+ } )
2463+ } ) ;
2464+ }
2465+
2466+ /// Checks that `rust-toolchain.toml` configs can be overridden by `RUSTUP_TOOLCHAIN`.
2467+ /// See: <https://github.com/rust-lang/rustup/issues/3483>
2468+ #[ test]
2469+ fn rust_toolchain_toml_with_rustup_toolchain ( ) {
2470+ test ( & |config| {
2471+ config. with_scenario ( Scenario :: SimpleV2 , & |config| {
2472+ config. expect_err (
2473+ & [ "rustc" , "--version" ] ,
2474+ "rustup could not choose a version of rustc to run" ,
2475+ ) ;
2476+
2477+ let cwd = config. current_dir ( ) ;
2478+ let toolchain_file = cwd. join ( "rust-toolchain.toml" ) ;
2479+ raw:: write_file (
2480+ & toolchain_file,
2481+ r#"
2482+ [toolchain]
2483+ channel = "nightly"
2484+ components = [ "rls" ]
2485+ "# ,
2486+ )
2487+ . unwrap ( ) ;
2488+
2489+ let env = & [ ( "RUSTUP_TOOLCHAIN" , "beta" ) ] ;
2490+ let beta = "hash-beta-1.2.0" ;
2491+ config. expect_stdout_ok_with_env ( & [ "rustc" , "--version" ] , env, beta) ;
2492+ config. expect_stdout_ok_with_env ( & [ "rls" , "--version" ] , env, beta) ;
2493+
2494+ // At this point, `nightly` is still NOT installed.
2495+ config. expect_not_stderr_ok ( & [ "rustup" , "toolchain" , "list" ] , "nightly" ) ;
2496+ } )
2497+ } ) ;
2498+ }
2499+
23792500/// Checks that a warning occurs if both `rust-toolchain` and `rust-toolchain.toml` files exist
23802501#[ test]
23812502fn warn_on_duplicate_rust_toolchain_file ( ) {
0 commit comments