| 1 | #[test] |
| 2 | fn test_stat() { |
| 3 | use rustix::fs::{fstat, lstat, stat, symlink}; |
| 4 | use std::io::Write as _; |
| 5 | |
| 6 | let tmp = tempfile::tempdir().unwrap(); |
| 7 | |
| 8 | let mut w = std::fs::File::create(tmp.path().join("file")).unwrap(); |
| 9 | writeln!(&mut w, "Hello, File!").unwrap(); |
| 10 | |
| 11 | assert_eq!(fstat(&w).unwrap().st_size, 13); |
| 12 | assert_eq!(stat(tmp.path().join("file")).unwrap().st_size, 13); |
| 13 | assert_eq!(lstat(tmp.path().join("file")).unwrap().st_size, 13); |
| 14 | |
| 15 | symlink("file", tmp.path().join("link")).unwrap(); |
| 16 | |
| 17 | assert_eq!(stat(tmp.path().join("link")).unwrap().st_size, 13); |
| 18 | assert_eq!(lstat(tmp.path().join("link")).unwrap().st_size, 4); |
| 19 | } |