skip test_iteration_errors if /root is missing (#14299)

# Description

`test_iteration_errors` no longer requires `/root` to exist:

```
failures:

---- test::test_iteration_errors stdout ----
thread 'test::test_iteration_errors' panicked at crates/nu-glob/src/li
b.rs:1151:13:
assertion failed: next.is_some()
```

`/root` is an optional home directory in the [File Hierarchy
Standard][1].

I encountered this while running the tests in a `guix shell` container,
which doesn't include a root user.

[1]: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s14.html

# User-Facing Changes

None
This commit is contained in:
Solomon 2024-11-14 02:13:04 -07:00 committed by GitHub
parent 948205c8e6
commit 3893fbb0b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1144,8 +1144,17 @@ mod test {
use std::io;
let mut iter = glob("/root/*").unwrap();
// Skip test if running with permissions to read /root
if std::fs::read_dir("/root/").is_err() {
match std::fs::read_dir("/root/") {
// skip if running with permissions to read /root
Ok(_) => {}
// skip if /root doesn't exist
Err(err) if err.kind() == io::ErrorKind::NotFound => {
assert!(iter.count() == 0);
}
// should otherwise return a single match with permission error
Err(_) => {
// GlobErrors shouldn't halt iteration
let next = iter.next();
assert!(next.is_some());
@ -1158,6 +1167,7 @@ mod test {
assert!(err.error().kind() == io::ErrorKind::PermissionDenied);
}
}
}
#[test]
fn test_absolute_pattern() {