1
+ use std:: ffi:: OsString ;
1
2
/// Create our own parser and build the Config from it.
2
3
use std:: fmt:: Debug ;
3
4
use std:: path:: PathBuf ;
@@ -16,6 +17,8 @@ pub enum Mode {
16
17
Fail ,
17
18
/// Run the tests, but always pass them as long as all annotations are satisfied and stderr files match.
18
19
Yolo ,
20
+ /// The test passes a full execution of `cargo build`
21
+ CargoPass ,
19
22
}
20
23
21
24
#[ derive( Debug , clap:: Parser ) ]
@@ -26,7 +29,7 @@ pub struct Args {
26
29
src_base : PathBuf ,
27
30
28
31
/// The mode according to ui_test modes.
29
- #[ arg( long, default_value= "yolo" ) ]
32
+ #[ arg( long, default_value = "yolo" ) ]
30
33
mode : Mode ,
31
34
32
35
/// Path for the stable-mir driver.
@@ -39,32 +42,74 @@ pub struct Args {
39
42
40
43
#[ arg( long) ]
41
44
pub verbose : bool ,
45
+
46
+ /// Run test-driver on verbose mode to print test outputs.
47
+ #[ arg( long) ]
48
+ pub no_capture : bool ,
42
49
}
43
50
44
51
impl From < Mode > for ui_test:: Mode {
45
52
/// Use rustc configuration as default but override arguments to fit our use case.
46
53
fn from ( mode : Mode ) -> ui_test:: Mode {
47
54
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
+ } ,
53
65
}
54
66
}
55
67
}
56
68
57
69
impl From < Args > for Config {
58
70
/// Use rustc configuration as default but override arguments to fit our use case.
59
71
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" , "" ) ;
64
78
config. mode = ui_test:: Mode :: from ( args. mode ) ;
65
79
config. output_conflict_handling = OutputConflictHandling :: Error ( "Should Fail" . to_string ( ) ) ;
66
80
config. out_dir = args. output_dir ;
67
81
//config.run_lib_path = PathBuf::from(env!("RUSTC_LIB_PATH"));
68
82
config
69
83
}
70
84
}
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