1+ use std:: ffi:: OsString ;
12/// Create our own parser and build the Config from it.
23use std:: fmt:: Debug ;
34use std:: path:: PathBuf ;
@@ -16,6 +17,8 @@ pub enum Mode {
1617 Fail ,
1718 /// Run the tests, but always pass them as long as all annotations are satisfied and stderr files match.
1819 Yolo ,
20+ /// The test passes a full execution of `cargo build`
21+ CargoPass ,
1922}
2023
2124#[ derive( Debug , clap:: Parser ) ]
@@ -26,7 +29,7 @@ pub struct Args {
2629 src_base : PathBuf ,
2730
2831 /// The mode according to ui_test modes.
29- #[ arg( long, default_value= "yolo" ) ]
32+ #[ arg( long, default_value = "yolo" ) ]
3033 mode : Mode ,
3134
3235 /// Path for the stable-mir driver.
@@ -39,32 +42,74 @@ pub struct Args {
3942
4043 #[ arg( long) ]
4144 pub verbose : bool ,
45+
46+ /// Run test-driver on verbose mode to print test outputs.
47+ #[ arg( long) ]
48+ pub no_capture : bool ,
4249}
4350
4451impl From < Mode > for ui_test:: Mode {
4552 /// Use rustc configuration as default but override arguments to fit our use case.
4653 fn from ( mode : Mode ) -> ui_test:: Mode {
4754 match mode {
48- Mode :: Pass => { ui_test:: Mode :: Pass }
49- Mode :: Run => { ui_test:: Mode :: Run { exit_code : 0 } }
50- Mode :: Panic => { ui_test:: Mode :: Panic }
51- Mode :: Fail => { ui_test:: Mode :: Fail { require_patterns : false , rustfix : RustfixMode :: Disabled } }
52- Mode :: Yolo => { ui_test:: Mode :: Yolo { rustfix : RustfixMode :: Disabled } }
55+ Mode :: Pass | Mode :: CargoPass => ui_test:: Mode :: Pass ,
56+ Mode :: Run => ui_test:: Mode :: Run { exit_code : 0 } ,
57+ Mode :: Panic => ui_test:: Mode :: Panic ,
58+ Mode :: Fail => ui_test:: Mode :: Fail {
59+ require_patterns : false ,
60+ rustfix : RustfixMode :: Disabled ,
61+ } ,
62+ Mode :: Yolo => ui_test:: Mode :: Yolo {
63+ rustfix : RustfixMode :: Disabled ,
64+ } ,
5365 }
5466 }
5567}
5668
5769impl From < Args > for Config {
5870 /// Use rustc configuration as default but override arguments to fit our use case.
5971 fn from ( args : Args ) -> Config {
60- let mut config = Config :: rustc ( args. src_base ) ;
61- config. program = CommandBuilder :: rustc ( ) ;
62- config. program . program = args. driver_path ;
63- config. program . args . push ( "--check-smir" . into ( ) ) ;
72+ let mut config = if matches ! ( args. mode, Mode :: CargoPass ) {
73+ cargo_config ( & args)
74+ } else {
75+ driver_config ( & args)
76+ } ;
77+ config. filter ( r"\[T-DRIVE\].*\n" , "" ) ;
6478 config. mode = ui_test:: Mode :: from ( args. mode ) ;
6579 config. output_conflict_handling = OutputConflictHandling :: Error ( "Should Fail" . to_string ( ) ) ;
6680 config. out_dir = args. output_dir ;
6781 //config.run_lib_path = PathBuf::from(env!("RUSTC_LIB_PATH"));
6882 config
6983 }
7084}
85+
86+ fn rustc_flags ( args : & Args ) -> Vec < OsString > {
87+ let mut flags = vec ! [ "--check-smir" . into( ) ] ;
88+ if args. verbose || args. no_capture {
89+ flags. push ( "--verbose" . into ( ) ) ;
90+ }
91+ flags
92+ }
93+
94+ /// Configure cargo tests that will run the test-driver instead of rustc.
95+ fn cargo_config ( args : & Args ) -> Config {
96+ let mut config = Config :: cargo ( args. src_base . clone ( ) ) ;
97+ config. program . envs . push ( (
98+ "RUST" . into ( ) ,
99+ Some ( args. driver_path . clone ( ) . into_os_string ( ) ) ,
100+ ) ) ;
101+ config. program . envs . push ( (
102+ "CARGO_ENCODED_RUSTFLAGS" . into ( ) ,
103+ Some ( rustc_flags ( args) . join ( & OsString :: from ( "\x1f " ) ) . into ( ) ) ,
104+ ) ) ;
105+ config
106+ }
107+
108+ /// Configure tests that will invoke the test-driver directly as rustc.
109+ fn driver_config ( args : & Args ) -> Config {
110+ let mut config = Config :: rustc ( args. src_base . clone ( ) ) ;
111+ config. program = CommandBuilder :: rustc ( ) ;
112+ config. program . program = args. driver_path . clone ( ) ;
113+ config. program . args = rustc_flags ( args) ;
114+ config
115+ }
0 commit comments