Skip to content

Commit 2f11666

Browse files
KSXGitHubclaude
andauthored
refactor(test): replace #[cfg] with #[cfg_attr(..., ignore)] in device_id tests (#380)
The device_id tests compile on all platforms since get_device_id and DeviceId exist everywhere. Use cfg_attr ignore instead of cfg gates so these tests are still compiled (catching type errors early) but skipped at runtime on unsupported platforms. Rename the duplicate-named different_filesystem_returns_different_ids functions to unique names to allow both to coexist without cfg gates. https://claude.ai/code/session_01UJVc5eCuHdjJwKFpcV82vP Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5a88f61 commit 2f11666

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/fs_tree_builder/device_id.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ pub fn get_device_id(_stats: &std::fs::Metadata) -> DeviceId {
2525
}
2626

2727
#[cfg(test)]
28-
#[cfg(unix)]
2928
mod tests {
3029
use super::get_device_id;
3130
use std::fs::symlink_metadata;
3231

3332
#[test]
33+
#[cfg_attr(not(unix), ignore = "device ID is meaningful only on unix")]
3434
fn same_filesystem_returns_equal_ids() {
3535
let root_stats = symlink_metadata("/").expect("stat /");
3636
let root_stats2 = symlink_metadata("/").expect("stat / again");
@@ -43,8 +43,11 @@ mod tests {
4343

4444
/// `/proc` is a virtual filesystem mounted separately from `/` on Linux.
4545
#[test]
46-
#[cfg(target_os = "linux")]
47-
fn different_filesystem_returns_different_ids() {
46+
#[cfg_attr(
47+
not(target_os = "linux"),
48+
ignore = "/proc is a separate filesystem only on Linux"
49+
)]
50+
fn different_filesystem_returns_different_ids_linux() {
4851
let root_stats = symlink_metadata("/").expect("stat /");
4952
let proc_stats = symlink_metadata("/proc").expect("stat /proc");
5053
assert_ne!(
@@ -56,8 +59,11 @@ mod tests {
5659

5760
/// `/dev` is a separate filesystem (`devfs`) from `/` on macOS.
5861
#[test]
59-
#[cfg(target_os = "macos")]
60-
fn different_filesystem_returns_different_ids() {
62+
#[cfg_attr(
63+
not(target_os = "macos"),
64+
ignore = "/dev is a separate filesystem only on macOS"
65+
)]
66+
fn different_filesystem_returns_different_ids_macos() {
6167
let root_stats = symlink_metadata("/").expect("stat /");
6268
let dev_stats = symlink_metadata("/dev").expect("stat /dev");
6369
assert_ne!(

0 commit comments

Comments
 (0)