@@ -8,3 +8,49 @@ mod linux;
88pub use linux:: * ;
99#[ cfg( not( target_os = "linux" ) ) ]
1010compile_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