@@ -15,8 +15,8 @@ use tempfile::TempDir;
15
15
const BIN_NAME : & str = "ruff" ;
16
16
const STDIN_BASE_OPTIONS : & [ & str ] = & [ "check" , "--no-cache" , "--output-format" , "concise" ] ;
17
17
18
- fn tempdir_filter ( tempdir : & TempDir ) -> String {
19
- format ! ( r"{}\\?/?" , escape( tempdir . path( ) . to_str( ) . unwrap( ) ) )
18
+ fn tempdir_filter ( path : impl AsRef < Path > ) -> String {
19
+ format ! ( r"{}\\?/?" , escape( path. as_ref ( ) . to_str( ) . unwrap( ) ) )
20
20
}
21
21
22
22
#[ test]
@@ -609,6 +609,139 @@ fn extend_passed_via_config_argument() {
609
609
" ) ;
610
610
}
611
611
612
+ #[ test]
613
+ fn nonexistent_extend_file ( ) -> Result < ( ) > {
614
+ let tempdir = TempDir :: new ( ) ?;
615
+ let project_dir = tempdir. path ( ) . canonicalize ( ) ?;
616
+ fs:: write (
617
+ project_dir. join ( "ruff.toml" ) ,
618
+ r#"
619
+ extend = "ruff2.toml"
620
+ "# ,
621
+ ) ?;
622
+
623
+ fs:: write (
624
+ project_dir. join ( "ruff2.toml" ) ,
625
+ r#"
626
+ extend = "ruff3.toml"
627
+ "# ,
628
+ ) ?;
629
+
630
+ insta:: with_settings!( {
631
+ filters => vec![
632
+ ( tempdir_filter( & project_dir) . as_str( ) , "[TMP]/" ) ,
633
+ ( "The system cannot find the file specified." , "No such file or directory" )
634
+ ]
635
+ } , {
636
+ assert_cmd_snapshot!( Command :: new( get_cargo_bin( BIN_NAME ) )
637
+ . args( [ "check" ] ) . current_dir( project_dir) , @r"
638
+ success: false
639
+ exit_code: 2
640
+ ----- stdout -----
641
+
642
+ ----- stderr -----
643
+ ruff failed
644
+ Cause: Failed to load extended configuration `[TMP]/ruff3.toml` (`[TMP]/ruff.toml` extends `[TMP]/ruff2.toml` extends `[TMP]/ruff3.toml`)
645
+ Cause: Failed to read [TMP]/ruff3.toml
646
+ Cause: No such file or directory (os error 2)
647
+ " ) ;
648
+ } ) ;
649
+
650
+ Ok ( ( ) )
651
+ }
652
+
653
+ #[ test]
654
+ fn circular_extend ( ) -> Result < ( ) > {
655
+ let tempdir = TempDir :: new ( ) ?;
656
+ let project_path = tempdir. path ( ) . canonicalize ( ) ?;
657
+
658
+ fs:: write (
659
+ project_path. join ( "ruff.toml" ) ,
660
+ r#"
661
+ extend = "ruff2.toml"
662
+ "# ,
663
+ ) ?;
664
+ fs:: write (
665
+ project_path. join ( "ruff2.toml" ) ,
666
+ r#"
667
+ extend = "ruff3.toml"
668
+ "# ,
669
+ ) ?;
670
+ fs:: write (
671
+ project_path. join ( "ruff3.toml" ) ,
672
+ r#"
673
+ extend = "ruff.toml"
674
+ "# ,
675
+ ) ?;
676
+
677
+ insta:: with_settings!( {
678
+ filters => vec![ ( tempdir_filter( & project_path) . as_str( ) , "[TMP]/" ) ]
679
+ } , {
680
+ assert_cmd_snapshot!(
681
+ Command :: new( get_cargo_bin( BIN_NAME ) )
682
+ . args( [ "check" ] )
683
+ . current_dir( project_path) ,
684
+ @r"
685
+ success: false
686
+ exit_code: 2
687
+ ----- stdout -----
688
+
689
+ ----- stderr -----
690
+ ruff failed
691
+ Cause: Circular configuration detected: `[TMP]/ruff.toml` extends `[TMP]/ruff2.toml` extends `[TMP]/ruff3.toml` extends `[TMP]/ruff.toml`
692
+ " ) ;
693
+ } ) ;
694
+
695
+ Ok ( ( ) )
696
+ }
697
+
698
+ #[ test]
699
+ fn parse_error_extends ( ) -> Result < ( ) > {
700
+ let tempdir = TempDir :: new ( ) ?;
701
+ let project_path = tempdir. path ( ) . canonicalize ( ) ?;
702
+
703
+ fs:: write (
704
+ project_path. join ( "ruff.toml" ) ,
705
+ r#"
706
+ extend = "ruff2.toml"
707
+ "# ,
708
+ ) ?;
709
+ fs:: write (
710
+ project_path. join ( "ruff2.toml" ) ,
711
+ r#"
712
+ [lint]
713
+ select = [E501]
714
+ "# ,
715
+ ) ?;
716
+
717
+ insta:: with_settings!( {
718
+ filters => vec![ ( tempdir_filter( & project_path) . as_str( ) , "[TMP]/" ) ]
719
+ } , {
720
+ assert_cmd_snapshot!(
721
+ Command :: new( get_cargo_bin( BIN_NAME ) )
722
+ . args( [ "check" ] )
723
+ . current_dir( project_path) ,
724
+ @r"
725
+ success: false
726
+ exit_code: 2
727
+ ----- stdout -----
728
+
729
+ ----- stderr -----
730
+ ruff failed
731
+ Cause: Failed to load extended configuration `[TMP]/ruff2.toml` (`[TMP]/ruff.toml` extends `[TMP]/ruff2.toml`)
732
+ Cause: Failed to parse [TMP]/ruff2.toml
733
+ Cause: TOML parse error at line 3, column 11
734
+ |
735
+ 3 | select = [E501]
736
+ | ^
737
+ invalid array
738
+ expected `]`
739
+ " ) ;
740
+ } ) ;
741
+
742
+ Ok ( ( ) )
743
+ }
744
+
612
745
#[ test]
613
746
fn config_file_and_isolated ( ) -> Result < ( ) > {
614
747
let tempdir = TempDir :: new ( ) ?;
@@ -2095,6 +2228,7 @@ fn flake8_import_convention_invalid_aliases_config_alias_name() -> Result<()> {
2095
2228
2096
2229
----- stderr -----
2097
2230
ruff failed
2231
+ Cause: Failed to load configuration `[TMP]/ruff.toml`
2098
2232
Cause: Failed to parse [TMP]/ruff.toml
2099
2233
Cause: TOML parse error at line 3, column 17
2100
2234
|
@@ -2131,6 +2265,7 @@ fn flake8_import_convention_invalid_aliases_config_extend_alias_name() -> Result
2131
2265
2132
2266
----- stderr -----
2133
2267
ruff failed
2268
+ Cause: Failed to load configuration `[TMP]/ruff.toml`
2134
2269
Cause: Failed to parse [TMP]/ruff.toml
2135
2270
Cause: TOML parse error at line 3, column 17
2136
2271
|
@@ -2167,6 +2302,7 @@ fn flake8_import_convention_invalid_aliases_config_module_name() -> Result<()> {
2167
2302
2168
2303
----- stderr -----
2169
2304
ruff failed
2305
+ Cause: Failed to load configuration `[TMP]/ruff.toml`
2170
2306
Cause: Failed to parse [TMP]/ruff.toml
2171
2307
Cause: TOML parse error at line 3, column 1
2172
2308
|
@@ -2429,6 +2565,5 @@ fn a005_module_shadowing_strict_default() -> Result<()> {
2429
2565
----- stderr -----
2430
2566
" ) ;
2431
2567
} ) ;
2432
-
2433
2568
Ok ( ( ) )
2434
2569
}
0 commit comments