Skip to content

Commit 8ede3cd

Browse files
committed
use command_executing in track_child
1 parent 9100d25 commit 8ede3cd

5 files changed

Lines changed: 21 additions & 28 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/fspy/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ bumpalo = { workspace = true }
1212
const_format = { workspace = true, features = ["fmt"] }
1313
derive_more = { workspace = true, features = ["debug"] }
1414
fspy_shared = { workspace = true }
15+
fspy_test_utils = { workspace = true }
1516
futures-util = { workspace = true }
1617
libc = { workspace = true }
1718
ouroboros = { workspace = true }
@@ -44,7 +45,6 @@ tempfile = { workspace = true }
4445
[dev-dependencies]
4546
anyhow = { workspace = true }
4647
csv-async = { workspace = true }
47-
ctor = { workspace = true }
4848
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "fs", "io-std"] }
4949

5050
[target.'cfg(all(target_os = "linux", target_arch = "aarch64"))'.dev-dependencies]

crates/fspy/tests/rust_std.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use test_utils::assert_contains;
1313
#[tokio::test]
1414
async fn open_read() -> anyhow::Result<()> {
1515
let accesses = track_child!({
16-
File::open("hello");
16+
let _ = File::open("hello");
1717
})
1818
.await?;
1919
assert_contains(&accesses, current_dir().unwrap().join("hello").as_path(), AccessMode::Read);
@@ -25,7 +25,7 @@ async fn open_read() -> anyhow::Result<()> {
2525
async fn open_write() -> anyhow::Result<()> {
2626
let accesses = track_child!({
2727
let path = format!("{}/hello", env!("CARGO_TARGET_TMPDIR"));
28-
OpenOptions::new().write(true).open(path);
28+
let _ = OpenOptions::new().write(true).open(path);
2929
})
3030
.await?;
3131
assert_contains(
@@ -41,7 +41,7 @@ async fn open_write() -> anyhow::Result<()> {
4141
async fn readdir() -> anyhow::Result<()> {
4242
let accesses = track_child!({
4343
let path = format!("{}/hello", env!("CARGO_TARGET_TMPDIR"));
44-
std::fs::read_dir(path);
44+
let _ = std::fs::read_dir(path);
4545
})
4646
.await?;
4747
assert_contains(

crates/fspy/tests/rust_tokio.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async fn open_read() -> anyhow::Result<()> {
1111
let accesses = track_child!({
1212
tokio::runtime::Builder::new_current_thread().enable_io().build().unwrap().block_on(
1313
async {
14-
tokio::fs::File::open("hello").await;
14+
let _ = tokio::fs::File::open("hello").await;
1515
},
1616
);
1717
})
@@ -28,7 +28,7 @@ async fn open_write() -> anyhow::Result<()> {
2828

2929
tokio::runtime::Builder::new_current_thread().enable_io().build().unwrap().block_on(
3030
async {
31-
OpenOptions::new().write(true).open(path).await;
31+
let _ = OpenOptions::new().write(true).open(path).await;
3232
},
3333
);
3434
})
@@ -49,7 +49,7 @@ async fn readdir() -> anyhow::Result<()> {
4949

5050
tokio::runtime::Builder::new_current_thread().enable_io().build().unwrap().block_on(
5151
async {
52-
tokio::fs::read_dir(path).await;
52+
let _ = tokio::fs::read_dir(path).await;
5353
},
5454
);
5555
})

crates/fspy/tests/test_utils.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::path::{Path, PathBuf, StripPrefixError};
22

33
use fspy::{AccessMode, PathAccessIterable};
4+
#[doc(hidden)]
5+
#[allow(unused)]
6+
pub use fspy_test_utils::command_executing;
47

58
#[track_caller]
69
pub fn assert_contains(
@@ -32,29 +35,19 @@ pub fn assert_contains(
3235
#[macro_export]
3336
macro_rules! track_child {
3437
($body: block) => {{
35-
const ID: &str =
36-
::core::concat!(::core::file!(), ":", ::core::line!(), ":", ::core::column!());
37-
#[ctor::ctor]
38-
unsafe fn init() {
39-
let mut args = ::std::env::args();
40-
let Some(_) = args.next() else {
41-
return;
42-
};
43-
let Some(current_id) = args.next() else {
44-
return;
45-
};
46-
if current_id == ID {
47-
$body;
48-
::std::process::exit(0);
49-
}
50-
}
51-
$crate::test_utils::_spawn_with_id(ID)
38+
let std_cmd = $crate::test_utils::command_executing!((), |(): ()| {
39+
let _ = $body;
40+
});
41+
$crate::test_utils::spawn_std(std_cmd)
5242
}};
5343
}
5444

55-
pub async fn _spawn_with_id(id: &str) -> anyhow::Result<PathAccessIterable> {
56-
let mut command = fspy::Command::new(::std::env::current_exe()?);
57-
command.arg(id);
45+
#[doc(hidden)]
46+
#[allow(unused)]
47+
pub async fn spawn_std(std_cmd: std::process::Command) -> anyhow::Result<PathAccessIterable> {
48+
let mut command = fspy::Command::new(std_cmd.get_program());
49+
command.args(std_cmd.get_args());
50+
5851
let termination = command.spawn().await?.wait_handle.await?;
5952
assert!(termination.status.success());
6053
Ok(termination.path_accesses)

0 commit comments

Comments
 (0)