Skip to content

Commit c8ce99b

Browse files
committed
modifed y.sh to allow for running cargo tests.
1 parent cfe88fa commit c8ce99b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

build_system/src/test.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -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+
/// Additonal 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,21 @@ 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 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 = test_env.clone();
217+
env.remove("RUSTFLAGS");
218+
// Pass all the default args + the user-specified ones.
219+
let mut args: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"test"];
220+
args.extend(test_args.test_args.iter().map(|s| s as &dyn AsRef<OsStr>));
221+
run_command_with_output_and_env(&args, None, Some(&env))?;
222+
Ok(())
223+
}
206224
fn mini_tests(env: &Env, args: &TestArg) -> Result<(), String> {
207225
// FIXME: create a function "display_if_not_quiet" or something along the line.
208226
println!("[BUILD] mini_core");
@@ -1218,6 +1236,7 @@ fn run_all(env: &Env, args: &TestArg) -> Result<(), String> {
12181236
test_libcore(env, args)?;
12191237
extended_sysroot_tests(env, args)?;
12201238
test_rustc(env, args)?;
1239+
cargo_tests(env, args)?;
12211240
Ok(())
12221241
}
12231242

0 commit comments

Comments
 (0)