Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e30dd07

Browse files
committed
libc test: also call isatty on an actual file
1 parent 896f558 commit e30dd07

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

tests/pass/libc.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//@ignore-windows: No libc on Windows
22
//@compile-flags: -Zmiri-disable-isolation
3-
43
#![feature(rustc_private)]
54

5+
use std::fs::{remove_file, File};
6+
use std::os::unix::io::AsRawFd;
7+
68
extern crate libc;
79

8-
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
910
fn tmp() -> std::path::PathBuf {
1011
std::env::var("MIRI_TEMP")
1112
.map(std::path::PathBuf::from)
@@ -15,9 +16,7 @@ fn tmp() -> std::path::PathBuf {
1516
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
1617
fn test_posix_fadvise() {
1718
use std::convert::TryInto;
18-
use std::fs::{remove_file, File};
1919
use std::io::Write;
20-
use std::os::unix::io::AsRawFd;
2120

2221
let path = tmp().join("miri_test_libc_posix_fadvise.txt");
2322
// Cleanup before test
@@ -44,9 +43,7 @@ fn test_posix_fadvise() {
4443

4544
#[cfg(any(target_os = "linux"))]
4645
fn test_sync_file_range() {
47-
use std::fs::{remove_file, File};
4846
use std::io::Write;
49-
use std::os::unix::io::AsRawFd;
5047

5148
let path = tmp().join("miri_test_libc_sync_file_range.txt");
5249
// Cleanup before test.
@@ -319,6 +316,19 @@ fn test_isatty() {
319316
libc::isatty(libc::STDIN_FILENO);
320317
libc::isatty(libc::STDOUT_FILENO);
321318
libc::isatty(libc::STDERR_FILENO);
319+
320+
// But when we open a file, it is definitely not a TTY.
321+
let path = tmp().join("notatty.txt");
322+
// Cleanup before test.
323+
remove_file(&path).ok();
324+
let file = File::create(&path).unwrap();
325+
326+
assert_eq!(libc::isatty(file.as_raw_fd()), 0);
327+
assert_eq!(std::io::Error::last_os_error().raw_os_error().unwrap(), libc::ENOTTY);
328+
329+
// Cleanup after test.
330+
drop(file);
331+
remove_file(&path).unwrap();
322332
}
323333
}
324334

0 commit comments

Comments
 (0)