diff options
author | Utkarsh Kukreti <utkarshkukreti@gmail.com> | 2015-02-11 12:12:34 +0530 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2015-02-12 21:10:49 -0800 |
commit | 954a1e6002c5c8dce4e88fb77e5fe398cb0871be (patch) | |
tree | 756f4da420fcbad58c9f524e7327a82950485756 | |
parent | f898b825566ab0738dbfa3a1a45010d37060aed0 (diff) | |
download | nix-954a1e6002c5c8dce4e88fb77e5fe398cb0871be.zip |
Add tests for `nix::sys::termios::tcgetattr()`.
-rw-r--r-- | tests/sys/termios.rs | 21 | ||||
-rw-r--r-- | tests/tests.rs | 6 |
2 files changed, 27 insertions, 0 deletions
diff --git a/tests/sys/termios.rs b/tests/sys/termios.rs new file mode 100644 index 00000000..24ce3434 --- /dev/null +++ b/tests/sys/termios.rs @@ -0,0 +1,21 @@ +use nix::errno::Errno; +use nix::sys::termios; +use nix::{NixError, unistd}; + +#[test] +fn test_tcgetattr() { + for fd in 0..5 { + let termios = termios::tcgetattr(fd); + match unistd::isatty(fd) { + // If `fd` is a TTY, tcgetattr must succeed. + Ok(true) => assert!(termios.is_ok()), + // If it's an invalid file descriptor, tcgetattr should also return + // the same error + Err(NixError::Sys(Errno::EBADF)) => { + assert!(termios.err() == Some(NixError::Sys(Errno::EBADF))); + }, + // Otherwise it should return any error + _ => assert!(termios.is_err()) + } + } +} diff --git a/tests/tests.rs b/tests/tests.rs new file mode 100644 index 00000000..b0b09a2b --- /dev/null +++ b/tests/tests.rs @@ -0,0 +1,6 @@ +#![feature(core)] +extern crate nix; + +mod sys { + mod termios; +} |