@@ -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,44 @@ 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 . threads = threads. or ( self . threads ) ;
130+
131+ self . filter_files . extend_from_slice ( filters) ;
132+ self . skip_files . extend_from_slice ( skip) ;
133+
134+ let bless = match ( bless, check) {
135+ ( _, true ) => false ,
136+ ( true , _) => true ,
137+ _ => default_bless,
138+ } ;
139+ self . output_conflict_handling = if bless {
140+ OutputConflictHandling :: Bless
141+ } else {
142+ OutputConflictHandling :: Error ( format ! (
143+ "{} --bless" ,
144+ std:: env:: args( )
145+ . map( |s| format!( "{s:?}" ) )
146+ . collect:: <Vec <_>>( )
147+ . join( " " )
148+ ) )
149+ } ;
150+ }
151+
101152 /// Replace all occurrences of a path in stderr/stdout with a byte string.
102153 pub fn path_filter ( & mut self , path : & Path , replacement : & ' static ( impl AsRef < [ u8 ] > + ?Sized ) ) {
103154 self . path_stderr_filter ( path, replacement) ;
@@ -154,8 +205,8 @@ impl Config {
154205
155206 /// Compile dependencies and return the right flags
156207 /// to find the dependencies.
157- pub fn build_dependencies ( & self , args : & Args ) -> Result < Vec < OsString > > {
158- let dependencies = build_dependencies ( args , self ) ?;
208+ pub fn build_dependencies ( & self ) -> Result < Vec < OsString > > {
209+ let dependencies = build_dependencies ( self ) ?;
159210 let mut args = vec ! [ ] ;
160211 for ( name, artifacts) in dependencies. dependencies {
161212 for dependency in artifacts {
@@ -207,3 +258,15 @@ impl Config {
207258 . any ( |arch| self . target . as_ref ( ) . unwrap ( ) . contains ( arch) )
208259 }
209260}
261+
262+ #[ derive( Debug , Clone ) ]
263+ /// The different options for what to do when stdout/stderr files differ from the actual output.
264+ pub enum OutputConflictHandling {
265+ /// The string should be a command that can be executed to bless all tests.
266+ Error ( String ) ,
267+ /// Ignore mismatches in the stderr/stdout files.
268+ Ignore ,
269+ /// Instead of erroring if the stderr/stdout differs from the expected
270+ /// automatically replace it with the found output (after applying filters).
271+ Bless ,
272+ }
0 commit comments