From cace998417bf54c5644ca340c9daf4f83016c794 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 21 May 2025 16:14:37 -0500 Subject: [PATCH] refactor: Move from Lazy to OnceCell --- .../tests/testsuite/all_passing.rs | 21 ++++++++++--------- .../tests/testsuite/mixed_bag.rs | 21 ++++++++++--------- .../libtest2-mimic/tests/testsuite/panic.rs | 21 ++++++++++--------- .../libtest2/tests/testsuite/all_passing.rs | 21 ++++++++++--------- crates/libtest2/tests/testsuite/mixed_bag.rs | 21 ++++++++++--------- crates/libtest2/tests/testsuite/panic.rs | 21 ++++++++++--------- 6 files changed, 66 insertions(+), 60 deletions(-) diff --git a/crates/libtest2-mimic/tests/testsuite/all_passing.rs b/crates/libtest2-mimic/tests/testsuite/all_passing.rs index 2568749..b36d00c 100644 --- a/crates/libtest2-mimic/tests/testsuite/all_passing.rs +++ b/crates/libtest2-mimic/tests/testsuite/all_passing.rs @@ -1,8 +1,9 @@ fn test_cmd() -> snapbox::cmd::Command { - static BIN: once_cell::sync::Lazy<(std::path::PathBuf, std::path::PathBuf)> = - once_cell::sync::Lazy::new(|| { - let package_root = crate::util::new_test( - r#" + static BIN: once_cell::sync::OnceCell<(std::path::PathBuf, std::path::PathBuf)> = + once_cell::sync::OnceCell::new(); + let (bin, current_dir) = BIN.get_or_init(|| { + let package_root = crate::util::new_test( + r#" fn main() { use libtest2_mimic::Trial; libtest2_mimic::Harness::with_env() @@ -14,12 +15,12 @@ fn main() { .main(); } "#, - false, - ); - let bin = crate::util::compile_test(&package_root); - (bin, package_root) - }); - snapbox::cmd::Command::new(&BIN.0).current_dir(&BIN.1) + false, + ); + let bin = crate::util::compile_test(&package_root); + (bin, package_root) + }); + snapbox::cmd::Command::new(bin).current_dir(current_dir) } fn check(args: &[&str], single: &str, parallel: &str) { diff --git a/crates/libtest2-mimic/tests/testsuite/mixed_bag.rs b/crates/libtest2-mimic/tests/testsuite/mixed_bag.rs index 38e5938..56eb28a 100644 --- a/crates/libtest2-mimic/tests/testsuite/mixed_bag.rs +++ b/crates/libtest2-mimic/tests/testsuite/mixed_bag.rs @@ -1,8 +1,9 @@ fn test_cmd() -> snapbox::cmd::Command { - static BIN: once_cell::sync::Lazy<(std::path::PathBuf, std::path::PathBuf)> = - once_cell::sync::Lazy::new(|| { - let package_root = crate::util::new_test( - r#" + static BIN: once_cell::sync::OnceCell<(std::path::PathBuf, std::path::PathBuf)> = + once_cell::sync::OnceCell::new(); + let (bin, current_dir) = BIN.get_or_init(|| { + let package_root = crate::util::new_test( + r#" fn main() { use libtest2_mimic::Trial; use libtest2_mimic::RunError; @@ -35,12 +36,12 @@ fn main() { .main(); } "#, - false, - ); - let bin = crate::util::compile_test(&package_root); - (bin, package_root) - }); - snapbox::cmd::Command::new(&BIN.0).current_dir(&BIN.1) + false, + ); + let bin = crate::util::compile_test(&package_root); + (bin, package_root) + }); + snapbox::cmd::Command::new(bin).current_dir(current_dir) } fn check(args: &[&str], code: i32, single: &str, parallel: &str) { diff --git a/crates/libtest2-mimic/tests/testsuite/panic.rs b/crates/libtest2-mimic/tests/testsuite/panic.rs index f27f063..6ccd5f4 100644 --- a/crates/libtest2-mimic/tests/testsuite/panic.rs +++ b/crates/libtest2-mimic/tests/testsuite/panic.rs @@ -1,8 +1,9 @@ fn test_cmd() -> snapbox::cmd::Command { - static BIN: once_cell::sync::Lazy<(std::path::PathBuf, std::path::PathBuf)> = - once_cell::sync::Lazy::new(|| { - let package_root = crate::util::new_test( - r#" + static BIN: once_cell::sync::OnceCell<(std::path::PathBuf, std::path::PathBuf)> = + once_cell::sync::OnceCell::new(); + let (bin, current_dir) = BIN.get_or_init(|| { + let package_root = crate::util::new_test( + r#" fn main() { use libtest2_mimic::Trial; libtest2_mimic::Harness::with_env() @@ -13,12 +14,12 @@ fn main() { .main(); } "#, - false, - ); - let bin = crate::util::compile_test(&package_root); - (bin, package_root) - }); - snapbox::cmd::Command::new(&BIN.0).current_dir(&BIN.1) + false, + ); + let bin = crate::util::compile_test(&package_root); + (bin, package_root) + }); + snapbox::cmd::Command::new(bin).current_dir(current_dir) } fn check(args: &[&str], code: i32, single: &str, parallel: &str) { diff --git a/crates/libtest2/tests/testsuite/all_passing.rs b/crates/libtest2/tests/testsuite/all_passing.rs index 8ad0542..e68047d 100644 --- a/crates/libtest2/tests/testsuite/all_passing.rs +++ b/crates/libtest2/tests/testsuite/all_passing.rs @@ -1,8 +1,9 @@ fn test_cmd() -> snapbox::cmd::Command { - static BIN: once_cell::sync::Lazy<(std::path::PathBuf, std::path::PathBuf)> = - once_cell::sync::Lazy::new(|| { - let package_root = crate::util::new_test( - r#" + static BIN: once_cell::sync::OnceCell<(std::path::PathBuf, std::path::PathBuf)> = + once_cell::sync::OnceCell::new(); + let (bin, current_dir) = BIN.get_or_init(|| { + let package_root = crate::util::new_test( + r#" libtest2::libtest2_main!(foo, bar, barro); fn foo(_state: &libtest2::State) -> libtest2::RunResult { @@ -17,12 +18,12 @@ fn barro(_state: &libtest2::State) -> libtest2::RunResult { Ok(()) } "#, - false, - ); - let bin = crate::util::compile_test(&package_root); - (bin, package_root) - }); - snapbox::cmd::Command::new(&BIN.0).current_dir(&BIN.1) + false, + ); + let bin = crate::util::compile_test(&package_root); + (bin, package_root) + }); + snapbox::cmd::Command::new(bin).current_dir(current_dir) } fn check(args: &[&str], single: &str, parallel: &str) { diff --git a/crates/libtest2/tests/testsuite/mixed_bag.rs b/crates/libtest2/tests/testsuite/mixed_bag.rs index 97a3e3d..897fcdc 100644 --- a/crates/libtest2/tests/testsuite/mixed_bag.rs +++ b/crates/libtest2/tests/testsuite/mixed_bag.rs @@ -1,8 +1,9 @@ fn test_cmd() -> snapbox::cmd::Command { - static BIN: once_cell::sync::Lazy<(std::path::PathBuf, std::path::PathBuf)> = - once_cell::sync::Lazy::new(|| { - let package_root = crate::util::new_test( - r#" + static BIN: once_cell::sync::OnceCell<(std::path::PathBuf, std::path::PathBuf)> = + once_cell::sync::OnceCell::new(); + let (bin, current_dir) = BIN.get_or_init(|| { + let package_root = crate::util::new_test( + r#" libtest2::libtest2_main!(cat, dog, fox, bunny, frog, owl, fly, bear); fn cat(_state: &libtest2::State) -> libtest2::RunResult { @@ -42,12 +43,12 @@ fn bear(state: &libtest2::State) -> libtest2::RunResult { Err(libtest2::RunError::fail("no honey")) } "#, - false, - ); - let bin = crate::util::compile_test(&package_root); - (bin, package_root) - }); - snapbox::cmd::Command::new(&BIN.0).current_dir(&BIN.1) + false, + ); + let bin = crate::util::compile_test(&package_root); + (bin, package_root) + }); + snapbox::cmd::Command::new(bin).current_dir(current_dir) } fn check(args: &[&str], code: i32, single: &str, parallel: &str) { diff --git a/crates/libtest2/tests/testsuite/panic.rs b/crates/libtest2/tests/testsuite/panic.rs index 0c875b4..b7a587f 100644 --- a/crates/libtest2/tests/testsuite/panic.rs +++ b/crates/libtest2/tests/testsuite/panic.rs @@ -1,8 +1,9 @@ fn test_cmd() -> snapbox::cmd::Command { - static BIN: once_cell::sync::Lazy<(std::path::PathBuf, std::path::PathBuf)> = - once_cell::sync::Lazy::new(|| { - let package_root = crate::util::new_test( - r#" + static BIN: once_cell::sync::OnceCell<(std::path::PathBuf, std::path::PathBuf)> = + once_cell::sync::OnceCell::new(); + let (bin, current_dir) = BIN.get_or_init(|| { + let package_root = crate::util::new_test( + r#" libtest2::libtest2_main!(passes, panics); fn passes(_state: &libtest2::State) -> libtest2::RunResult { @@ -13,12 +14,12 @@ fn panics(_state: &libtest2::State) -> libtest2::RunResult { panic!("uh oh") } "#, - false, - ); - let bin = crate::util::compile_test(&package_root); - (bin, package_root) - }); - snapbox::cmd::Command::new(&BIN.0).current_dir(&BIN.1) + false, + ); + let bin = crate::util::compile_test(&package_root); + (bin, package_root) + }); + snapbox::cmd::Command::new(bin).current_dir(current_dir) } fn check(args: &[&str], code: i32, single: &str, parallel: &str) {