From 3893fbb0b1110728fded596d2c457db8ad390bcf Mon Sep 17 00:00:00 2001 From: Solomon Date: Thu, 14 Nov 2024 02:13:04 -0700 Subject: [PATCH] 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 --- crates/nu-glob/src/lib.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/crates/nu-glob/src/lib.rs b/crates/nu-glob/src/lib.rs index 2a3f861983..602500fa1a 100644 --- a/crates/nu-glob/src/lib.rs +++ b/crates/nu-glob/src/lib.rs @@ -1144,18 +1144,28 @@ 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() { - // GlobErrors shouldn't halt iteration - let next = iter.next(); - assert!(next.is_some()); + match std::fs::read_dir("/root/") { + // skip if running with permissions to read /root + Ok(_) => {} - let err = next.unwrap(); - assert!(err.is_err()); + // skip if /root doesn't exist + Err(err) if err.kind() == io::ErrorKind::NotFound => { + assert!(iter.count() == 0); + } - let err = err.err().unwrap(); - assert!(err.path() == Path::new("/root")); - assert!(err.error().kind() == io::ErrorKind::PermissionDenied); + // should otherwise return a single match with permission error + Err(_) => { + // GlobErrors shouldn't halt iteration + let next = iter.next(); + assert!(next.is_some()); + + let err = next.unwrap(); + assert!(err.is_err()); + + let err = err.err().unwrap(); + assert!(err.path() == Path::new("/root")); + assert!(err.error().kind() == io::ErrorKind::PermissionDenied); + } } }