@@ -30,26 +30,6 @@ fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
3030 toml:: from_str ( & contents) . and_then ( |table : toml:: Value | TomlConfig :: deserialize ( table) )
3131}
3232
33- /// Helps with debugging by using consistent test-specific directories instead of
34- /// random temporary directories.
35- fn prepare_test_specific_dir ( ) -> PathBuf {
36- let current = std:: thread:: current ( ) ;
37- // Replace "::" with "_" to make it safe for directory names on Windows systems
38- let test_path = current. name ( ) . unwrap ( ) . replace ( "::" , "_" ) ;
39-
40- let testdir = crate :: utils:: tests:: TestCtx :: new ( )
41- . config ( "check" )
42- . create_config ( )
43- . tempdir ( )
44- . join ( test_path) ;
45-
46- // clean up any old test files
47- let _ = fs:: remove_dir_all ( & testdir) ;
48- let _ = fs:: create_dir_all ( & testdir) ;
49-
50- testdir
51- }
52-
5333#[ test]
5434fn download_ci_llvm ( ) {
5535 let config = TestCtx :: new ( ) . config ( "check" ) . create_config ( ) ;
@@ -505,16 +485,8 @@ fn test_ci_flag() {
505485
506486#[ test]
507487fn test_precedence_of_includes ( ) {
508- let testdir = prepare_test_specific_dir ( ) ;
509-
510- let root_config = testdir. join ( "config.toml" ) ;
511- let root_config_content = br#"
512- include = ["./extension.toml"]
513-
514- [llvm]
515- link-jobs = 2
516- "# ;
517- File :: create ( & root_config) . unwrap ( ) . write_all ( root_config_content) . unwrap ( ) ;
488+ let test_ctx = TestCtx :: new ( ) ;
489+ let testdir = test_ctx. dir ( ) ;
518490
519491 let extension = testdir. join ( "extension.toml" ) ;
520492 let extension_content = br#"
@@ -535,10 +507,17 @@ fn test_precedence_of_includes() {
535507 "# ;
536508 File :: create ( extension) . unwrap ( ) . write_all ( extension_content) . unwrap ( ) ;
537509
538- let config = Config :: parse_inner (
539- Flags :: parse ( & [ "check" . to_owned ( ) , format ! ( "--config={}" , root_config. to_str( ) . unwrap( ) ) ] ) ,
540- get_toml,
541- ) ;
510+ let config = test_ctx
511+ . config ( "check" )
512+ . with_default_toml_config (
513+ r#"
514+ include = ["./extension.toml"]
515+
516+ [llvm]
517+ link-jobs = 2
518+ "# ,
519+ )
520+ . create_config ( ) ;
542521
543522 assert_eq ! ( config. change_id. unwrap( ) , ChangeId :: Id ( 543 ) ) ;
544523 assert_eq ! ( config. llvm_link_jobs. unwrap( ) , 2 ) ;
@@ -548,36 +527,29 @@ fn test_precedence_of_includes() {
548527#[ test]
549528#[ should_panic( expected = "Cyclic inclusion detected" ) ]
550529fn test_cyclic_include_direct ( ) {
551- let testdir = prepare_test_specific_dir ( ) ;
552-
553- let root_config = testdir. join ( "config.toml" ) ;
554- let root_config_content = br#"
555- include = ["./extension.toml"]
556- "# ;
557- File :: create ( & root_config) . unwrap ( ) . write_all ( root_config_content) . unwrap ( ) ;
558-
530+ let test_ctx = TestCtx :: new ( ) ;
531+ let testdir = test_ctx. dir ( ) ;
559532 let extension = testdir. join ( "extension.toml" ) ;
560533 let extension_content = br#"
561- include = ["./config .toml"]
534+ include = ["./bootstrap .toml"]
562535 "# ;
563536 File :: create ( extension) . unwrap ( ) . write_all ( extension_content) . unwrap ( ) ;
564537
565- let config = Config :: parse_inner (
566- Flags :: parse ( & [ "check" . to_owned ( ) , format ! ( "--config={}" , root_config. to_str( ) . unwrap( ) ) ] ) ,
567- get_toml,
568- ) ;
538+ test_ctx
539+ . config ( "check" )
540+ . with_default_toml_config (
541+ r#"
542+ include = ["./extension.toml"]
543+ "# ,
544+ )
545+ . create_config ( ) ;
569546}
570547
571548#[ test]
572549#[ should_panic( expected = "Cyclic inclusion detected" ) ]
573550fn test_cyclic_include_indirect ( ) {
574- let testdir = prepare_test_specific_dir ( ) ;
575-
576- let root_config = testdir. join ( "config.toml" ) ;
577- let root_config_content = br#"
578- include = ["./extension.toml"]
579- "# ;
580- File :: create ( & root_config) . unwrap ( ) . write_all ( root_config_content) . unwrap ( ) ;
551+ let test_ctx = TestCtx :: new ( ) ;
552+ let testdir = test_ctx. dir ( ) ;
581553
582554 let extension = testdir. join ( "extension.toml" ) ;
583555 let extension_content = br#"
@@ -597,43 +569,37 @@ fn test_cyclic_include_indirect() {
597569 "# ;
598570 File :: create ( extension) . unwrap ( ) . write_all ( extension_content) . unwrap ( ) ;
599571
600- let config = Config :: parse_inner (
601- Flags :: parse ( & [ "check" . to_owned ( ) , format ! ( "--config={}" , root_config. to_str( ) . unwrap( ) ) ] ) ,
602- get_toml,
603- ) ;
572+ test_ctx
573+ . config ( "check" )
574+ . with_default_toml_config (
575+ r#"
576+ include = ["./extension.toml"]
577+ "# ,
578+ )
579+ . create_config ( ) ;
604580}
605581
606582#[ test]
607583fn test_include_absolute_paths ( ) {
608- let testdir = prepare_test_specific_dir ( ) ;
584+ let test_ctx = TestCtx :: new ( ) ;
585+ let testdir = test_ctx. dir ( ) ;
609586
610587 let extension = testdir. join ( "extension.toml" ) ;
611588 File :: create ( & extension) . unwrap ( ) . write_all ( & [ ] ) . unwrap ( ) ;
612589
613- let root_config = testdir. join ( "config.toml" ) ;
614590 let extension_absolute_path =
615591 extension. canonicalize ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . replace ( '\\' , r"\\" ) ;
616592 let root_config_content = format ! ( r#"include = ["{}"]"# , extension_absolute_path) ;
617- File :: create ( & root_config) . unwrap ( ) . write_all ( root_config_content. as_bytes ( ) ) . unwrap ( ) ;
618-
619- let config = Config :: parse_inner (
620- Flags :: parse ( & [ "check" . to_owned ( ) , format ! ( "--config={}" , root_config. to_str( ) . unwrap( ) ) ] ) ,
621- get_toml,
622- ) ;
593+ test_ctx. config ( "check" ) . with_default_toml_config ( & root_config_content) . create_config ( ) ;
623594}
624595
625596#[ test]
626597fn test_include_relative_paths ( ) {
627- let testdir = prepare_test_specific_dir ( ) ;
598+ let test_ctx = TestCtx :: new ( ) ;
599+ let testdir = test_ctx. dir ( ) ;
628600
629601 let _ = fs:: create_dir_all ( & testdir. join ( "subdir/another_subdir" ) ) ;
630602
631- let root_config = testdir. join ( "config.toml" ) ;
632- let root_config_content = br#"
633- include = ["./subdir/extension.toml"]
634- "# ;
635- File :: create ( & root_config) . unwrap ( ) . write_all ( root_config_content) . unwrap ( ) ;
636-
637603 let extension = testdir. join ( "subdir/extension.toml" ) ;
638604 let extension_content = br#"
639605 include = ["../extension2.toml"]
@@ -655,22 +621,20 @@ fn test_include_relative_paths() {
655621 let extension = testdir. join ( "extension4.toml" ) ;
656622 File :: create ( extension) . unwrap ( ) . write_all ( & [ ] ) . unwrap ( ) ;
657623
658- let config = Config :: parse_inner (
659- Flags :: parse ( & [ "check" . to_owned ( ) , format ! ( "--config={}" , root_config. to_str( ) . unwrap( ) ) ] ) ,
660- get_toml,
661- ) ;
624+ test_ctx
625+ . config ( "check" )
626+ . with_default_toml_config (
627+ r#"
628+ include = ["./subdir/extension.toml"]
629+ "# ,
630+ )
631+ . create_config ( ) ;
662632}
663633
664634#[ test]
665635fn test_include_precedence_over_profile ( ) {
666- let testdir = prepare_test_specific_dir ( ) ;
667-
668- let root_config = testdir. join ( "config.toml" ) ;
669- let root_config_content = br#"
670- profile = "dist"
671- include = ["./extension.toml"]
672- "# ;
673- File :: create ( & root_config) . unwrap ( ) . write_all ( root_config_content) . unwrap ( ) ;
636+ let test_ctx = TestCtx :: new ( ) ;
637+ let testdir = test_ctx. dir ( ) ;
674638
675639 let extension = testdir. join ( "extension.toml" ) ;
676640 let extension_content = br#"
@@ -679,10 +643,22 @@ fn test_include_precedence_over_profile() {
679643 "# ;
680644 File :: create ( extension) . unwrap ( ) . write_all ( extension_content) . unwrap ( ) ;
681645
682- let config = Config :: parse_inner (
683- Flags :: parse ( & [ "check" . to_owned ( ) , format ! ( "--config={}" , root_config. to_str( ) . unwrap( ) ) ] ) ,
684- get_toml,
685- ) ;
646+ let root_config = testdir. join ( "config.toml" ) ;
647+ let root_config_content = br#"
648+ profile = "dist"
649+ include = ["./extension.toml"]
650+ "# ;
651+ File :: create ( & root_config) . unwrap ( ) . write_all ( root_config_content) . unwrap ( ) ;
652+
653+ let config = test_ctx
654+ . config ( "check" )
655+ . with_default_toml_config (
656+ r#"
657+ profile = "dist"
658+ include = ["./extension.toml"]
659+ "# ,
660+ )
661+ . create_config ( ) ;
686662
687663 // "dist" profile would normally set the channel to "auto-detect", but includes should
688664 // override profile settings, so we expect this to be "dev" here.
0 commit comments