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

Commit

Permalink
tests: add some no_run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PatchMixolydic committed Aug 14, 2021
1 parent 0f8e230 commit 22eaa6c
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,49 @@ mod linux;
pub use linux::*;
#[cfg(not(target_os = "linux"))]
compile_error!("pidfds are currently only supported on Linux");

#[cfg(any(test, doctest))]
mod tests {
/// Used to allow for `no_run` tests.
///
/// Using `pidfd`:
/// ```no_run (/usr/bin/foo likely does not exist and might close fd 1 regardless)
/// use pidfd::PidFd;
/// use pidfd_getfd::{GetFdFlags, PidFdExt};
/// use std::{io, process::Command};
///
/// fn main() -> io::Result<()> {
/// let child = Command::new("/usr/bin/foo").spawn().expect("failed to run `foo`");
/// let pidfd = PidFd::from_std_checked(&child)?;
/// let file_from_child = pidfd.get_file(1, GetFdFlags::empty())?;
/// Ok(())
/// }
/// ```
struct _DocTests;

#[cfg(feature = "nightly")]
/// Used to allow for `no_run` tests.
///
/// Using `std`'s `PidFd`:
/// ```no_run (/usr/bin/foo likely does not exist and might close fd 1 regardless)
/// #![feature(linux_pidfd)]
///
/// use pidfd_getfd::{GetFdFlags, PidFdExt};
/// use std::{
/// io,
/// os::linux::process::{ChildExt, CommandExt},
/// process::Command,
/// };
///
/// fn main() -> io::Result<()> {
/// let child = Command::new("/usr/bin/foo")
/// .create_pidfd(true)
/// .spawn()
/// .expect("failed to run `foo`");
///
/// let file_from_child = child.pidfd()?.get_file(1, GetFdFlags::empty())?;
/// Ok(())
/// }
/// ```
struct _NightlyDocTests;
}

0 comments on commit 22eaa6c

Please sign in to comment.