@@ -192,19 +192,33 @@ impl ConstState {
192192
193193/// State a test can interact and mutate
194194pub async fn setup_test_state ( test_dist_dir : tempfile:: TempDir ) -> ( tempfile:: TempDir , Config ) {
195- // Unset env variables that will break our testing
196- env:: remove_var ( "RUSTUP_UPDATE_ROOT" ) ;
197- env:: remove_var ( "RUSTUP_TOOLCHAIN" ) ;
198- env:: remove_var ( "SHELL" ) ;
199- env:: remove_var ( "ZDOTDIR" ) ;
200- // clap does its own terminal colour probing, and that isn't
201- // trait-controllable, but it does honour the terminal. To avoid testing
202- // claps code, lie about whatever terminal this process was started under.
203- env:: set_var ( "TERM" , "dumb" ) ;
204-
205- match env:: var ( "RUSTUP_BACKTRACE" ) {
206- Ok ( val) => env:: set_var ( "RUST_BACKTRACE" , val) ,
207- _ => env:: remove_var ( "RUST_BACKTRACE" ) ,
195+ // SAFETY: This is probably not the best way of doing such a thing, but it should be
196+ // okay since we are setting the environment variables for the integration tests only.
197+ // There are two types of integration test in rustup: in-process and subprocess.
198+ // For the former, the environment variables are 100% injected via [`TestContext::vars`];
199+ // for the latter, the environment variables in question are only relevant in the
200+ // corresponding subprocesses. Thus, it should be safe to assume that the following won't
201+ // cause inconsistencies as far as **this** particular process is concerned, as long as
202+ // **each subprocess gets the same value for every environment variable listed below when
203+ // it spins off**. To do so, we will have to ensure that:
204+ // - The following `unsafe` block is idempotent, making its output absolutely stable.
205+ // - The environment variables listed below are never modified to anything else
206+ // **in this process** when the tests are still running.
207+ unsafe {
208+ // Unset env variables that will break our testing
209+ env:: remove_var ( "RUSTUP_UPDATE_ROOT" ) ;
210+ env:: remove_var ( "RUSTUP_TOOLCHAIN" ) ;
211+ env:: remove_var ( "SHELL" ) ;
212+ env:: remove_var ( "ZDOTDIR" ) ;
213+ // clap does its own terminal colour probing, and that isn't
214+ // trait-controllable, but it does honour the terminal. To avoid testing
215+ // claps code, lie about whatever terminal this process was started under.
216+ env:: set_var ( "TERM" , "dumb" ) ;
217+
218+ match env:: var ( "RUSTUP_BACKTRACE" ) {
219+ Ok ( val) => env:: set_var ( "RUST_BACKTRACE" , val) ,
220+ _ => env:: remove_var ( "RUST_BACKTRACE" ) ,
221+ }
208222 }
209223
210224 let current_exe_path = env:: current_exe ( ) . unwrap ( ) ;
0 commit comments