Skip to content

Commit 0b5ee16

Browse files
authored
Rollup merge of rust-lang#137679 - bjorn3:coretests_improvements, r=jieyouxu,onur-ozkan
Various coretests improvements The first commit is not yet strictly necessary as directly testing libcore works though useless work, but will be necessary once rust-lang#136642 migrates the liballoc tests into a separate package. The second commit fixes rust-lang#137478 and ensures that coretests actually gets tested on all CI job. The third commit fixes an error that didn't get caught because coretests doesn't run on the wasm32 CI job.
2 parents 6980d9d + 169e731 commit 0b5ee16

File tree

4 files changed

+25
-69
lines changed

4 files changed

+25
-69
lines changed

library/coretests/tests/slice.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use core::num::NonZero;
55
use core::ops::{Range, RangeInclusive};
66
use core::slice;
77

8-
use rand::seq::IndexedRandom;
9-
108
#[test]
119
fn test_position() {
1210
let b = [1, 2, 3, 5, 5];
@@ -1810,6 +1808,7 @@ fn select_nth_unstable() {
18101808
use core::cmp::Ordering::{Equal, Greater, Less};
18111809

18121810
use rand::Rng;
1811+
use rand::seq::IndexedRandom;
18131812

18141813
let mut rng = crate::test_rng();
18151814

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 24 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl Step for CrateBootstrap {
9090
);
9191

9292
let crate_name = path.rsplit_once('/').unwrap().1;
93-
run_cargo_test(cargo, &[], &[], crate_name, crate_name, bootstrap_host, builder);
93+
run_cargo_test(cargo, &[], &[], crate_name, bootstrap_host, builder);
9494
}
9595
}
9696

@@ -140,15 +140,7 @@ You can skip linkcheck with --skip src/tools/linkchecker"
140140
SourceType::InTree,
141141
&[],
142142
);
143-
run_cargo_test(
144-
cargo,
145-
&[],
146-
&[],
147-
"linkchecker",
148-
"linkchecker self tests",
149-
bootstrap_host,
150-
builder,
151-
);
143+
run_cargo_test(cargo, &[], &[], "linkchecker self tests", bootstrap_host, builder);
152144

153145
if builder.doc_tests == DocTests::No {
154146
return;
@@ -337,7 +329,7 @@ impl Step for Cargo {
337329
);
338330

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

342334
// Don't run cross-compile tests, we may not have cross-compiled libstd libs
343335
// available.
@@ -423,7 +415,7 @@ impl Step for RustAnalyzer {
423415
cargo.env("SKIP_SLOW_TESTS", "1");
424416

425417
cargo.add_rustc_lib_path(builder);
426-
run_cargo_test(cargo, &[], &[], "rust-analyzer", "rust-analyzer", host, builder);
418+
run_cargo_test(cargo, &[], &[], "rust-analyzer", host, builder);
427419
}
428420
}
429421

@@ -472,7 +464,7 @@ impl Step for Rustfmt {
472464

473465
cargo.add_rustc_lib_path(builder);
474466

475-
run_cargo_test(cargo, &[], &[], "rustfmt", "rustfmt", host, builder);
467+
run_cargo_test(cargo, &[], &[], "rustfmt", host, builder);
476468
}
477469
}
478470

@@ -588,7 +580,7 @@ impl Step for Miri {
588580

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

593585
// miri tests need to know about the stage sysroot
594586
cargo.env("MIRI_SYSROOT", &miri_sysroot);
@@ -736,7 +728,7 @@ impl Step for CompiletestTest {
736728
&[],
737729
);
738730
cargo.allow_features("test");
739-
run_cargo_test(cargo, &[], &[], "compiletest", "compiletest self test", host, builder);
731+
run_cargo_test(cargo, &[], &[], "compiletest self test", host, builder);
740732
}
741733
}
742734

@@ -797,7 +789,7 @@ impl Step for Clippy {
797789
cargo.env("HOST_LIBS", host_libs);
798790

799791
cargo.add_rustc_lib_path(builder);
800-
let cargo = prepare_cargo_test(cargo, &[], &[], "clippy", host, builder);
792+
let cargo = prepare_cargo_test(cargo, &[], &[], host, builder);
801793

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

@@ -1330,15 +1322,7 @@ impl Step for CrateRunMakeSupport {
13301322
&[],
13311323
);
13321324
cargo.allow_features("test");
1333-
run_cargo_test(
1334-
cargo,
1335-
&[],
1336-
&[],
1337-
"run-make-support",
1338-
"run-make-support self test",
1339-
host,
1340-
builder,
1341-
);
1325+
run_cargo_test(cargo, &[], &[], "run-make-support self test", host, builder);
13421326
}
13431327
}
13441328

@@ -1375,7 +1359,7 @@ impl Step for CrateBuildHelper {
13751359
&[],
13761360
);
13771361
cargo.allow_features("test");
1378-
run_cargo_test(cargo, &[], &[], "build_helper", "build_helper self test", host, builder);
1362+
run_cargo_test(cargo, &[], &[], "build_helper self test", host, builder);
13791363
}
13801364
}
13811365

@@ -2585,13 +2569,12 @@ fn run_cargo_test<'a>(
25852569
cargo: builder::Cargo,
25862570
libtest_args: &[&str],
25872571
crates: &[String],
2588-
primary_crate: &str,
25892572
description: impl Into<Option<&'a str>>,
25902573
target: TargetSelection,
25912574
builder: &Builder<'_>,
25922575
) -> bool {
25932576
let compiler = cargo.compiler();
2594-
let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, primary_crate, target, builder);
2577+
let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, target, builder);
25952578
let _time = helpers::timeit(builder);
25962579
let _group = description.into().and_then(|what| {
25972580
builder.msg_sysroot_tool(Kind::Test, compiler.stage, what, compiler.host, target)
@@ -2615,7 +2598,6 @@ fn prepare_cargo_test(
26152598
cargo: builder::Cargo,
26162599
libtest_args: &[&str],
26172600
crates: &[String],
2618-
primary_crate: &str,
26192601
target: TargetSelection,
26202602
builder: &Builder<'_>,
26212603
) -> BootstrapCommand {
@@ -2645,13 +2627,6 @@ fn prepare_cargo_test(
26452627
cargo.arg("--doc");
26462628
}
26472629
DocTests::No => {
2648-
let krate = &builder
2649-
.crates
2650-
.get(primary_crate)
2651-
.unwrap_or_else(|| panic!("missing crate {primary_crate}"));
2652-
if krate.has_lib {
2653-
cargo.arg("--lib");
2654-
}
26552630
cargo.args(["--bins", "--examples", "--tests", "--benches"]);
26562631
}
26572632
DocTests::Yes => {}
@@ -2826,15 +2801,15 @@ impl Step for Crate {
28262801
_ => panic!("can only test libraries"),
28272802
};
28282803

2829-
run_cargo_test(
2830-
cargo,
2831-
&[],
2832-
&self.crates,
2833-
&self.crates[0],
2834-
&*crate_description(&self.crates),
2835-
target,
2836-
builder,
2837-
);
2804+
let mut crates = self.crates.clone();
2805+
// The core crate can't directly be tested. We could silently
2806+
// ignore it, but adding it's own test crate is less confusing
2807+
// for users. We still keep core itself for doctests.
2808+
if crates.iter().any(|crate_| crate_ == "core") {
2809+
crates.push("coretests".to_owned());
2810+
}
2811+
2812+
run_cargo_test(cargo, &[], &crates, &*crate_description(&self.crates), target, builder);
28382813
}
28392814
}
28402815

@@ -2927,15 +2902,7 @@ impl Step for CrateRustdoc {
29272902
dylib_path.insert(0, PathBuf::from(&*libdir));
29282903
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
29292904

2930-
run_cargo_test(
2931-
cargo,
2932-
&[],
2933-
&["rustdoc:0.0.0".to_string()],
2934-
"rustdoc",
2935-
"rustdoc",
2936-
target,
2937-
builder,
2938-
);
2905+
run_cargo_test(cargo, &[], &["rustdoc:0.0.0".to_string()], "rustdoc", target, builder);
29392906
}
29402907
}
29412908

@@ -2992,7 +2959,6 @@ impl Step for CrateRustdocJsonTypes {
29922959
libtest_args,
29932960
&["rustdoc-json-types".to_string()],
29942961
"rustdoc-json-types",
2995-
"rustdoc-json-types",
29962962
target,
29972963
builder,
29982964
);
@@ -3172,7 +3138,7 @@ impl Step for Bootstrap {
31723138

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

31783144
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@@ -3297,7 +3263,7 @@ impl Step for RustInstaller {
32973263
bootstrap_host,
32983264
bootstrap_host,
32993265
);
3300-
run_cargo_test(cargo, &[], &[], "installer", None, bootstrap_host, builder);
3266+
run_cargo_test(cargo, &[], &[], None, bootstrap_host, builder);
33013267

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

3691-
run_cargo_test(cargo_test, &[], &[], crate_name, crate_name, bootstrap_host, builder);
3657+
run_cargo_test(cargo_test, &[], &[], crate_name, bootstrap_host, builder);
36923658

36933659
// Run the actual parse tests.
36943660
let mut cargo_run = tool::prepare_tool_cargo(

src/bootstrap/src/core/metadata.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ struct Package {
2828
source: Option<String>,
2929
manifest_path: String,
3030
dependencies: Vec<Dependency>,
31-
targets: Vec<Target>,
3231
features: BTreeMap<String, Vec<String>>,
3332
}
3433

@@ -40,11 +39,6 @@ struct Dependency {
4039
source: Option<String>,
4140
}
4241

43-
#[derive(Debug, Deserialize)]
44-
struct Target {
45-
kind: Vec<String>,
46-
}
47-
4842
/// Collects and stores package metadata of each workspace members into `build`,
4943
/// by executing `cargo metadata` commands.
5044
pub fn build(build: &mut Build) {
@@ -59,12 +53,10 @@ pub fn build(build: &mut Build) {
5953
.filter(|dep| dep.source.is_none())
6054
.map(|dep| dep.name)
6155
.collect();
62-
let has_lib = package.targets.iter().any(|t| t.kind.iter().any(|k| k == "lib"));
6356
let krate = Crate {
6457
name: name.clone(),
6558
deps,
6659
path,
67-
has_lib,
6860
features: package.features.keys().cloned().collect(),
6961
};
7062
let relative_path = krate.local_path(build);

src/bootstrap/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ struct Crate {
185185
name: String,
186186
deps: HashSet<String>,
187187
path: PathBuf,
188-
has_lib: bool,
189188
features: Vec<String>,
190189
}
191190

0 commit comments

Comments
 (0)