@@ -2,6 +2,8 @@ use colored::*;
2
2
use regex:: bytes:: Regex ;
3
3
use std:: path:: { Path , PathBuf } ;
4
4
use std:: { env, process:: Command } ;
5
+ use ui_test:: status_emitter:: StatusEmitter ;
6
+ use ui_test:: CommandBuilder ;
5
7
use ui_test:: { color_eyre:: Result , Config , Match , Mode , OutputConflictHandling } ;
6
8
7
9
fn miri_path ( ) -> PathBuf {
@@ -44,40 +46,30 @@ fn build_so_for_c_ffi_tests() -> PathBuf {
44
46
}
45
47
46
48
fn run_tests ( mode : Mode , path : & str , target : & str , with_dependencies : bool ) -> Result < ( ) > {
47
- let mut config = Config {
48
- target : Some ( target. to_owned ( ) ) ,
49
- stderr_filters : STDERR . clone ( ) ,
50
- stdout_filters : STDOUT . clone ( ) ,
51
- root_dir : PathBuf :: from ( path) ,
52
- mode,
53
- program : miri_path ( ) ,
54
- quiet : false ,
55
- edition : Some ( "2021" . into ( ) ) ,
56
- ..Config :: default ( )
57
- } ;
49
+ // Miri is rustc-like, so we create a default builder for rustc and modify it
50
+ let mut program = CommandBuilder :: rustc ( ) ;
51
+ program. program = miri_path ( ) ;
58
52
59
53
let in_rustc_test_suite = option_env ! ( "RUSTC_STAGE" ) . is_some ( ) ;
60
54
61
55
// Add some flags we always want.
62
56
if in_rustc_test_suite {
63
57
// Less aggressive warnings to make the rustc toolstate management less painful.
64
58
// (We often get warnings when e.g. a feature gets stabilized or some lint gets added/improved.)
65
- config . args . push ( "-Astable-features" . into ( ) ) ;
66
- config . args . push ( "-Aunused" . into ( ) ) ;
59
+ program . args . push ( "-Astable-features" . into ( ) ) ;
60
+ program . args . push ( "-Aunused" . into ( ) ) ;
67
61
} else {
68
- config . args . push ( "-Dwarnings" . into ( ) ) ;
69
- config . args . push ( "-Dunused" . into ( ) ) ;
62
+ program . args . push ( "-Dwarnings" . into ( ) ) ;
63
+ program . args . push ( "-Dunused" . into ( ) ) ;
70
64
}
71
65
if let Ok ( extra_flags) = env:: var ( "MIRIFLAGS" ) {
72
66
for flag in extra_flags. split_whitespace ( ) {
73
- config . args . push ( flag. into ( ) ) ;
67
+ program . args . push ( flag. into ( ) ) ;
74
68
}
75
69
}
76
- config. args . push ( "-Zui-testing" . into ( ) ) ;
77
- if let Some ( target) = & config. target {
78
- config. args . push ( "--target" . into ( ) ) ;
79
- config. args . push ( target. into ( ) ) ;
80
- }
70
+ program. args . push ( "-Zui-testing" . into ( ) ) ;
71
+ program. args . push ( "--target" . into ( ) ) ;
72
+ program. args . push ( target. into ( ) ) ;
81
73
82
74
// If we're on linux, and we're testing the extern-so functionality,
83
75
// then build the shared object file for testing external C function calls
@@ -86,18 +78,31 @@ fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> R
86
78
let so_file_path = build_so_for_c_ffi_tests ( ) ;
87
79
let mut flag = std:: ffi:: OsString :: from ( "-Zmiri-extern-so-file=" ) ;
88
80
flag. push ( so_file_path. into_os_string ( ) ) ;
89
- config . args . push ( flag) ;
81
+ program . args . push ( flag) ;
90
82
}
91
83
92
84
let skip_ui_checks = env:: var_os ( "MIRI_SKIP_UI_CHECKS" ) . is_some ( ) ;
93
85
94
- config . output_conflict_handling = match ( env:: var_os ( "MIRI_BLESS" ) . is_some ( ) , skip_ui_checks) {
86
+ let output_conflict_handling = match ( env:: var_os ( "MIRI_BLESS" ) . is_some ( ) , skip_ui_checks) {
95
87
( false , false ) => OutputConflictHandling :: Error ,
96
88
( true , false ) => OutputConflictHandling :: Bless ,
97
89
( false , true ) => OutputConflictHandling :: Ignore ,
98
90
( true , true ) => panic ! ( "cannot use MIRI_BLESS and MIRI_SKIP_UI_CHECKS at the same time" ) ,
99
91
} ;
100
92
93
+ let mut config = Config {
94
+ target : Some ( target. to_owned ( ) ) ,
95
+ stderr_filters : STDERR . clone ( ) ,
96
+ stdout_filters : STDOUT . clone ( ) ,
97
+ root_dir : PathBuf :: from ( path) ,
98
+ mode,
99
+ program,
100
+ output_conflict_handling,
101
+ quiet : false ,
102
+ edition : Some ( "2021" . into ( ) ) ,
103
+ ..Config :: default ( )
104
+ } ;
105
+
101
106
// Handle command-line arguments.
102
107
let mut after_dashdash = false ;
103
108
config. path_filter . extend ( std:: env:: args ( ) . skip ( 1 ) . filter ( |arg| {
@@ -135,7 +140,14 @@ fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> R
135
140
"run" . into( ) , // There is no `cargo miri build` so we just use `cargo miri run`.
136
141
] ;
137
142
}
138
- ui_test:: run_tests ( config)
143
+ ui_test:: run_tests_generic (
144
+ config,
145
+ // The files we're actually interested in (all `.rs` files).
146
+ |path| path. extension ( ) . is_some_and ( |ext| ext == "rs" ) ,
147
+ // This could be used to overwrite the `Config` on a per-test basis.
148
+ |_, _| None ,
149
+ TextAndGha ,
150
+ )
139
151
}
140
152
141
153
macro_rules! regexes {
@@ -235,3 +247,45 @@ fn main() -> Result<()> {
235
247
236
248
Ok ( ( ) )
237
249
}
250
+
251
+ /// This is a custom renderer for `ui_test` output that does not emit github actions
252
+ /// `group`s, while still producing regular github actions messages on test failures.
253
+ struct TextAndGha ;
254
+ impl StatusEmitter for TextAndGha {
255
+ fn failed_test < ' a > (
256
+ & ' a self ,
257
+ revision : & ' a str ,
258
+ path : & ' a Path ,
259
+ cmd : & ' a Command ,
260
+ stderr : & ' a [ u8 ] ,
261
+ ) -> Box < dyn std:: fmt:: Debug + ' a > {
262
+ Box :: new ( (
263
+ ui_test:: status_emitter:: Gha :: < false > . failed_test ( revision, path, cmd, stderr) ,
264
+ ui_test:: status_emitter:: Text . failed_test ( revision, path, cmd, stderr) ,
265
+ ) )
266
+ }
267
+
268
+ fn run_tests ( & self , _config : & Config ) -> Box < dyn ui_test:: status_emitter:: DuringTestRun > {
269
+ Box :: new ( TextAndGha )
270
+ }
271
+
272
+ fn finalize (
273
+ & self ,
274
+ failures : usize ,
275
+ succeeded : usize ,
276
+ ignored : usize ,
277
+ filtered : usize ,
278
+ ) -> Box < dyn ui_test:: status_emitter:: Summary > {
279
+ Box :: new ( (
280
+ ui_test:: status_emitter:: Gha :: < false > . finalize ( failures, succeeded, ignored, filtered) ,
281
+ ui_test:: status_emitter:: Text . finalize ( failures, succeeded, ignored, filtered) ,
282
+ ) )
283
+ }
284
+ }
285
+
286
+ impl ui_test:: status_emitter:: DuringTestRun for TextAndGha {
287
+ fn test_result ( & mut self , path : & Path , revision : & str , result : & ui_test:: TestResult ) {
288
+ ui_test:: status_emitter:: Text . test_result ( path, revision, result) ;
289
+ ui_test:: status_emitter:: Gha :: < false > . test_result ( path, revision, result) ;
290
+ }
291
+ }
0 commit comments