@@ -16,6 +16,7 @@ use std::{
16
16
17
17
use enum_map:: { enum_map, Enum , EnumMap } ;
18
18
use once_cell:: sync:: Lazy ;
19
+ use tempfile:: TempDir ;
19
20
use tokio:: runtime:: Builder ;
20
21
use url:: Url ;
21
22
@@ -302,25 +303,34 @@ pub fn setup_test_state(test_dist_dir: tempfile::TempDir) -> (tempfile::TempDir,
302
303
( test_dir, config)
303
304
}
304
305
305
- /// Run this to create the test environment containing rustup, and
306
- /// a mock dist server.
307
306
pub fn test ( s : Scenario , f : & dyn Fn ( & mut Config ) ) {
308
- // Things we might cache or what not
307
+ let mut cx = CliTestContext :: from ( s) ;
308
+ f ( & mut cx. config ) ;
309
+ }
310
+
311
+ pub struct CliTestContext {
312
+ pub config : Config ,
313
+ _test_dir : TempDir ,
314
+ }
309
315
310
- // Mutable dist server - working toward elimination
311
- let test_dist_dir = crate :: test :: test_dist_dir ( ) . unwrap ( ) ;
312
- create_mock_dist_server ( test_dist_dir . path ( ) , s ) ;
316
+ impl From < Scenario > for CliTestContext {
317
+ fn from ( scenario : Scenario ) -> Self {
318
+ // Things we might cache or what not
313
319
314
- // Things that are just about the test itself
315
- let ( _test_dir, mut config) = setup_test_state ( test_dist_dir) ;
316
- // Pulled out of setup_test_state for clarity: the long term intent is to
317
- // not have this at all.
318
- if s != Scenario :: None {
319
- config. distdir = Some ( config. test_dist_dir . path ( ) . to_path_buf ( ) ) ;
320
- }
320
+ // Mutable dist server - working toward elimination
321
+ let test_dist_dir = crate :: test:: test_dist_dir ( ) . unwrap ( ) ;
322
+ create_mock_dist_server ( test_dist_dir. path ( ) , scenario) ;
321
323
322
- // Run the test
323
- f ( & mut config) ;
324
+ // Things that are just about the test itself
325
+ let ( _test_dir, mut config) = setup_test_state ( test_dist_dir) ;
326
+ // Pulled out of setup_test_state for clarity: the long term intent is to
327
+ // not have this at all.
328
+ if scenario != Scenario :: None {
329
+ config. distdir = Some ( config. test_dist_dir . path ( ) . to_path_buf ( ) ) ;
330
+ }
331
+
332
+ Self { config, _test_dir }
333
+ }
324
334
}
325
335
326
336
fn create_local_update_server ( self_dist : & Path , exedir : & Path , version : & str ) -> String {
0 commit comments