1
1
use colored:: * ;
2
2
use regex:: bytes:: Regex ;
3
- use std:: io :: Write ;
3
+ use std:: ffi :: OsString ;
4
4
use std:: path:: { Path , PathBuf } ;
5
5
use std:: { env, process:: Command } ;
6
6
use ui_test:: status_emitter:: StatusEmitter ;
@@ -46,13 +46,7 @@ fn build_so_for_c_ffi_tests() -> PathBuf {
46
46
so_file_path
47
47
}
48
48
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 {
56
50
// Miri is rustc-like, so we create a default builder for rustc and modify it
57
51
let mut program = CommandBuilder :: rustc ( ) ;
58
52
program. program = miri_path ( ) ;
@@ -110,9 +104,29 @@ fn test_config(
110
104
..Config :: default ( )
111
105
} ;
112
106
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
+
113
127
// Handle command-line arguments.
114
128
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| {
116
130
if after_dashdash {
117
131
// Just propagate everything.
118
132
return true ;
@@ -133,26 +147,6 @@ fn test_config(
133
147
}
134
148
} ) ) ;
135
149
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
-
156
150
eprintln ! ( " Compiler: {}" , config. program. display( ) ) ;
157
151
ui_test:: run_tests_generic (
158
152
config,
@@ -241,9 +235,12 @@ fn main() -> Result<()> {
241
235
242
236
let target = get_target ( ) ;
243
237
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 ) {
245
242
if first == "--miri-run-dep-mode" {
246
- return run_dep_mode ( target) ;
243
+ return run_dep_mode ( target, args ) ;
247
244
}
248
245
}
249
246
@@ -269,19 +266,17 @@ fn main() -> Result<()> {
269
266
Ok ( ( ) )
270
267
}
271
268
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 ) }
285
280
}
286
281
287
282
/// This is a custom renderer for `ui_test` output that does not emit github actions
0 commit comments