Skip to content

Commit 58cd701

Browse files
committed
tests: make xattr test more robust
Currently the xattr test asserts that listxattr() on Cargo.toml returns a length of 0. This causes a spurious failure when Cargo.toml does have xattrs, and this can happen in fairly normal situations like when a Linux distribution enables selinux (as it does on an AlmaLinux 10 test system, for example): $ cat /etc/almalinux-release AlmaLinux release 10.0 (Purple Lion) $ getfattr -d -m - Cargo.toml security.selinux=[...] $ cargo test --features=fs,stdio xattr [...] thread 'xattr::xattr_basic' panicked at tests/fs/xattr.rs:88:5: assertion `left == right` failed left: 17 right: 0 This change fixes the failure by making the test not assume that the file has no xattrs defined. Given that, pretty much the only reasonable thing the test can assume about a call to listxattr is that it should succeed for a file that is known to exist. So this makes the test just assert that it succeeds.
1 parent 65b04ae commit 58cd701

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tests/fs/xattr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ fn xattr_basic() {
8585
.raw_os_error(),
8686
enodata
8787
);
88-
assert_eq!(rustix::fs::listxattr("Cargo.toml", &mut empty).unwrap(), 0);
89-
assert_eq!(rustix::fs::llistxattr("Cargo.toml", &mut empty).unwrap(), 0);
88+
assert!(rustix::fs::listxattr("Cargo.toml", &mut empty).is_ok());
89+
assert!(rustix::fs::llistxattr("Cargo.toml", &mut empty).is_ok());
9090
assert_eq!(
9191
rustix::fs::removexattr("Cargo.toml", "user.test")
9292
.unwrap_err()

0 commit comments

Comments
 (0)