Skip to content

Commit 633a3fe

Browse files
committed
Auto merge of rust-lang#135937 - bjorn3:separate_coretests_crate, r=jieyouxu,tgross35
Put the core unit tests in a separate coretests package Having standard library tests in the same package as a standard library crate has bad side effects. It causes the test to have a dependency on a locally built standard library crate, while also indirectly depending on it through libtest. Currently this works out fine in the context of rust's build system as both copies are identical, but for example in cg_clif's tests I've found it basically impossible to compile both copies with the exact same compiler flags and thus the two copies would cause lang item conflicts. This PR moves the tests of libcore to a separate package which doesn't depend on libcore, thus preventing the duplicate crates even when compiler flags don't exactly match between building the sysroot (for libtest) and building the test itself. The rest of the standard library crates do still have this issue however.
2 parents 0df0662 + 2f4dd6e commit 633a3fe

File tree

168 files changed

+52
-77
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+52
-77
lines changed

compiler/rustc_codegen_cranelift/build_system/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
151151
apply_patches(
152152
&runner.dirs,
153153
"coretests",
154-
&runner.stdlib_source.join("library/core/tests"),
154+
&runner.stdlib_source.join("library/coretests"),
155155
&LIBCORE_TESTS_SRC.to_path(&runner.dirs),
156156
);
157157

compiler/rustc_codegen_cranelift/patches/0022-coretests-Disable-not-compiling-tests.patch

-44
This file was deleted.

compiler/rustc_codegen_cranelift/patches/0027-coretests-128bit-atomic-operations.patch

+7-8
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@ Cranelift doesn't support them yet
1010
library/core/tests/atomic.rs | 4 ---
1111
4 files changed, 4 insertions(+), 50 deletions(-)
1212

13-
diff --git a/lib.rs b/lib.rs
13+
diff --git a/tests/lib.rs b/tests/lib.rs
1414
index 1e336bf..35e6f54 100644
15-
--- a/lib.rs
16-
+++ b/lib.rs
17-
@@ -2,6 +2,5 @@
18-
#![cfg(test)]
15+
--- a/tests/lib.rs
16+
+++ b/tests/lib.rs
17+
@@ -2,5 +2,4 @@
1918
// tidy-alphabetical-start
2019
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
2120
#![cfg_attr(test, feature(cfg_match))]
2221
#![feature(alloc_layout_extra)]
2322
#![feature(array_chunks)]
24-
diff --git a/atomic.rs b/atomic.rs
23+
diff --git a/tests/atomic.rs b/tests/atomic.rs
2524
index b735957..ea728b6 100644
26-
--- a/atomic.rs
27-
+++ b/atomic.rs
25+
--- a/tests/atomic.rs
26+
+++ b/tests/atomic.rs
2827
@@ -185,10 +185,6 @@ fn atomic_alignment() {
2928
assert_eq!(align_of::<AtomicU64>(), size_of::<AtomicU64>());
3029
#[cfg(target_has_atomic = "64")]

compiler/rustc_codegen_cranelift/patches/0028-coretests-Disable-long-running-tests.patch

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ Subject: [PATCH] Disable long running tests
77
library/core/tests/slice.rs | 2 ++
88
1 file changed, 2 insertions(+)
99

10-
diff --git a/slice.rs b/slice.rs
10+
diff --git a/tests/slice.rs b/tests/slice.rs
1111
index 8402833..84592e0 100644
12-
--- a/slice.rs
13-
+++ b/slice.rs
12+
--- a/tests/slice.rs
13+
+++ b/tests/slice.rs
1414
@@ -1809,6 +1809,7 @@ fn sort_unstable() {
1515
}
1616
}

library/Cargo.lock

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ dependencies = [
7272
[[package]]
7373
name = "core"
7474
version = "0.0.0"
75+
76+
[[package]]
77+
name = "coretests"
78+
version = "0.0.0"
7579
dependencies = [
7680
"rand",
7781
"rand_xorshift",

library/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ resolver = "1"
33
members = [
44
"std",
55
"sysroot",
6+
"coretests",
67
]
78

89
exclude = [

library/core/Cargo.toml

-13
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@ edition = "2021"
1515
test = false
1616
bench = false
1717

18-
[[test]]
19-
name = "coretests"
20-
path = "tests/lib.rs"
21-
22-
[[bench]]
23-
name = "corebenches"
24-
path = "benches/lib.rs"
25-
test = true
26-
27-
[dev-dependencies]
28-
rand = { version = "0.8.5", default-features = false }
29-
rand_xorshift = { version = "0.3.0", default-features = false }
30-
3118
[features]
3219
# Make panics and failed asserts immediately abort without formatting any message
3320
panic_immediate_abort = []

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
//! called. The `lang` attribute is called `eh_personality`.
4545
4646
// Since core defines many fundamental lang items, all tests live in a
47-
// separate crate, libcoretest (library/core/tests), to avoid bizarre issues.
47+
// separate crate, coretests (library/coretests), to avoid bizarre issues.
4848
//
4949
// Here we explicitly #[cfg]-out this whole crate when testing. If we don't do
5050
// this, both the generated test artifact and the linked libtest (which

library/coretests/Cargo.toml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[package]
2+
name = "coretests"
3+
version = "0.0.0"
4+
license = "MIT OR Apache-2.0"
5+
repository = "https://github.com/rust-lang/rust.git"
6+
description = "Tests for the Rust Core Library"
7+
autotests = false
8+
autobenches = false
9+
edition = "2021"
10+
11+
[lib]
12+
path = "lib.rs"
13+
test = false
14+
bench = false
15+
16+
[[test]]
17+
name = "coretests"
18+
path = "tests/lib.rs"
19+
20+
[[bench]]
21+
name = "corebenches"
22+
path = "benches/lib.rs"
23+
test = true
24+
25+
[dev-dependencies]
26+
rand = { version = "0.8.5", default-features = false }
27+
rand_xorshift = { version = "0.3.0", default-features = false }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

library/coretests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Intentionally left empty.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

library/core/tests/bstr.rs library/coretests/tests/bstr.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#![feature(bstr)]
2-
3-
use core::ByteStr;
1+
use core::bstr::ByteStr;
42

53
#[test]
64
fn test_debug() {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

library/core/tests/lib.rs library/coretests/tests/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![feature(async_iter_from_iter)]
1212
#![feature(async_iterator)]
1313
#![feature(bigint_helper_methods)]
14+
#![feature(bstr)]
1415
#![feature(cell_update)]
1516
#![feature(clone_to_uninit)]
1617
#![feature(const_black_box)]
@@ -139,6 +140,7 @@ mod asserting;
139140
mod async_iter;
140141
mod atomic;
141142
mod bool;
143+
mod bstr;
142144
mod cell;
143145
mod char;
144146
mod clone;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/bootstrap/mk/Makefile.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ check-aux:
5555
$(BOOTSTRAP_ARGS)
5656
# Run standard library tests in Miri.
5757
$(Q)$(BOOTSTRAP) miri --stage 2 \
58-
library/core \
58+
library/coretests \
5959
library/alloc \
6060
$(BOOTSTRAP_ARGS) \
6161
--no-doc
6262
# Some doctests use file system operations to demonstrate dealing with `Result`.
6363
$(Q)MIRIFLAGS="-Zmiri-disable-isolation" \
6464
$(BOOTSTRAP) miri --stage 2 \
65-
library/core \
65+
library/coretests \
6666
library/alloc \
6767
$(BOOTSTRAP_ARGS) \
6868
--doc

src/bootstrap/src/core/build_steps/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Step for Std {
4545
const DEFAULT: bool = true;
4646

4747
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
48-
run.crate_or_deps("sysroot").path("library")
48+
run.crate_or_deps("sysroot").crate_or_deps("coretests").path("library")
4949
}
5050

5151
fn make_run(run: RunConfig<'_>) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2658,7 +2658,7 @@ impl Step for Crate {
26582658
const DEFAULT: bool = true;
26592659

26602660
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2661-
run.crate_or_deps("sysroot")
2661+
run.crate_or_deps("sysroot").crate_or_deps("coretests")
26622662
}
26632663

26642664
fn make_run(run: RunConfig<'_>) {

0 commit comments

Comments
 (0)