1
1
use colored:: * ;
2
2
use regex:: bytes:: Regex ;
3
+ use std:: ffi:: OsString ;
3
4
use std:: path:: { Path , PathBuf } ;
4
5
use std:: { env, process:: Command } ;
5
6
use ui_test:: status_emitter:: StatusEmitter ;
@@ -45,7 +46,7 @@ fn build_so_for_c_ffi_tests() -> PathBuf {
45
46
so_file_path
46
47
}
47
48
48
- fn run_tests ( mode : Mode , path : & str , target : & str , with_dependencies : bool ) -> Result < ( ) > {
49
+ fn test_config ( target : & str , path : & str , mode : Mode , with_dependencies : bool ) -> Config {
49
50
// Miri is rustc-like, so we create a default builder for rustc and modify it
50
51
let mut program = CommandBuilder :: rustc ( ) ;
51
52
program. program = miri_path ( ) ;
@@ -103,6 +104,26 @@ fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> R
103
104
..Config :: default ( )
104
105
} ;
105
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
+
106
127
// Handle command-line arguments.
107
128
let mut after_dashdash = false ;
108
129
config. path_filter . extend ( std:: env:: args ( ) . skip ( 1 ) . filter ( |arg| {
@@ -126,21 +147,6 @@ fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> R
126
147
}
127
148
} ) ) ;
128
149
129
- let use_std = env:: var_os ( "MIRI_NO_STD" ) . is_none ( ) ;
130
-
131
- if with_dependencies && use_std {
132
- config. dependencies_crate_manifest_path =
133
- Some ( Path :: new ( "test_dependencies" ) . join ( "Cargo.toml" ) ) ;
134
- config. dependency_builder . args = vec ! [
135
- "run" . into( ) ,
136
- "--manifest-path" . into( ) ,
137
- "cargo-miri/Cargo.toml" . into( ) ,
138
- "--" . into( ) ,
139
- "miri" . into( ) ,
140
- "run" . into( ) , // There is no `cargo miri build` so we just use `cargo miri run`.
141
- ] ;
142
- }
143
-
144
150
eprintln ! ( " Compiler: {}" , config. program. display( ) ) ;
145
151
ui_test:: run_tests_generic (
146
152
config,
@@ -226,8 +232,18 @@ fn get_target() -> String {
226
232
227
233
fn main ( ) -> Result < ( ) > {
228
234
ui_test:: color_eyre:: install ( ) ?;
235
+
229
236
let target = get_target ( ) ;
230
237
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 ) {
242
+ if first == "--miri-run-dep-mode" {
243
+ return run_dep_mode ( target, args) ;
244
+ }
245
+ }
246
+
231
247
// Add a test env var to do environment communication tests.
232
248
env:: set_var ( "MIRI_ENV_VAR_TEST" , "0" ) ;
233
249
// Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
@@ -250,6 +266,21 @@ fn main() -> Result<()> {
250
266
Ok ( ( ) )
251
267
}
252
268
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 , /* with dependencies */ 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
+ // Separate the arguments to the `cargo miri` invocation from
277
+ // the arguments to the interpreted prog
278
+ cmd. arg ( "--" ) ;
279
+ cmd. args ( args) ;
280
+ println ! ( "{cmd:?}" ) ;
281
+ if cmd. spawn ( ) ?. wait ( ) ?. success ( ) { Ok ( ( ) ) } else { std:: process:: exit ( 1 ) }
282
+ }
283
+
253
284
/// This is a custom renderer for `ui_test` output that does not emit github actions
254
285
/// `group`s, while still producing regular github actions messages on test failures.
255
286
struct TextAndGha ;
0 commit comments