11use colored:: * ;
22use regex:: bytes:: Regex ;
3- use std:: io :: Write ;
3+ use std:: ffi :: OsString ;
44use std:: path:: { Path , PathBuf } ;
55use std:: { env, process:: Command } ;
66use ui_test:: status_emitter:: StatusEmitter ;
@@ -46,13 +46,7 @@ fn build_so_for_c_ffi_tests() -> PathBuf {
4646 so_file_path
4747}
4848
49- fn test_config (
50- args : impl Iterator < Item = String > ,
51- target : & str ,
52- path : & str ,
53- mode : Mode ,
54- with_dependencies : bool ,
55- ) -> Config {
49+ fn test_config ( target : & str , path : & str , mode : Mode , with_dependencies : bool ) -> Config {
5650 // Miri is rustc-like, so we create a default builder for rustc and modify it
5751 let mut program = CommandBuilder :: rustc ( ) ;
5852 program. program = miri_path ( ) ;
@@ -110,9 +104,29 @@ fn test_config(
110104 ..Config :: default ( )
111105 } ;
112106
107+ let use_std = env:: var_os ( "MIRI_NO_STD" ) . is_none ( ) ;
108+
109+ if with_dependencies && use_std {
110+ config. dependencies_crate_manifest_path =
111+ Some ( Path :: new ( "test_dependencies" ) . join ( "Cargo.toml" ) ) ;
112+ config. dependency_builder . args = vec ! [
113+ "run" . into( ) ,
114+ "--manifest-path" . into( ) ,
115+ "cargo-miri/Cargo.toml" . into( ) ,
116+ "--" . into( ) ,
117+ "miri" . into( ) ,
118+ "run" . into( ) , // There is no `cargo miri build` so we just use `cargo miri run`.
119+ ] ;
120+ }
121+ config
122+ }
123+
124+ fn run_tests ( mode : Mode , path : & str , target : & str , with_dependencies : bool ) -> Result < ( ) > {
125+ let mut config = test_config ( target, path, mode, with_dependencies) ;
126+
113127 // Handle command-line arguments.
114128 let mut after_dashdash = false ;
115- config. path_filter . extend ( args. filter ( |arg| {
129+ config. path_filter . extend ( std :: env :: args ( ) . skip ( 1 ) . filter ( |arg| {
116130 if after_dashdash {
117131 // Just propagate everything.
118132 return true ;
@@ -133,26 +147,6 @@ fn test_config(
133147 }
134148 } ) ) ;
135149
136- let use_std = env:: var_os ( "MIRI_NO_STD" ) . is_none ( ) ;
137-
138- if with_dependencies && use_std {
139- config. dependencies_crate_manifest_path =
140- Some ( Path :: new ( "test_dependencies" ) . join ( "Cargo.toml" ) ) ;
141- config. dependency_builder . args = vec ! [
142- "run" . into( ) ,
143- "--manifest-path" . into( ) ,
144- "cargo-miri/Cargo.toml" . into( ) ,
145- "--" . into( ) ,
146- "miri" . into( ) ,
147- "run" . into( ) , // There is no `cargo miri build` so we just use `cargo miri run`.
148- ] ;
149- }
150- config
151- }
152-
153- fn run_tests ( mode : Mode , path : & str , target : & str , with_dependencies : bool ) -> Result < ( ) > {
154- let config = test_config ( std:: env:: args ( ) . skip ( 1 ) , target, path, mode, with_dependencies) ;
155-
156150 eprintln ! ( " Compiler: {}" , config. program. display( ) ) ;
157151 ui_test:: run_tests_generic (
158152 config,
@@ -241,9 +235,12 @@ fn main() -> Result<()> {
241235
242236 let target = get_target ( ) ;
243237
244- if let Some ( first) = std:: env:: args ( ) . nth ( 1 ) {
238+ let mut args = std:: env:: args_os ( ) ;
239+
240+ // Skip the program name and check whether this is a `./miri run-dep` invocation
241+ if let Some ( first) = args. nth ( 1 ) {
245242 if first == "--miri-run-dep-mode" {
246- return run_dep_mode ( target) ;
243+ return run_dep_mode ( target, args ) ;
247244 }
248245 }
249246
@@ -269,19 +266,17 @@ fn main() -> Result<()> {
269266 Ok ( ( ) )
270267}
271268
272- fn run_dep_mode ( target : String ) -> Result < ( ) > {
273- let files = std:: env:: args ( ) . skip ( 2 ) ;
274- for path in files {
275- let mut config = test_config ( std:: iter:: empty ( ) , & target, & path, Mode :: Yolo , true ) ;
276- config. program . args . remove ( 0 ) ; // remove the `--error-format=json` argument
277- config. program . args . push ( "--color" . into ( ) ) ;
278- config. program . args . push ( "always" . into ( ) ) ;
279- let output = ui_test:: run_file ( config, Path :: new ( & path) ) ?;
280- std:: io:: stderr ( ) . write_all ( & output. stderr ) ?;
281- std:: io:: stdout ( ) . write_all ( & output. stdout ) ?;
282- std:: process:: exit ( output. status . code ( ) . unwrap ( ) ) ;
283- }
284- Ok ( ( ) )
269+ fn run_dep_mode ( target : String , mut args : impl Iterator < Item = OsString > ) -> Result < ( ) > {
270+ let path = args. next ( ) . expect ( "./miri run-dep must be followed by a file name" ) ;
271+ let mut config = test_config ( & target, "" , Mode :: Yolo , true ) ;
272+ config. program . args . remove ( 0 ) ; // remove the `--error-format=json` argument
273+ config. program . args . push ( "--color" . into ( ) ) ;
274+ config. program . args . push ( "always" . into ( ) ) ;
275+ let mut cmd = ui_test:: test_command ( config, Path :: new ( & path) ) ?;
276+ cmd. arg ( "--" ) ;
277+ cmd. args ( args) ;
278+ println ! ( "{cmd:?}" ) ;
279+ if cmd. spawn ( ) ?. wait ( ) ?. success ( ) { Ok ( ( ) ) } else { std:: process:: exit ( 1 ) }
285280}
286281
287282/// This is a custom renderer for `ui_test` output that does not emit github actions
0 commit comments