summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/tests/termios
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rustix/tests/termios')
-rw-r--r--vendor/rustix/tests/termios/isatty.rs69
-rw-r--r--vendor/rustix/tests/termios/main.rs10
-rw-r--r--vendor/rustix/tests/termios/ttyname.rs24
3 files changed, 103 insertions, 0 deletions
diff --git a/vendor/rustix/tests/termios/isatty.rs b/vendor/rustix/tests/termios/isatty.rs
new file mode 100644
index 000000000..5e6fae73d
--- /dev/null
+++ b/vendor/rustix/tests/termios/isatty.rs
@@ -0,0 +1,69 @@
+use rustix::fd::AsRawFd;
+use rustix::termios::{isatty, tcgetwinsize};
+use tempfile::{tempdir, TempDir};
+
+#[allow(unused)]
+fn tmpdir() -> TempDir {
+ tempdir().expect("expected to be able to create a temporary directory")
+}
+
+#[test]
+fn std_file_is_not_terminal() {
+ let tmpdir = tempfile::tempdir().unwrap();
+ assert!(!isatty(
+ &std::fs::File::create(tmpdir.path().join("file")).unwrap()
+ ));
+ assert!(!isatty(
+ &std::fs::File::open(tmpdir.path().join("file")).unwrap()
+ ));
+}
+
+#[test]
+fn stdout_stderr_terminals() {
+ // This test is flaky under qemu.
+ if std::env::vars().any(|var| var.0.starts_with("CARGO_TARGET_") && var.0.ends_with("_RUNNER"))
+ {
+ return;
+ }
+
+ // Compare `isatty` against `libc::isatty`.
+ assert_eq!(isatty(&std::io::stdout()), unsafe {
+ libc::isatty(std::io::stdout().as_raw_fd()) != 0
+ });
+ assert_eq!(isatty(&std::io::stderr()), unsafe {
+ libc::isatty(std::io::stderr().as_raw_fd()) != 0
+ });
+
+ // Compare `isatty` against `tcgetwinsize`.
+ assert_eq!(
+ isatty(&std::io::stdout()),
+ tcgetwinsize(&std::io::stdout()).is_ok()
+ );
+ assert_eq!(
+ isatty(&std::io::stderr()),
+ tcgetwinsize(&std::io::stderr()).is_ok()
+ );
+}
+
+#[test]
+fn stdio_descriptors() {
+ #[cfg(unix)]
+ use std::os::unix::io::AsRawFd;
+ #[cfg(target_os = "wasi")]
+ use std::os::wasi::io::AsRawFd;
+
+ unsafe {
+ assert_eq!(
+ rustix::io::stdin().as_raw_fd(),
+ std::io::stdin().as_raw_fd()
+ );
+ assert_eq!(
+ rustix::io::stdout().as_raw_fd(),
+ std::io::stdout().as_raw_fd()
+ );
+ assert_eq!(
+ rustix::io::stderr().as_raw_fd(),
+ std::io::stderr().as_raw_fd()
+ );
+ }
+}
diff --git a/vendor/rustix/tests/termios/main.rs b/vendor/rustix/tests/termios/main.rs
new file mode 100644
index 000000000..d9ad9338b
--- /dev/null
+++ b/vendor/rustix/tests/termios/main.rs
@@ -0,0 +1,10 @@
+//! Tests for [`rustix::termios`].
+
+#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
+#![cfg_attr(io_lifetimes_use_std, feature(io_safety))]
+#![cfg(feature = "termios")]
+
+#[cfg(not(windows))]
+mod isatty;
+#[cfg(not(windows))]
+mod ttyname;
diff --git a/vendor/rustix/tests/termios/ttyname.rs b/vendor/rustix/tests/termios/ttyname.rs
new file mode 100644
index 000000000..636178c31
--- /dev/null
+++ b/vendor/rustix/tests/termios/ttyname.rs
@@ -0,0 +1,24 @@
+use rustix::io;
+use rustix::termios::{isatty, ttyname};
+use std::fs::File;
+
+#[test]
+fn test_ttyname_ok() {
+ let file = File::open("/dev/stdin").unwrap();
+ if isatty(&file) {
+ assert!(ttyname(&file, Vec::new())
+ .unwrap()
+ .into_string()
+ .unwrap()
+ .starts_with("/dev/"));
+ }
+}
+
+#[test]
+fn test_ttyname_not_tty() {
+ let file = File::open("Cargo.toml").unwrap();
+ assert_eq!(ttyname(&file, Vec::new()).unwrap_err(), io::Errno::NOTTY);
+
+ let file = File::open("/dev/null").unwrap();
+ assert_eq!(ttyname(&file, Vec::new()).unwrap_err(), io::Errno::NOTTY);
+}