File tree Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -196,7 +196,14 @@ impl Cfg {
196
196
197
197
// Centralised file for multi-user systems to provide admin/distributor set initial values.
198
198
let fallback_settings = if cfg ! ( not( windows) ) {
199
- FallbackSettings :: new ( PathBuf :: from ( UNIX_FALLBACK_SETTINGS ) ) ?
199
+ // If present, use the RUSTUP_OVERRIDE_UNIX_FALLBACK_SETTINGS environment
200
+ // variable as settings path, or UNIX_FALLBACK_SETTINGS otherwise
201
+ FallbackSettings :: new (
202
+ match process ( ) . var ( "RUSTUP_OVERRIDE_UNIX_FALLBACK_SETTINGS" ) {
203
+ Ok ( s) => PathBuf :: from ( s) ,
204
+ Err ( _) => PathBuf :: from ( UNIX_FALLBACK_SETTINGS ) ,
205
+ } ,
206
+ ) ?
200
207
} else {
201
208
None
202
209
} ;
Original file line number Diff line number Diff line change @@ -1940,3 +1940,41 @@ fn check_host_goes_away() {
1940
1940
) ;
1941
1941
} )
1942
1942
}
1943
+
1944
+ #[ cfg( unix) ]
1945
+ #[ test]
1946
+ fn check_unix_settings_fallback ( ) {
1947
+ setup ( & |config| {
1948
+ // No default toolchain specified yet
1949
+ expect_err (
1950
+ config,
1951
+ & [ "rustup" , "default" ] ,
1952
+ r"no default toolchain configured" ,
1953
+ ) ;
1954
+
1955
+ // Default toolchain specified in fallback settings file
1956
+ let mock_settings_file = config. current_dir ( ) . join ( "mock_fallback_settings.toml" ) ;
1957
+ raw:: write_file (
1958
+ & mock_settings_file,
1959
+ for_host ! ( r"default_toolchain = 'nightly-{0}'" ) ,
1960
+ )
1961
+ . unwrap ( ) ;
1962
+
1963
+ let mut cmd = clitools:: cmd ( config, "rustup" , & [ "default" ] ) ;
1964
+ clitools:: env ( config, & mut cmd) ;
1965
+
1966
+ // Override the path to the fallback settings file to be the mock file
1967
+ cmd. env ( "RUSTUP_OVERRIDE_UNIX_FALLBACK_SETTINGS" , mock_settings_file) ;
1968
+
1969
+ let out = cmd. output ( ) . unwrap ( ) ;
1970
+ assert ! ( out. status. success( ) ) ;
1971
+ let stdout = String :: from_utf8 ( out. stdout ) . unwrap ( ) ;
1972
+ assert_eq ! (
1973
+ & stdout,
1974
+ for_host!(
1975
+ r"nightly-{0} (default)
1976
+ "
1977
+ )
1978
+ ) ;
1979
+ } ) ;
1980
+ }
Original file line number Diff line number Diff line change @@ -446,6 +446,13 @@ pub fn env<E: rustup_test::Env>(config: &Config, cmd: &mut E) {
446
446
. join ( "tests/mock/signing-key.pub.asc" ) ,
447
447
) ;
448
448
449
+ // The unix fallback settings file may be present in the test environment, so override
450
+ // the path to the settings file with a non-existing path to avoid intereference
451
+ cmd. env (
452
+ "RUSTUP_OVERRIDE_UNIX_FALLBACK_SETTINGS" ,
453
+ "/bogus-config-file.toml" ,
454
+ ) ;
455
+
449
456
if let Some ( root) = config. rustup_update_root . as_ref ( ) {
450
457
cmd. env ( "RUSTUP_UPDATE_ROOT" , root) ;
451
458
}
You can’t perform that action at this time.
0 commit comments