@@ -30,26 +30,6 @@ fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
30
30
toml:: from_str ( & contents) . and_then ( |table : toml:: Value | TomlConfig :: deserialize ( table) )
31
31
}
32
32
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
-
53
33
#[ test]
54
34
fn download_ci_llvm ( ) {
55
35
let config = TestCtx :: new ( ) . config ( "check" ) . create_config ( ) ;
@@ -505,16 +485,8 @@ fn test_ci_flag() {
505
485
506
486
#[ test]
507
487
fn 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 ( ) ;
518
490
519
491
let extension = testdir. join ( "extension.toml" ) ;
520
492
let extension_content = br#"
@@ -535,10 +507,17 @@ fn test_precedence_of_includes() {
535
507
"# ;
536
508
File :: create ( extension) . unwrap ( ) . write_all ( extension_content) . unwrap ( ) ;
537
509
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 ( ) ;
542
521
543
522
assert_eq ! ( config. change_id. unwrap( ) , ChangeId :: Id ( 543 ) ) ;
544
523
assert_eq ! ( config. llvm_link_jobs. unwrap( ) , 2 ) ;
@@ -548,36 +527,29 @@ fn test_precedence_of_includes() {
548
527
#[ test]
549
528
#[ should_panic( expected = "Cyclic inclusion detected" ) ]
550
529
fn 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 ( ) ;
559
532
let extension = testdir. join ( "extension.toml" ) ;
560
533
let extension_content = br#"
561
- include = ["./config .toml"]
534
+ include = ["./bootstrap .toml"]
562
535
"# ;
563
536
File :: create ( extension) . unwrap ( ) . write_all ( extension_content) . unwrap ( ) ;
564
537
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 ( ) ;
569
546
}
570
547
571
548
#[ test]
572
549
#[ should_panic( expected = "Cyclic inclusion detected" ) ]
573
550
fn 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 ( ) ;
581
553
582
554
let extension = testdir. join ( "extension.toml" ) ;
583
555
let extension_content = br#"
@@ -597,43 +569,37 @@ fn test_cyclic_include_indirect() {
597
569
"# ;
598
570
File :: create ( extension) . unwrap ( ) . write_all ( extension_content) . unwrap ( ) ;
599
571
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 ( ) ;
604
580
}
605
581
606
582
#[ test]
607
583
fn test_include_absolute_paths ( ) {
608
- let testdir = prepare_test_specific_dir ( ) ;
584
+ let test_ctx = TestCtx :: new ( ) ;
585
+ let testdir = test_ctx. dir ( ) ;
609
586
610
587
let extension = testdir. join ( "extension.toml" ) ;
611
588
File :: create ( & extension) . unwrap ( ) . write_all ( & [ ] ) . unwrap ( ) ;
612
589
613
- let root_config = testdir. join ( "config.toml" ) ;
614
590
let extension_absolute_path =
615
591
extension. canonicalize ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . replace ( '\\' , r"\\" ) ;
616
592
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 ( ) ;
623
594
}
624
595
625
596
#[ test]
626
597
fn test_include_relative_paths ( ) {
627
- let testdir = prepare_test_specific_dir ( ) ;
598
+ let test_ctx = TestCtx :: new ( ) ;
599
+ let testdir = test_ctx. dir ( ) ;
628
600
629
601
let _ = fs:: create_dir_all ( & testdir. join ( "subdir/another_subdir" ) ) ;
630
602
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
-
637
603
let extension = testdir. join ( "subdir/extension.toml" ) ;
638
604
let extension_content = br#"
639
605
include = ["../extension2.toml"]
@@ -655,22 +621,20 @@ fn test_include_relative_paths() {
655
621
let extension = testdir. join ( "extension4.toml" ) ;
656
622
File :: create ( extension) . unwrap ( ) . write_all ( & [ ] ) . unwrap ( ) ;
657
623
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 ( ) ;
662
632
}
663
633
664
634
#[ test]
665
635
fn 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 ( ) ;
674
638
675
639
let extension = testdir. join ( "extension.toml" ) ;
676
640
let extension_content = br#"
@@ -679,10 +643,22 @@ fn test_include_precedence_over_profile() {
679
643
"# ;
680
644
File :: create ( extension) . unwrap ( ) . write_all ( extension_content) . unwrap ( ) ;
681
645
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 ( ) ;
686
662
687
663
// "dist" profile would normally set the channel to "auto-detect", but includes should
688
664
// override profile settings, so we expect this to be "dev" here.
0 commit comments