test is_terminal

This commit is contained in:
Ralf Jung 2022-10-21 14:16:12 +02:00
parent 7300aac798
commit 1c9f3682f5
2 changed files with 13 additions and 1 deletions

View File

@ -3,6 +3,7 @@
#![feature(io_error_more)] #![feature(io_error_more)]
#![feature(io_error_uncategorized)] #![feature(io_error_uncategorized)]
#![feature(is_terminal)]
use std::collections::HashMap; use std::collections::HashMap;
use std::ffi::OsString; use std::ffi::OsString;
@ -10,7 +11,7 @@
canonicalize, create_dir, read_dir, read_link, remove_dir, remove_dir_all, remove_file, rename, canonicalize, create_dir, read_dir, read_link, remove_dir, remove_dir_all, remove_file, rename,
File, OpenOptions, File, OpenOptions,
}; };
use std::io::{Error, ErrorKind, Read, Result, Seek, SeekFrom, Write}; use std::io::{Error, ErrorKind, IsTerminal, Read, Result, Seek, SeekFrom, Write};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
fn main() { fn main() {
@ -91,6 +92,8 @@ fn test_file() {
file.read_to_end(&mut contents).unwrap(); file.read_to_end(&mut contents).unwrap();
assert_eq!(bytes, contents.as_slice()); assert_eq!(bytes, contents.as_slice());
assert!(!file.is_terminal());
// Removing file should succeed. // Removing file should succeed.
remove_file(&path).unwrap(); remove_file(&path).unwrap();
} }

View File

@ -0,0 +1,9 @@
#![feature(is_terminal)]
use std::io::IsTerminal;
fn main() {
// We can't really assume that this is truly a terminal, and anyway on Windows Miri will always
// return `false` here, but we can check that the call succeeds.
std::io::stdout().is_terminal();
}