Consolidate Rust unit tests under dedicated test modules (#56247)

## What changed

Move inline crate tests into `lib_tests.rs` and nest related test suites under each crate's `tests` module. Update imports, subprocess test filters, logging targets, and snapshot names to match the new module paths.

Keep test helpers accessible where needed and preserve the schema writer's exact test name used by release tooling.

GitOrigin-RevId: de55eaae66dce4941abb33dd0b2f170093daa8f9
This commit is contained in:
Dmitriy Kovalenko
2026-10-22 19:36:47 +00:00
committed by copyberry
parent 22db5847c8
commit c227654800
47 changed files with 4100 additions and 4090 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
//! Checks that initialization releases the global lock and survives LRU eviction.
use super::BlockingLruCache;
use crate::BlockingLruCache;
use std::num::NonZeroUsize;
use std::sync::mpsc;
use std::time::Duration;
+2 -53
View File
@@ -163,56 +163,5 @@ pub fn sha1_digest(bytes: &[u8]) -> [u8; 20] {
}
#[cfg(test)]
#[path = "initialization_tests.rs"]
mod initialization_tests;
#[cfg(test)]
mod tests {
use super::BlockingLruCache;
use std::num::NonZeroUsize;
#[tokio::test(flavor = "multi_thread")]
async fn stores_and_retrieves_values() {
let cache = BlockingLruCache::new(NonZeroUsize::new(2).expect("capacity"));
assert!(cache.get(&"first").is_none());
cache.insert("first", /*value*/ 1);
assert_eq!(cache.get(&"first"), Some(1));
}
#[tokio::test(flavor = "multi_thread")]
async fn evicts_least_recently_used() {
let cache = BlockingLruCache::new(NonZeroUsize::new(2).expect("capacity"));
cache.insert("a", /*value*/ 1);
cache.insert("b", /*value*/ 2);
assert_eq!(cache.get(&"a"), Some(1));
cache.insert("c", /*value*/ 3);
assert!(cache.get(&"b").is_none());
assert_eq!(cache.get(&"a"), Some(1));
assert_eq!(cache.get(&"c"), Some(3));
}
#[test]
fn disabled_without_runtime() {
let cache = BlockingLruCache::new(NonZeroUsize::new(2).expect("capacity"));
cache.insert("first", /*value*/ 1);
assert!(cache.get(&"first").is_none());
assert_eq!(cache.get_or_insert_with("first", || 2), 2);
assert!(cache.get(&"first").is_none());
assert!(cache.remove(&"first").is_none());
cache.clear();
let result = cache.with_mut(|inner| {
inner.put("tmp", 3);
inner.get(&"tmp").cloned()
});
assert_eq!(result, Some(3));
assert!(cache.get(&"tmp").is_none());
assert!(cache.blocking_lock().is_none());
}
}
#[path = "lib_tests.rs"]
mod tests;
+54
View File
@@ -0,0 +1,54 @@
#![cfg(test)]
//! Unit tests for the crate and its related test suites.
use super::BlockingLruCache;
use std::num::NonZeroUsize;
#[tokio::test(flavor = "multi_thread")]
async fn stores_and_retrieves_values() {
let cache = BlockingLruCache::new(NonZeroUsize::new(2).expect("capacity"));
assert!(cache.get(&"first").is_none());
cache.insert("first", /*value*/ 1);
assert_eq!(cache.get(&"first"), Some(1));
}
#[tokio::test(flavor = "multi_thread")]
async fn evicts_least_recently_used() {
let cache = BlockingLruCache::new(NonZeroUsize::new(2).expect("capacity"));
cache.insert("a", /*value*/ 1);
cache.insert("b", /*value*/ 2);
assert_eq!(cache.get(&"a"), Some(1));
cache.insert("c", /*value*/ 3);
assert!(cache.get(&"b").is_none());
assert_eq!(cache.get(&"a"), Some(1));
assert_eq!(cache.get(&"c"), Some(3));
}
#[test]
fn disabled_without_runtime() {
let cache = BlockingLruCache::new(NonZeroUsize::new(2).expect("capacity"));
cache.insert("first", /*value*/ 1);
assert!(cache.get(&"first").is_none());
assert_eq!(cache.get_or_insert_with("first", || 2), 2);
assert!(cache.get(&"first").is_none());
assert!(cache.remove(&"first").is_none());
cache.clear();
let result = cache.with_mut(|inner| {
inner.put("tmp", 3);
inner.get(&"tmp").cloned()
});
assert_eq!(result, Some(3));
assert!(cache.get(&"tmp").is_none());
assert!(cache.blocking_lock().is_none());
}
#[path = "initialization_tests.rs"]
mod initialization_tests;
+2 -2
View File
@@ -65,6 +65,6 @@ mod spawn_helper;
mod spawn_helper_main;
#[cfg(target_os = "linux")]
pub use spawn_helper::init_spawn_helper;
#[cfg(all(test, target_os = "linux"))]
#[path = "spawn_helper_tests.rs"]
mod spawn_helper_tests;
use tests::spawn_helper_tests;
+4 -4
View File
@@ -619,7 +619,7 @@ fn helper_dispatch_before_rust_initializes_argv() -> anyhow::Result<()> {
let output = std::process::Command::new(std::env::current_exe()?)
.args([
"--exact",
"spawn_helper_tests::helper_preserves_cwd_env_arg0_and_streams",
"tests::spawn_helper_tests::helper_preserves_cwd_env_arg0_and_streams",
"--nocapture",
])
.env("CODEX_TEST_EARLY_HELPER_ARGV", "1")
@@ -659,7 +659,7 @@ async fn helper_control_socket_survives_closed_stdio() -> anyhow::Result<()> {
let output = std::process::Command::new(std::env::current_exe()?)
.args([
"--exact",
"spawn_helper_tests::helper_control_socket_survives_closed_stdio",
"tests::spawn_helper_tests::helper_control_socket_survives_closed_stdio",
"--nocapture",
])
.env("CODEX_TEST_HELPER_CLOSED_STDIO", "1")
@@ -709,7 +709,7 @@ async fn helper_descriptor_pressure_falls_back_to_direct_spawn() -> anyhow::Resu
let output = std::process::Command::new(std::env::current_exe()?)
.args([
"--exact",
"spawn_helper_tests::helper_descriptor_pressure_falls_back_to_direct_spawn",
"tests::spawn_helper_tests::helper_descriptor_pressure_falls_back_to_direct_spawn",
"--nocapture",
])
.env("CODEX_TEST_HELPER_FD_PRESSURE", "1")
@@ -782,7 +782,7 @@ async fn parent_loader_environment_does_not_disable_helper_dispatch() -> anyhow:
let output = std::process::Command::new(std::env::current_exe()?)
.args([
"--exact",
"spawn_helper_tests::parent_loader_environment_does_not_disable_helper_dispatch",
"tests::spawn_helper_tests::parent_loader_environment_does_not_disable_helper_dispatch",
"--nocapture",
])
.env("CODEX_TEST_PARENT_LOADER_ENV", "1")
+4
View File
@@ -1657,3 +1657,7 @@ async fn pipe_spawn_no_stdin_can_preserve_inherited_fds() -> anyhow::Result<()>
Ok(())
}
#[cfg(target_os = "linux")]
#[path = "spawn_helper_tests.rs"]
pub(crate) mod spawn_helper_tests;