1+ use std:: process:: Command ;
2+
13use insta_cmd:: assert_cmd_snapshot;
24
35use crate :: CliTest ;
46
57#[ test]
68fn type_checking_imports ( ) -> anyhow:: Result < ( ) > {
7- let test = CliTest :: with_files ( [
9+ let test = AnalyzeTest :: with_files ( [
810 ( "ruff/__init__.py" , "" ) ,
911 (
1012 "ruff/a.py" ,
@@ -27,7 +29,7 @@ fn type_checking_imports() -> anyhow::Result<()> {
2729 ( "ruff/c.py" , "" ) ,
2830 ] ) ?;
2931
30- assert_cmd_snapshot ! ( test. analyze_graph_command ( ) , @r###"
32+ assert_cmd_snapshot ! ( test. command ( ) , @r###"
3133 success: true
3234 exit_code: 0
3335 ----- stdout -----
@@ -47,7 +49,7 @@ fn type_checking_imports() -> anyhow::Result<()> {
4749 "### ) ;
4850
4951 assert_cmd_snapshot ! (
50- test. analyze_graph_command ( )
52+ test. command ( )
5153 . arg( "--no-type-checking-imports" ) ,
5254 @r###"
5355 success: true
@@ -71,7 +73,7 @@ fn type_checking_imports() -> anyhow::Result<()> {
7173
7274#[ test]
7375fn type_checking_imports_from_config ( ) -> anyhow:: Result < ( ) > {
74- let test = CliTest :: with_files ( [
76+ let test = AnalyzeTest :: with_files ( [
7577 ( "ruff/__init__.py" , "" ) ,
7678 (
7779 "ruff/a.py" ,
@@ -101,7 +103,7 @@ fn type_checking_imports_from_config() -> anyhow::Result<()> {
101103 ) ,
102104 ] ) ?;
103105
104- assert_cmd_snapshot ! ( test. analyze_graph_command ( ) , @r###"
106+ assert_cmd_snapshot ! ( test. command ( ) , @r###"
105107 success: true
106108 exit_code: 0
107109 ----- stdout -----
@@ -125,7 +127,7 @@ fn type_checking_imports_from_config() -> anyhow::Result<()> {
125127 "# ,
126128 ) ?;
127129
128- assert_cmd_snapshot ! ( test. analyze_graph_command ( ) , @r###"
130+ assert_cmd_snapshot ! ( test. command ( ) , @r###"
129131 success: true
130132 exit_code: 0
131133 ----- stdout -----
@@ -148,10 +150,44 @@ fn type_checking_imports_from_config() -> anyhow::Result<()> {
148150 Ok ( ( ) )
149151}
150152
151- impl CliTest {
152- fn analyze_graph_command ( & self ) -> std:: process:: Command {
153- let mut command = self . command ( ) ;
153+ struct AnalyzeTest {
154+ cli_test : CliTest ,
155+ }
156+
157+ impl AnalyzeTest {
158+ pub ( crate ) fn new ( ) -> anyhow:: Result < Self > {
159+ Ok ( Self {
160+ cli_test : CliTest :: with_settings ( |_, mut settings| {
161+ settings. add_filter ( r#"\\"# , "/" ) ;
162+ settings
163+ } ) ?,
164+ } )
165+ }
166+
167+ fn with_files < ' a > ( files : impl IntoIterator < Item = ( & ' a str , & ' a str ) > ) -> anyhow:: Result < Self > {
168+ let case = Self :: new ( ) ?;
169+ case. write_files ( files) ?;
170+ Ok ( case)
171+ }
172+
173+ #[ expect( unused) ]
174+ fn with_file ( path : impl AsRef < std:: path:: Path > , content : & str ) -> anyhow:: Result < Self > {
175+ let fixture = Self :: new ( ) ?;
176+ fixture. write_file ( path, content) ?;
177+ Ok ( fixture)
178+ }
179+
180+ fn command ( & self ) -> Command {
181+ let mut command = self . cli_test . command ( ) ;
154182 command. arg ( "analyze" ) . arg ( "graph" ) . arg ( "--preview" ) ;
155183 command
156184 }
157185}
186+
187+ impl std:: ops:: Deref for AnalyzeTest {
188+ type Target = CliTest ;
189+
190+ fn deref ( & self ) -> & Self :: Target {
191+ & self . cli_test
192+ }
193+ }
0 commit comments