| 1 | #[test] |
| 2 | fn test_basic_pipes() { |
| 3 | use rustix::io::{read, write}; |
| 4 | use rustix::pipe::pipe; |
| 5 | |
| 6 | let message = b"Hello, tee!"; |
| 7 | |
| 8 | #[cfg(not(any( |
| 9 | solarish, |
| 10 | windows, |
| 11 | target_os = "espidf", |
| 12 | target_os = "haiku", |
| 13 | target_os = "redox", |
| 14 | target_os = "wasi", |
| 15 | )))] |
| 16 | assert!(message.len() <= rustix::pipe::PIPE_BUF); |
| 17 | |
| 18 | let (reader, writer) = pipe().unwrap(); |
| 19 | |
| 20 | let n = write(&writer, message).unwrap(); |
| 21 | assert_eq!(n, message.len()); |
| 22 | |
| 23 | let mut buf = vec![0_u8; 256]; |
| 24 | let n = read(&reader, &mut buf).unwrap(); |
| 25 | assert_eq!(n, message.len()); |
| 26 | assert_eq!(&buf[..n], message); |
| 27 | } |
| 28 | |
| 29 | #[cfg(not(any(apple, target_os = "aix", target_os = "espidf", target_os = "haiku")))] |
| 30 | #[test] |