Skip to content

Commit bb8e8cc

Browse files
committed
refactor(test): probe permissions instead of checking euid
Replace the `unsafe { libc::geteuid() }` check with a direct probe: after chmod -r, try read_dir and skip if it still succeeds. This removes the `unsafe` block and the `libc` dev-dependency while being more semantically correct — it tests the actual condition we care about rather than a proxy. https://claude.ai/code/session_01Ki7wbrgQXWs2GXf8h2hybQ
1 parent 4179eb7 commit bb8e8cc

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ zero-copy-pads = "0.2.0"
7979
[dev-dependencies]
8080
build-fs-tree = "0.8.1"
8181
command-extra = "1.0.0"
82-
libc = "0.2"
8382
maplit = "1.0.2"
8483
normalize-path = "0.2.1"
8584
pretty_assertions = "1.4.1"

tests/cli_errors.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,16 @@ fn max_depth_0() {
108108
#[cfg(unix)]
109109
#[test]
110110
fn fs_errors() {
111-
if unsafe { libc::geteuid() } == 0 {
112-
eprintln!("SKIPPED: fs_errors test cannot work as root (permission checks are bypassed)");
113-
return;
114-
}
115-
116111
let workspace = SampleWorkspace::default();
117112
fs_permission(workspace.join("empty-dir"), "-r", false);
118113
fs_permission(workspace.join("nested").join("0"), "-r", false);
119114

115+
if std::fs::read_dir(workspace.join("empty-dir")).is_ok() {
116+
fs_permission(&workspace, "+rwx", true);
117+
eprintln!("SKIPPED: permission removal had no effect (likely running as root)");
118+
return;
119+
}
120+
120121
let Output {
121122
status,
122123
stdout,

0 commit comments

Comments
 (0)