diff --git a/fish-rust/src/fds.rs b/fish-rust/src/fds.rs index 742599ff7..bdaefac7d 100644 --- a/fish-rust/src/fds.rs +++ b/fish-rust/src/fds.rs @@ -233,3 +233,22 @@ pub fn make_fd_blocking(fd: RawFd) -> Result<(), io::Error> { } Ok(()) } + +crate::ffi_tests::add_test!("test_pipes", || { + // Here we just test that each pipe has CLOEXEC set and is in the high range. + // Note pipe creation may fail due to fd exhaustion; don't fail in that case. + let mut pipes = vec![]; + for _i in 0..10 { + if let Some(pipe) = make_autoclose_pipes() { + pipes.push(pipe); + } + } + for pipe in pipes { + for fd in [pipe.read.fd(), pipe.write.fd()] { + assert!(fd >= FIRST_HIGH_FD); + let flags = unsafe { libc::fcntl(fd, F_GETFD, 0) }; + assert!(flags >= 0); + assert!(flags & FD_CLOEXEC != 0); + } + } +}); diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index fc1c67bd4..0d2bffe61 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -2035,27 +2035,6 @@ void test_dirname_basename() { do_test(wbasename(longpath) == L"overlong"); } -// todo!("port this") -static void test_pipes() { - say(L"Testing pipes"); - // Here we just test that each pipe has CLOEXEC set and is in the high range. - // Note pipe creation may fail due to fd exhaustion; don't fail in that case. - std::vector pipes; - for (int i = 0; i < 10; i++) { - if (auto pipe = make_autoclose_pipes()) { - pipes.push_back(pipe.acquire()); - } - } - for (const auto &pipe : pipes) { - for (int fd : {pipe.read.fd(), pipe.write.fd()}) { - do_test(fd >= k_first_high_fd); - int flags = fcntl(fd, F_GETFD, 0); - do_test(flags >= 0); - do_test(bool(flags & FD_CLOEXEC)); - } - } -} - // todo!("port this") static void test_fd_event_signaller() { say(L"Testing fd event signaller"); @@ -2141,7 +2120,6 @@ static const test_t s_tests[]{ {TEST_GROUP("maybe"), test_maybe}, {TEST_GROUP("normalize"), test_normalize_path}, {TEST_GROUP("dirname"), test_dirname_basename}, - {TEST_GROUP("pipes"), test_pipes}, {TEST_GROUP("fd_event"), test_fd_event_signaller}, {TEST_GROUP("rust_smoke"), test_rust_smoke}, {TEST_GROUP("rust_ffi"), test_rust_ffi},