Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various coretests improvements #137679

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions library/coretests/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use core::num::NonZero;
use core::ops::{Range, RangeInclusive};
use core::slice;

use rand::seq::IndexedRandom;

#[test]
fn test_position() {
let b = [1, 2, 3, 5, 5];
Expand Down Expand Up @@ -1810,6 +1808,7 @@ fn select_nth_unstable() {
use core::cmp::Ordering::{Equal, Greater, Less};

use rand::Rng;
use rand::seq::IndexedRandom;

let mut rng = crate::test_rng();

Expand Down
82 changes: 24 additions & 58 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Step for CrateBootstrap {
);

let crate_name = path.rsplit_once('/').unwrap().1;
run_cargo_test(cargo, &[], &[], crate_name, crate_name, bootstrap_host, builder);
run_cargo_test(cargo, &[], &[], crate_name, bootstrap_host, builder);
}
}

Expand Down Expand Up @@ -140,15 +140,7 @@ You can skip linkcheck with --skip src/tools/linkchecker"
SourceType::InTree,
&[],
);
run_cargo_test(
cargo,
&[],
&[],
"linkchecker",
"linkchecker self tests",
bootstrap_host,
builder,
);
run_cargo_test(cargo, &[], &[], "linkchecker self tests", bootstrap_host, builder);

if builder.doc_tests == DocTests::No {
return;
Expand Down Expand Up @@ -331,7 +323,7 @@ impl Step for Cargo {
);

// NOTE: can't use `run_cargo_test` because we need to overwrite `PATH`
let mut cargo = prepare_cargo_test(cargo, &[], &[], "cargo", self.host, builder);
let mut cargo = prepare_cargo_test(cargo, &[], &[], self.host, builder);

// Don't run cross-compile tests, we may not have cross-compiled libstd libs
// available.
Expand Down Expand Up @@ -417,7 +409,7 @@ impl Step for RustAnalyzer {
cargo.env("SKIP_SLOW_TESTS", "1");

cargo.add_rustc_lib_path(builder);
run_cargo_test(cargo, &[], &[], "rust-analyzer", "rust-analyzer", host, builder);
run_cargo_test(cargo, &[], &[], "rust-analyzer", host, builder);
}
}

Expand Down Expand Up @@ -466,7 +458,7 @@ impl Step for Rustfmt {

cargo.add_rustc_lib_path(builder);

run_cargo_test(cargo, &[], &[], "rustfmt", "rustfmt", host, builder);
run_cargo_test(cargo, &[], &[], "rustfmt", host, builder);
}
}

Expand Down Expand Up @@ -582,7 +574,7 @@ impl Step for Miri {

// We can NOT use `run_cargo_test` since Miri's integration tests do not use the usual test
// harness and therefore do not understand the flags added by `add_flags_and_try_run_test`.
let mut cargo = prepare_cargo_test(cargo, &[], &[], "miri", host, builder);
let mut cargo = prepare_cargo_test(cargo, &[], &[], host, builder);

// miri tests need to know about the stage sysroot
cargo.env("MIRI_SYSROOT", &miri_sysroot);
Expand Down Expand Up @@ -730,7 +722,7 @@ impl Step for CompiletestTest {
&[],
);
cargo.allow_features("test");
run_cargo_test(cargo, &[], &[], "compiletest", "compiletest self test", host, builder);
run_cargo_test(cargo, &[], &[], "compiletest self test", host, builder);
}
}

Expand Down Expand Up @@ -791,7 +783,7 @@ impl Step for Clippy {
cargo.env("HOST_LIBS", host_libs);

cargo.add_rustc_lib_path(builder);
let cargo = prepare_cargo_test(cargo, &[], &[], "clippy", host, builder);
let cargo = prepare_cargo_test(cargo, &[], &[], host, builder);

let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host);

Expand Down Expand Up @@ -1318,15 +1310,7 @@ impl Step for CrateRunMakeSupport {
&[],
);
cargo.allow_features("test");
run_cargo_test(
cargo,
&[],
&[],
"run-make-support",
"run-make-support self test",
host,
builder,
);
run_cargo_test(cargo, &[], &[], "run-make-support self test", host, builder);
}
}

Expand Down Expand Up @@ -1363,7 +1347,7 @@ impl Step for CrateBuildHelper {
&[],
);
cargo.allow_features("test");
run_cargo_test(cargo, &[], &[], "build_helper", "build_helper self test", host, builder);
run_cargo_test(cargo, &[], &[], "build_helper self test", host, builder);
}
}

Expand Down Expand Up @@ -2569,13 +2553,12 @@ fn run_cargo_test<'a>(
cargo: builder::Cargo,
libtest_args: &[&str],
crates: &[String],
primary_crate: &str,
description: impl Into<Option<&'a str>>,
target: TargetSelection,
builder: &Builder<'_>,
) -> bool {
let compiler = cargo.compiler();
let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, primary_crate, target, builder);
let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, target, builder);
let _time = helpers::timeit(builder);
let _group = description.into().and_then(|what| {
builder.msg_sysroot_tool(Kind::Test, compiler.stage, what, compiler.host, target)
Expand All @@ -2599,7 +2582,6 @@ fn prepare_cargo_test(
cargo: builder::Cargo,
libtest_args: &[&str],
crates: &[String],
primary_crate: &str,
target: TargetSelection,
builder: &Builder<'_>,
) -> BootstrapCommand {
Expand Down Expand Up @@ -2629,13 +2611,6 @@ fn prepare_cargo_test(
cargo.arg("--doc");
}
DocTests::No => {
let krate = &builder
.crates
.get(primary_crate)
.unwrap_or_else(|| panic!("missing crate {primary_crate}"));
if krate.has_lib {
cargo.arg("--lib");
}
cargo.args(["--bins", "--examples", "--tests", "--benches"]);
}
DocTests::Yes => {}
Expand Down Expand Up @@ -2810,15 +2785,15 @@ impl Step for Crate {
_ => panic!("can only test libraries"),
};

run_cargo_test(
cargo,
&[],
&self.crates,
&self.crates[0],
&*crate_description(&self.crates),
target,
builder,
);
let mut crates = self.crates.clone();
// The core crate can't directly be tested. We could silently
// ignore it, but adding it's own test crate is less confusing
// for users. We still keep core itself for doctests.
if crates.iter().any(|crate_| crate_ == "core") {
crates.push("coretests".to_owned());
}

run_cargo_test(cargo, &[], &crates, &*crate_description(&self.crates), target, builder);
}
}

Expand Down Expand Up @@ -2911,15 +2886,7 @@ impl Step for CrateRustdoc {
dylib_path.insert(0, PathBuf::from(&*libdir));
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());

run_cargo_test(
cargo,
&[],
&["rustdoc:0.0.0".to_string()],
"rustdoc",
"rustdoc",
target,
builder,
);
run_cargo_test(cargo, &[], &["rustdoc:0.0.0".to_string()], "rustdoc", target, builder);
}
}

Expand Down Expand Up @@ -2976,7 +2943,6 @@ impl Step for CrateRustdocJsonTypes {
libtest_args,
&["rustdoc-json-types".to_string()],
"rustdoc-json-types",
"rustdoc-json-types",
target,
builder,
);
Expand Down Expand Up @@ -3156,7 +3122,7 @@ impl Step for Bootstrap {

// bootstrap tests are racy on directory creation so just run them one at a time.
// Since there's not many this shouldn't be a problem.
run_cargo_test(cargo, &["--test-threads=1"], &[], "bootstrap", None, host, builder);
run_cargo_test(cargo, &["--test-threads=1"], &[], None, host, builder);
}

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
Expand Down Expand Up @@ -3281,7 +3247,7 @@ impl Step for RustInstaller {
bootstrap_host,
bootstrap_host,
);
run_cargo_test(cargo, &[], &[], "installer", None, bootstrap_host, builder);
run_cargo_test(cargo, &[], &[], None, bootstrap_host, builder);

// We currently don't support running the test.sh script outside linux(?) environments.
// Eventually this should likely migrate to #[test]s in rust-installer proper rather than a
Expand Down Expand Up @@ -3672,7 +3638,7 @@ impl Step for TestFloatParse {
&[],
);

run_cargo_test(cargo_test, &[], &[], crate_name, crate_name, bootstrap_host, builder);
run_cargo_test(cargo_test, &[], &[], crate_name, bootstrap_host, builder);

// Run the actual parse tests.
let mut cargo_run = tool::prepare_tool_cargo(
Expand Down
8 changes: 0 additions & 8 deletions src/bootstrap/src/core/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ struct Package {
source: Option<String>,
manifest_path: String,
dependencies: Vec<Dependency>,
targets: Vec<Target>,
features: BTreeMap<String, Vec<String>>,
}

Expand All @@ -40,11 +39,6 @@ struct Dependency {
source: Option<String>,
}

#[derive(Debug, Deserialize)]
struct Target {
kind: Vec<String>,
}

/// Collects and stores package metadata of each workspace members into `build`,
/// by executing `cargo metadata` commands.
pub fn build(build: &mut Build) {
Expand All @@ -59,12 +53,10 @@ pub fn build(build: &mut Build) {
.filter(|dep| dep.source.is_none())
.map(|dep| dep.name)
.collect();
let has_lib = package.targets.iter().any(|t| t.kind.iter().any(|k| k == "lib"));
let krate = Crate {
name: name.clone(),
deps,
path,
has_lib,
features: package.features.keys().cloned().collect(),
};
let relative_path = krate.local_path(build);
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ struct Crate {
name: String,
deps: HashSet<String>,
path: PathBuf,
has_lib: bool,
features: Vec<String>,
}

Expand Down
Loading