MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / test_readlink

Function test_readlink

tests/fs/readlinkat.rs:2–27  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1#[test]
2fn test_readlink() {
3 use rustix::fs::{open, readlink, symlink, Mode, OFlags};
4
5 let tmp = tempfile::tempdir().unwrap();
6
7 let _ = open(
8 tmp.path().join("file"),
9 OFlags::CREATE | OFlags::WRONLY,
10 Mode::RUSR,
11 )
12 .unwrap();
13 symlink("file", tmp.path().join("link")).unwrap();
14
15 readlink(tmp.path().join("absent"), Vec::new()).unwrap_err();
16 readlink(tmp.path().join("file"), Vec::new()).unwrap_err();
17
18 let target = readlink(tmp.path().join("link"), Vec::new()).unwrap();
19 assert_eq!(target.to_string_lossy(), "file");
20
21 symlink("link", tmp.path().join("another")).unwrap();
22
23 let target = readlink(tmp.path().join("link"), Vec::new()).unwrap();
24 assert_eq!(target.to_string_lossy(), "file");
25 let target = readlink(tmp.path().join("another"), Vec::new()).unwrap();
26 assert_eq!(target.to_string_lossy(), "link");
27}
28
29#[cfg(not(target_os = "redox"))]
30#[test]

Callers

nothing calls this directly

Calls 4

openFunction · 0.50
symlinkFunction · 0.50
readlinkFunction · 0.50
pathMethod · 0.45

Tested by

no test coverage detected