Skip to content

Commit

Permalink
Auto merge of rust-lang#135937 - bjorn3:separate_coretests_crate, r=j…
Browse files Browse the repository at this point in the history
…ieyouxu,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.
  • Loading branch information
bors committed Jan 27, 2025
2 parents 0df0662 + 2f4dd6e commit 633a3fe
Show file tree
Hide file tree
Showing 168 changed files with 52 additions and 77 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/build_system/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
apply_patches(
&runner.dirs,
"coretests",
&runner.stdlib_source.join("library/core/tests"),
&runner.stdlib_source.join("library/coretests"),
&LIBCORE_TESTS_SRC.to_path(&runner.dirs),
);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ Cranelift doesn't support them yet
library/core/tests/atomic.rs | 4 ---
4 files changed, 4 insertions(+), 50 deletions(-)

diff --git a/lib.rs b/lib.rs
diff --git a/tests/lib.rs b/tests/lib.rs
index 1e336bf..35e6f54 100644
--- a/lib.rs
+++ b/lib.rs
@@ -2,6 +2,5 @@
#![cfg(test)]
--- a/tests/lib.rs
+++ b/tests/lib.rs
@@ -2,5 +2,4 @@
// tidy-alphabetical-start
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
#![cfg_attr(test, feature(cfg_match))]
#![feature(alloc_layout_extra)]
#![feature(array_chunks)]
diff --git a/atomic.rs b/atomic.rs
diff --git a/tests/atomic.rs b/tests/atomic.rs
index b735957..ea728b6 100644
--- a/atomic.rs
+++ b/atomic.rs
--- a/tests/atomic.rs
+++ b/tests/atomic.rs
@@ -185,10 +185,6 @@ fn atomic_alignment() {
assert_eq!(align_of::<AtomicU64>(), size_of::<AtomicU64>());
#[cfg(target_has_atomic = "64")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Subject: [PATCH] Disable long running tests
library/core/tests/slice.rs | 2 ++
1 file changed, 2 insertions(+)

diff --git a/slice.rs b/slice.rs
diff --git a/tests/slice.rs b/tests/slice.rs
index 8402833..84592e0 100644
--- a/slice.rs
+++ b/slice.rs
--- a/tests/slice.rs
+++ b/tests/slice.rs
@@ -1809,6 +1809,7 @@ fn sort_unstable() {
}
}
Expand Down
4 changes: 4 additions & 0 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ dependencies = [
[[package]]
name = "core"
version = "0.0.0"

[[package]]
name = "coretests"
version = "0.0.0"
dependencies = [
"rand",
"rand_xorshift",
Expand Down
1 change: 1 addition & 0 deletions library/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "1"
members = [
"std",
"sysroot",
"coretests",
]

exclude = [
Expand Down
13 changes: 0 additions & 13 deletions library/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ edition = "2021"
test = false
bench = false

[[test]]
name = "coretests"
path = "tests/lib.rs"

[[bench]]
name = "corebenches"
path = "benches/lib.rs"
test = true

[dev-dependencies]
rand = { version = "0.8.5", default-features = false }
rand_xorshift = { version = "0.3.0", default-features = false }

[features]
# Make panics and failed asserts immediately abort without formatting any message
panic_immediate_abort = []
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
//! called. The `lang` attribute is called `eh_personality`.
// Since core defines many fundamental lang items, all tests live in a
// separate crate, libcoretest (library/core/tests), to avoid bizarre issues.
// separate crate, coretests (library/coretests), to avoid bizarre issues.
//
// Here we explicitly #[cfg]-out this whole crate when testing. If we don't do
// this, both the generated test artifact and the linked libtest (which
Expand Down
27 changes: 27 additions & 0 deletions library/coretests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "coretests"
version = "0.0.0"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/rust.git"
description = "Tests for the Rust Core Library"
autotests = false
autobenches = false
edition = "2021"

[lib]
path = "lib.rs"
test = false
bench = false

[[test]]
name = "coretests"
path = "tests/lib.rs"

[[bench]]
name = "corebenches"
path = "benches/lib.rs"
test = true

[dev-dependencies]
rand = { version = "0.8.5", default-features = false }
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.
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.
1 change: 1 addition & 0 deletions library/coretests/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +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.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#![feature(bstr)]

use core::ByteStr;
use core::bstr::ByteStr;

#[test]
fn test_debug() {
Expand Down
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.
2 changes: 2 additions & 0 deletions library/core/tests/lib.rs → library/coretests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#![feature(async_iter_from_iter)]
#![feature(async_iterator)]
#![feature(bigint_helper_methods)]
#![feature(bstr)]
#![feature(cell_update)]
#![feature(clone_to_uninit)]
#![feature(const_black_box)]
Expand Down Expand Up @@ -139,6 +140,7 @@ mod asserting;
mod async_iter;
mod atomic;
mod bool;
mod bstr;
mod cell;
mod char;
mod clone;
Expand Down
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.
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.
4 changes: 2 additions & 2 deletions src/bootstrap/mk/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ check-aux:
$(BOOTSTRAP_ARGS)
# Run standard library tests in Miri.
$(Q)$(BOOTSTRAP) miri --stage 2 \
library/core \
library/coretests \
library/alloc \
$(BOOTSTRAP_ARGS) \
--no-doc
# Some doctests use file system operations to demonstrate dealing with `Result`.
$(Q)MIRIFLAGS="-Zmiri-disable-isolation" \
$(BOOTSTRAP) miri --stage 2 \
library/core \
library/coretests \
library/alloc \
$(BOOTSTRAP_ARGS) \
--doc
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Step for Std {
const DEFAULT: bool = true;

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

fn make_run(run: RunConfig<'_>) {
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2658,7 +2658,7 @@ impl Step for Crate {
const DEFAULT: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.crate_or_deps("sysroot")
run.crate_or_deps("sysroot").crate_or_deps("coretests")
}

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

0 comments on commit 633a3fe

Please sign in to comment.