From 126e71a84d684d4f75bdfc9140f23cfe14953153 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 17 Jul 2022 21:51:52 -0400 Subject: [PATCH] libc test: also call isatty on an actual file --- tests/pass/libc.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/pass/libc.rs b/tests/pass/libc.rs index 6da5279270..08c1abe642 100644 --- a/tests/pass/libc.rs +++ b/tests/pass/libc.rs @@ -1,8 +1,10 @@ //@ignore-windows: No libc on Windows //@compile-flags: -Zmiri-disable-isolation - #![feature(rustc_private)] +use std::fs::{remove_file, File}; +use std::os::unix::io::AsRawFd; + extern crate libc; #[cfg(any(target_os = "linux", target_os = "freebsd"))] @@ -15,9 +17,7 @@ fn tmp() -> std::path::PathBuf { #[cfg(any(target_os = "linux", target_os = "freebsd"))] fn test_posix_fadvise() { use std::convert::TryInto; - use std::fs::{remove_file, File}; use std::io::Write; - use std::os::unix::io::AsRawFd; let path = tmp().join("miri_test_libc_posix_fadvise.txt"); // Cleanup before test @@ -44,9 +44,7 @@ fn test_posix_fadvise() { #[cfg(any(target_os = "linux"))] fn test_sync_file_range() { - use std::fs::{remove_file, File}; use std::io::Write; - use std::os::unix::io::AsRawFd; let path = tmp().join("miri_test_libc_sync_file_range.txt"); // Cleanup before test. @@ -319,6 +317,19 @@ fn test_isatty() { libc::isatty(libc::STDIN_FILENO); libc::isatty(libc::STDOUT_FILENO); libc::isatty(libc::STDERR_FILENO); + + // But when we open a file, it is definitely not a TTY. + let path = tmp().join("notatty.txt"); + // Cleanup before test. + remove_file(&path).ok(); + let file = File::create(&path).unwrap(); + + assert_eq!(libc::isatty(file.as_raw_fd()), 0); + assert_eq!(std::io::Error::last_os_error().raw_os_error().unwrap(), libc::ENOTTY); + + // Cleanup after test. + drop(file); + remove_file(&path).unwrap(); } }