@@ -2,6 +2,8 @@ use colored::*;
22use regex:: bytes:: Regex ;
33use std:: path:: { Path , PathBuf } ;
44use std:: { env, process:: Command } ;
5+ use ui_test:: status_emitter:: StatusEmitter ;
6+ use ui_test:: CommandBuilder ;
57use ui_test:: { color_eyre:: Result , Config , Match , Mode , OutputConflictHandling } ;
68
79fn miri_path ( ) -> PathBuf {
@@ -44,40 +46,30 @@ fn build_so_for_c_ffi_tests() -> PathBuf {
4446}
4547
4648fn 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 ( ) ;
5852
5953 let in_rustc_test_suite = option_env ! ( "RUSTC_STAGE" ) . is_some ( ) ;
6054
6155 // Add some flags we always want.
6256 if in_rustc_test_suite {
6357 // Less aggressive warnings to make the rustc toolstate management less painful.
6458 // (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 ( ) ) ;
6761 } 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 ( ) ) ;
7064 }
7165 if let Ok ( extra_flags) = env:: var ( "MIRIFLAGS" ) {
7266 for flag in extra_flags. split_whitespace ( ) {
73- config . args . push ( flag. into ( ) ) ;
67+ program . args . push ( flag. into ( ) ) ;
7468 }
7569 }
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 ( ) ) ;
8173
8274 // If we're on linux, and we're testing the extern-so functionality,
8375 // 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
8678 let so_file_path = build_so_for_c_ffi_tests ( ) ;
8779 let mut flag = std:: ffi:: OsString :: from ( "-Zmiri-extern-so-file=" ) ;
8880 flag. push ( so_file_path. into_os_string ( ) ) ;
89- config . args . push ( flag) ;
81+ program . args . push ( flag) ;
9082 }
9183
9284 let skip_ui_checks = env:: var_os ( "MIRI_SKIP_UI_CHECKS" ) . is_some ( ) ;
9385
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) {
9587 ( false , false ) => OutputConflictHandling :: Error ,
9688 ( true , false ) => OutputConflictHandling :: Bless ,
9789 ( false , true ) => OutputConflictHandling :: Ignore ,
9890 ( true , true ) => panic ! ( "cannot use MIRI_BLESS and MIRI_SKIP_UI_CHECKS at the same time" ) ,
9991 } ;
10092
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+
101106 // Handle command-line arguments.
102107 let mut after_dashdash = false ;
103108 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
135140 "run" . into( ) , // There is no `cargo miri build` so we just use `cargo miri run`.
136141 ] ;
137142 }
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+ )
139151}
140152
141153macro_rules! regexes {
@@ -235,3 +247,45 @@ fn main() -> Result<()> {
235247
236248 Ok ( ( ) )
237249}
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