@@ -3,18 +3,19 @@ use libtest_lexarg::OutputFormat;
33use crate :: { cli, notify, Case , RunError , RunMode , State } ;
44
55pub struct Harness {
6- raw : Vec < std:: ffi:: OsString > ,
6+ raw : std :: io :: Result < Vec < std:: ffi:: OsString > > ,
77 cases : Vec < Box < dyn Case > > ,
88}
99
1010impl Harness {
1111 pub fn with_args ( args : impl IntoIterator < Item = impl Into < std:: ffi:: OsString > > ) -> Self {
12- let raw = args . into_iter ( ) . map ( |s| s . into ( ) ) . collect :: < Vec < _ > > ( ) ;
12+ let raw = expand_args ( args ) ;
1313 Self { raw, cases : vec ! [ ] }
1414 }
1515
1616 pub fn with_env ( ) -> Self {
17- let raw = std:: env:: args_os ( ) . collect :: < Vec < _ > > ( ) ;
17+ let raw = std:: env:: args_os ( ) ;
18+ let raw = expand_args ( raw) ;
1819 Self { raw, cases : vec ! [ ] }
1920 }
2021
@@ -31,7 +32,14 @@ impl Harness {
3132 }
3233
3334 pub fn main ( mut self ) -> ! {
34- let mut parser = cli:: Parser :: new ( & self . raw ) ;
35+ let raw = match self . raw {
36+ Ok ( raw) => raw,
37+ Err ( err) => {
38+ eprintln ! ( "{err}" ) ;
39+ std:: process:: exit ( 1 )
40+ }
41+ } ;
42+ let mut parser = cli:: Parser :: new ( & raw ) ;
3543 let opts = parse ( & mut parser) . unwrap_or_else ( |err| {
3644 eprintln ! ( "{err}" ) ;
3745 std:: process:: exit ( 1 )
@@ -131,6 +139,27 @@ fn parse<'p>(
131139 Ok ( opts)
132140}
133141
142+ fn expand_args (
143+ args : impl IntoIterator < Item = impl Into < std:: ffi:: OsString > > ,
144+ ) -> std:: io:: Result < Vec < std:: ffi:: OsString > > {
145+ let mut expanded = Vec :: new ( ) ;
146+ for arg in args {
147+ let arg = arg. into ( ) ;
148+ if let Some ( argfile) = arg. to_str ( ) . and_then ( |s| s. strip_prefix ( "@" ) ) {
149+ expanded. extend ( parse_argfile ( std:: path:: Path :: new ( argfile) ) ?) ;
150+ } else {
151+ expanded. push ( arg) ;
152+ }
153+ }
154+ Ok ( expanded)
155+ }
156+
157+ fn parse_argfile ( path : & std:: path:: Path ) -> std:: io:: Result < Vec < std:: ffi:: OsString > > {
158+ // Logic taken from rust-lang/rust's `compiler/rustc_driver_impl/src/args.rs`
159+ let content = std:: fs:: read_to_string ( path) ?;
160+ Ok ( content. lines ( ) . map ( |s| s. into ( ) ) . collect ( ) )
161+ }
162+
134163fn notifier ( opts : & libtest_lexarg:: TestOpts ) -> std:: io:: Result < Box < dyn notify:: Notifier > > {
135164 #[ cfg( feature = "color" ) ]
136165 let stdout = anstream:: stdout ( ) ;
0 commit comments