Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit 22eaa6c

Browse files
tests: add some no_run tests
1 parent 0f8e230 commit 22eaa6c

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/lib.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,49 @@ mod linux;
88
pub use linux::*;
99
#[cfg(not(target_os = "linux"))]
1010
compile_error!("pidfds are currently only supported on Linux");
11+
12+
#[cfg(any(test, doctest))]
13+
mod tests {
14+
/// Used to allow for `no_run` tests.
15+
///
16+
/// Using `pidfd`:
17+
/// ```no_run (/usr/bin/foo likely does not exist and might close fd 1 regardless)
18+
/// use pidfd::PidFd;
19+
/// use pidfd_getfd::{GetFdFlags, PidFdExt};
20+
/// use std::{io, process::Command};
21+
///
22+
/// fn main() -> io::Result<()> {
23+
/// let child = Command::new("/usr/bin/foo").spawn().expect("failed to run `foo`");
24+
/// let pidfd = PidFd::from_std_checked(&child)?;
25+
/// let file_from_child = pidfd.get_file(1, GetFdFlags::empty())?;
26+
/// Ok(())
27+
/// }
28+
/// ```
29+
struct _DocTests;
30+
31+
#[cfg(feature = "nightly")]
32+
/// Used to allow for `no_run` tests.
33+
///
34+
/// Using `std`'s `PidFd`:
35+
/// ```no_run (/usr/bin/foo likely does not exist and might close fd 1 regardless)
36+
/// #![feature(linux_pidfd)]
37+
///
38+
/// use pidfd_getfd::{GetFdFlags, PidFdExt};
39+
/// use std::{
40+
/// io,
41+
/// os::linux::process::{ChildExt, CommandExt},
42+
/// process::Command,
43+
/// };
44+
///
45+
/// fn main() -> io::Result<()> {
46+
/// let child = Command::new("/usr/bin/foo")
47+
/// .create_pidfd(true)
48+
/// .spawn()
49+
/// .expect("failed to run `foo`");
50+
///
51+
/// let file_from_child = child.pidfd()?.get_file(1, GetFdFlags::empty())?;
52+
/// Ok(())
53+
/// }
54+
/// ```
55+
struct _NightlyDocTests;
56+
}

0 commit comments

Comments
 (0)