@@ -5,6 +5,7 @@ pub use color_eyre;
55use color_eyre:: eyre:: Result ;
66use std:: {
77 ffi:: OsString ,
8+ num:: NonZeroUsize ,
89 path:: { Path , PathBuf } ,
910} ;
1011
@@ -34,16 +35,24 @@ pub struct Config {
3435 pub program : CommandBuilder ,
3536 /// The command to run to obtain the cfgs that the output is supposed to
3637 pub cfgs : CommandBuilder ,
38+ /// What to do in case the stdout/stderr output differs from the expected one.
39+ pub output_conflict_handling : OutputConflictHandling ,
3740 /// Path to a `Cargo.toml` that describes which dependencies the tests can access.
3841 pub dependencies_crate_manifest_path : Option < PathBuf > ,
3942 /// The command to run can be changed from `cargo` to any custom command to build the
40- /// dependencies in `dependencies_crate_manifest_path`
43+ /// dependencies in `dependencies_crate_manifest_path`.
4144 pub dependency_builder : CommandBuilder ,
4245 /// Where to dump files like the binaries compiled from tests.
4346 /// Defaults to `target/ui` in the current directory.
4447 pub out_dir : PathBuf ,
45- /// The default edition to use on all tests
48+ /// The default edition to use on all tests.
4649 pub edition : Option < String > ,
50+ /// Skip test files whose names contain any of these entries.
51+ pub skip_files : Vec < String > ,
52+ /// Only test files whose names contain any of these entries.
53+ pub filter_files : Vec < String > ,
54+ /// Override the number of threads to use.
55+ pub threads : Option < NonZeroUsize > ,
4756}
4857
4958impl Config {
@@ -74,13 +83,17 @@ impl Config {
7483 } ,
7584 program : CommandBuilder :: rustc ( ) ,
7685 cfgs : CommandBuilder :: cfgs ( ) ,
86+ output_conflict_handling : OutputConflictHandling :: Bless ,
7787 dependencies_crate_manifest_path : None ,
7888 dependency_builder : CommandBuilder :: cargo ( ) ,
7989 out_dir : std:: env:: var_os ( "CARGO_TARGET_DIR" )
8090 . map ( PathBuf :: from)
8191 . unwrap_or_else ( || std:: env:: current_dir ( ) . unwrap ( ) . join ( "target" ) )
8292 . join ( "ui" ) ,
8393 edition : Some ( "2021" . into ( ) ) ,
94+ skip_files : Vec :: new ( ) ,
95+ filter_files : Vec :: new ( ) ,
96+ threads : None ,
8497 }
8598 }
8699
@@ -98,6 +111,42 @@ impl Config {
98111 }
99112 }
100113
114+ /// Populate the config with the values from parsed command line arguments.
115+ /// If neither `--bless` or `--check` are provided `default_bless` is used.
116+ ///
117+ /// The default output conflict handling command suggests adding `--bless`
118+ /// to the end of the current command.
119+ pub fn with_args ( & mut self , args : & Args , default_bless : bool ) {
120+ let Args {
121+ ref filters,
122+ quiet : _,
123+ check,
124+ bless,
125+ threads : _,
126+ ref skip,
127+ } = * args;
128+
129+ self . filter_files . extend_from_slice ( filters) ;
130+ self . skip_files . extend_from_slice ( skip) ;
131+
132+ let bless = match ( bless, check) {
133+ ( _, true ) => false ,
134+ ( true , _) => true ,
135+ _ => default_bless,
136+ } ;
137+ self . output_conflict_handling = if bless {
138+ OutputConflictHandling :: Bless
139+ } else {
140+ OutputConflictHandling :: Error ( format ! (
141+ "{} --bless" ,
142+ std:: env:: args( )
143+ . map( |s| format!( "{s:?}" ) )
144+ . collect:: <Vec <_>>( )
145+ . join( " " )
146+ ) )
147+ } ;
148+ }
149+
101150 /// Replace all occurrences of a path in stderr/stdout with a byte string.
102151 pub fn path_filter ( & mut self , path : & Path , replacement : & ' static ( impl AsRef < [ u8 ] > + ?Sized ) ) {
103152 self . path_stderr_filter ( path, replacement) ;
@@ -154,8 +203,8 @@ impl Config {
154203
155204 /// Compile dependencies and return the right flags
156205 /// to find the dependencies.
157- pub fn build_dependencies ( & self , args : & Args ) -> Result < Vec < OsString > > {
158- let dependencies = build_dependencies ( args , self ) ?;
206+ pub fn build_dependencies ( & self ) -> Result < Vec < OsString > > {
207+ let dependencies = build_dependencies ( self ) ?;
159208 let mut args = vec ! [ ] ;
160209 for ( name, artifacts) in dependencies. dependencies {
161210 for dependency in artifacts {
@@ -207,3 +256,15 @@ impl Config {
207256 . any ( |arch| self . target . as_ref ( ) . unwrap ( ) . contains ( arch) )
208257 }
209258}
259+
260+ #[ derive( Debug , Clone ) ]
261+ /// The different options for what to do when stdout/stderr files differ from the actual output.
262+ pub enum OutputConflictHandling {
263+ /// The string should be a command that can be executed to bless all tests.
264+ Error ( String ) ,
265+ /// Ignore mismatches in the stderr/stdout files.
266+ Ignore ,
267+ /// Instead of erroring if the stderr/stdout differs from the expected
268+ /// automatically replace it with the found output (after applying filters).
269+ Bless ,
270+ }
0 commit comments