From 2828d90f9984b2fe470e6d6650d52523f5848122 Mon Sep 17 00:00:00 2001 From: Simon Engmann Date: Mon, 30 Dec 2019 22:51:11 +0100 Subject: [PATCH] Don't assume that /dev/null exists in test If `/dev/null` doesn't exist or is not on a different partition during the test for `--one-file-system`, the test is skipped instead of mistakenly failing. --- tests/tests.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/tests.rs b/tests/tests.rs index 7a7e3ff..0b88e54 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -562,10 +562,24 @@ fn test_follow() { #[test] #[cfg(unix)] fn test_file_system_boundaries() { + // Helper function to get the device ID for a given path + fn device_num(path: impl AsRef) -> u64 { + use std::os::unix::fs::MetadataExt; + + path.as_ref().metadata().map(|md| md.dev()).unwrap() + } + // Can't simulate file system boundaries let te = TestEnv::new(&[], &[]); - // /dev/null should exist in all sane Unixes + let dev_null = Path::new("/dev/null"); + + // /dev/null should exist in all sane Unixes. Skip if it doesn't exist for some reason. + // Also skip should it be on the same device as the root partition for some reason. + if !dev_null.is_file() || device_num(dev_null) == device_num("/") { + return; + } + te.assert_output( &["--full-path", "--max-depth", "2", "^/dev/null$", "/"], "/dev/null",