-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for several more functions (#709)
* Add a test for `sysinfo`. * Add a test for `pipe_with`. * Add tests for `getpeername`. * Add tests for `accept_from`. * Add minimal tests for `fsync` and `fdatasync`: * Add tests for `close` and `dup`.
- Loading branch information
1 parent
d98d532
commit d30f908
Showing
8 changed files
with
254 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use rustix::fd::IntoRawFd; | ||
|
||
#[cfg(any(unix, target_os = "wasi"))] | ||
#[test] | ||
fn test_close_file() { | ||
let file = std::fs::File::open("Cargo.toml").unwrap(); | ||
let raw = file.into_raw_fd(); | ||
unsafe { | ||
rustix::io::close(raw); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_close_socket() { | ||
let socket = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); | ||
let raw = socket.into_raw_fd(); | ||
unsafe { | ||
rustix::io::close(raw); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#[cfg(feature = "fs")] | ||
#[test] | ||
fn test_dup() { | ||
let file = std::fs::File::open("Cargo.toml").unwrap(); | ||
let alt = rustix::io::dup(&file).unwrap(); | ||
|
||
// Initial position is 0. | ||
assert_eq!( | ||
rustix::fs::seek(&file, rustix::fs::SeekFrom::Current(0)), | ||
Ok(0) | ||
); | ||
assert_eq!( | ||
rustix::fs::seek(&alt, rustix::fs::SeekFrom::Current(0)), | ||
Ok(0) | ||
); | ||
|
||
let mut buf = [0_u8; 4]; | ||
assert_eq!(rustix::io::read(&file, &mut buf), Ok(4)); | ||
|
||
// Both postitions updated. | ||
assert_eq!( | ||
rustix::fs::seek(&file, rustix::fs::SeekFrom::Current(0)), | ||
Ok(4) | ||
); | ||
assert_eq!( | ||
rustix::fs::seek(&alt, rustix::fs::SeekFrom::Current(0)), | ||
Ok(4) | ||
); | ||
|
||
assert_eq!(rustix::io::read(&alt, &mut buf), Ok(4)); | ||
|
||
// Both postitions updated. | ||
assert_eq!( | ||
rustix::fs::seek(&file, rustix::fs::SeekFrom::Current(0)), | ||
Ok(8) | ||
); | ||
assert_eq!( | ||
rustix::fs::seek(&alt, rustix::fs::SeekFrom::Current(0)), | ||
Ok(8) | ||
); | ||
|
||
drop(file); | ||
|
||
assert_eq!(rustix::io::read(&alt, &mut buf), Ok(4)); | ||
|
||
assert_eq!( | ||
rustix::fs::seek(&alt, rustix::fs::SeekFrom::Current(0)), | ||
Ok(12) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.