Skip to content

Commit dc52386

Browse files
committed
refactor(test): address review feedback on ignore attributes
- Change ignore reason to "only one path separator style is tested" - Reorder attributes: place #[cfg_attr(..., ignore)] below #[test] - Revert hint message in fs_errors back to "skip" - Soften "Always" to "Prefer" for reason strings in CONTRIBUTING.md - Rephrase CONTRIBUTING.md to mention tests are "still compiled" https://claude.ai/code/session_0184ceZayyCwvK7PEF9iB7K3
1 parent 53356ff commit dc52386

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,16 @@ pub enum RuntimeError {
215215

216216
### Conditional Test Skipping: `#[cfg]` vs `#[cfg_attr(..., ignore)]`
217217

218-
When a test cannot run under certain conditions (e.g., wrong platform, running as root), prefer `#[cfg_attr(..., ignore)]` over `#[cfg(...)]` to skip it. `#[ignore]` keeps the test compiled on all configurations, catching type errors and regressions early — the test is simply skipped at runtime.
218+
When a test cannot run under certain conditions (e.g., wrong platform, running as root), prefer `#[cfg_attr(..., ignore)]` over `#[cfg(...)]` to skip it. This way the test is still compiled on all configurationscatching type errors and regressions early — but simply skipped at runtime.
219219

220220
Use `#[cfg]` on tests **only** when the code cannot compile under the condition — for example, when the test references types, functions, or trait methods that are gated behind `#[cfg]` and do not exist on other platforms or feature sets.
221221

222-
Always include a reason string in the `ignore` attribute to explain why the test is skipped.
222+
Prefer including a reason string in the `ignore` attribute to explain why the test is skipped.
223223

224224
```rust
225225
// Good — test compiles everywhere, skipped at runtime on non-unix
226-
#[cfg_attr(not(unix), ignore = "test uses hardcoded unix paths")]
227226
#[test]
227+
#[cfg_attr(not(unix), ignore = "only one path separator style is tested")]
228228
fn unix_path_logic() { /* uses hardcoded unix paths but no unix-only types */ }
229229

230230
// Good — test CANNOT compile on non-unix (uses unix-only types)
@@ -233,8 +233,8 @@ fn unix_path_logic() { /* uses hardcoded unix paths but no unix-only types */ }
233233
fn block_size() { /* uses GetBlockSize which only exists on unix */ }
234234

235235
// Good — test compiles with the flag, skipped at runtime
236-
#[cfg_attr(pdu_test_skip_fs_errors, ignore = "pdu_test_skip_fs_errors is set")]
237236
#[test]
237+
#[cfg_attr(pdu_test_skip_fs_errors, ignore = "pdu_test_skip_fs_errors is set")]
238238
fn fs_errors() { /* ... */ }
239239

240240
// Bad — excludes the test from compilation entirely when it could still compile

src/app/overlapping_arguments/test_remove_overlapping_paths.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ impl Api for MockedApi {
6969
}
7070
}
7171

72-
#[cfg_attr(not(unix), ignore = "test uses hardcoded unix paths")]
7372
#[test]
73+
#[cfg_attr(not(unix), ignore = "only one path separator style is tested")]
7474
fn remove_nothing() {
7575
let original = vec!["foo", "bar", "abc/def", "0/1/2"];
7676
let mut actual = original.clone();
@@ -79,8 +79,8 @@ fn remove_nothing() {
7979
assert_eq!(actual, expected);
8080
}
8181

82-
#[cfg_attr(not(unix), ignore = "test uses hardcoded unix paths")]
8382
#[test]
83+
#[cfg_attr(not(unix), ignore = "only one path separator style is tested")]
8484
fn remove_duplicated_arguments() {
8585
let original = dbg!(vec![
8686
"foo",
@@ -111,8 +111,8 @@ fn remove_duplicated_arguments() {
111111
assert_eq!(actual, expected);
112112
}
113113

114-
#[cfg_attr(not(unix), ignore = "test uses hardcoded unix paths")]
115114
#[test]
115+
#[cfg_attr(not(unix), ignore = "only one path separator style is tested")]
116116
fn remove_overlapping_sub_paths() {
117117
let original = vec![
118118
"foo/child",
@@ -129,8 +129,8 @@ fn remove_overlapping_sub_paths() {
129129
assert_eq!(actual, expected);
130130
}
131131

132-
#[cfg_attr(not(unix), ignore = "test uses hardcoded unix paths")]
133132
#[test]
133+
#[cfg_attr(not(unix), ignore = "only one path separator style is tested")]
134134
fn remove_all_except_current_dir() {
135135
let original = dbg!(vec!["foo", "bar", ".", "abc/def", "0/1/2"]);
136136
let mut actual = original.clone();
@@ -165,8 +165,8 @@ fn remove_all_except_current_dir() {
165165
assert_eq!(actual, expected);
166166
}
167167

168-
#[cfg_attr(not(unix), ignore = "test uses hardcoded unix paths")]
169168
#[test]
169+
#[cfg_attr(not(unix), ignore = "only one path separator style is tested")]
170170
fn remove_all_except_parent_dir() {
171171
let original = dbg!(vec!["foo", "bar", "..", "abc/def", ".", "0/1/2"]);
172172
let mut actual = original.clone();
@@ -189,8 +189,8 @@ fn remove_all_except_parent_dir() {
189189
assert_eq!(actual, expected);
190190
}
191191

192-
#[cfg_attr(not(unix), ignore = "test uses hardcoded unix paths")]
193192
#[test]
193+
#[cfg_attr(not(unix), ignore = "only one path separator style is tested")]
194194
fn remove_overlapping_real_paths() {
195195
let original = dbg!(vec![
196196
"foo",
@@ -232,8 +232,8 @@ fn remove_overlapping_real_paths() {
232232
assert_eq!(actual, expected);
233233
}
234234

235-
#[cfg_attr(not(unix), ignore = "test uses hardcoded unix paths")]
236235
#[test]
236+
#[cfg_attr(not(unix), ignore = "only one path separator style is tested")]
237237
fn do_not_remove_symlinks() {
238238
let original = dbg!(vec![
239239
"foo",

tests/cli_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ fn max_depth_0() {
106106
}
107107

108108
#[cfg(unix)]
109-
#[cfg_attr(pdu_test_skip_fs_errors, ignore = "pdu_test_skip_fs_errors is set")]
110109
#[test]
110+
#[cfg_attr(pdu_test_skip_fs_errors, ignore = "pdu_test_skip_fs_errors is set")]
111111
fn fs_errors() {
112112
if unsafe { libc::geteuid() } == 0 {
113113
panic!(
114114
"{}\n{}",
115115
"error: This test must not be run as root because running with elevated privileges would affect its accuracy.",
116-
"hint: Either run this test as a non-root user or set `RUSTFLAGS='--cfg pdu_test_skip_fs_errors'` to ignore this test.",
116+
"hint: Either run this test as a non-root user or set `RUSTFLAGS='--cfg pdu_test_skip_fs_errors'` to skip this test.",
117117
);
118118
}
119119

0 commit comments

Comments
 (0)