@@ -42,7 +42,7 @@ fn get_runners() -> Runners {
4242 ) ;
4343 runners. insert ( "--extended-regex-tests" , ( "Run extended regex tests" , extended_regex_tests) ) ;
4444 runners. insert ( "--mini-tests" , ( "Run mini tests" , mini_tests) ) ;
45-
45+ runners . insert ( "--cargo-tests" , ( "Run cargo tests" , cargo_tests ) ) ;
4646 runners
4747}
4848
@@ -88,6 +88,8 @@ struct TestArg {
8888 use_system_gcc : bool ,
8989 runners : Vec < String > ,
9090 flags : Vec < String > ,
91+ /// Additional arguments, to be passed to commands like `cargo test`.
92+ test_args : Vec < String > ,
9193 nb_parts : Option < usize > ,
9294 current_part : Option < usize > ,
9395 sysroot_panic_abort : bool ,
@@ -144,6 +146,7 @@ impl TestArg {
144146 show_usage ( ) ;
145147 return Ok ( None ) ;
146148 }
149+ "--" => test_arg. test_args . extend ( & mut args) ,
147150 x if runners. contains_key ( x)
148151 && !test_arg. runners . iter ( ) . any ( |runner| runner == x) =>
149152 {
@@ -203,6 +206,33 @@ fn clean(_env: &Env, args: &TestArg) -> Result<(), String> {
203206 create_dir ( & path)
204207}
205208
209+ fn cargo_tests ( test_env : & Env , test_args : & TestArg ) -> Result < ( ) , String > {
210+ // First, we call `mini_tests` to build minicore for us. This ensures we are testing with a working `minicore`,
211+ // and that any changes we have made affect `minicore`(since it would get rebuilt).
212+ mini_tests ( test_env, test_args) ?;
213+ // Then, we copy some of the env vars from `test_env`
214+ // We don't want to pass things like `RUSTFLAGS`, since they contain the -Zcodegen-backend flag.
215+ // That would force `cg_gcc` to *rebuild itself* and only then run tests, which is undesirable.
216+ let mut env = HashMap :: new ( ) ;
217+ env. insert (
218+ "LD_LIBRARY_PATH" . into ( ) ,
219+ test_env. get ( "LD_LIBRARY_PATH" ) . expect ( "LD_LIBRARY_PATH missing!" ) . to_string ( ) ,
220+ ) ;
221+ env. insert (
222+ "LIBRARY_PATH" . into ( ) ,
223+ test_env. get ( "LIBRARY_PATH" ) . expect ( "LIBRARY_PATH missing!" ) . to_string ( ) ,
224+ ) ;
225+ env. insert (
226+ "CG_RUSTFLAGS" . into ( ) ,
227+ test_env. get ( "CG_RUSTFLAGS" ) . map ( |s| s. as_str ( ) ) . unwrap_or ( "" ) . to_string ( ) ,
228+ ) ;
229+ // Pass all the default args + the user-specified ones.
230+ let mut args: Vec < & dyn AsRef < OsStr > > = vec ! [ & "cargo" , & "test" ] ;
231+ args. extend ( test_args. test_args . iter ( ) . map ( |s| s as & dyn AsRef < OsStr > ) ) ;
232+ run_command_with_output_and_env ( & args, None , Some ( & env) ) ?;
233+ Ok ( ( ) )
234+ }
235+
206236fn mini_tests ( env : & Env , args : & TestArg ) -> Result < ( ) , String > {
207237 // FIXME: create a function "display_if_not_quiet" or something along the line.
208238 println ! ( "[BUILD] mini_core" ) ;
@@ -1217,7 +1247,9 @@ fn run_all(env: &Env, args: &TestArg) -> Result<(), String> {
12171247 // asm_tests(env, args)?;
12181248 test_libcore ( env, args) ?;
12191249 extended_sysroot_tests ( env, args) ?;
1250+ cargo_tests ( env, args) ?;
12201251 test_rustc ( env, args) ?;
1252+
12211253 Ok ( ( ) )
12221254}
12231255
0 commit comments