Skip to content

Commit 36bfdd3

Browse files
committed
improve test
1 parent 1b9f748 commit 36bfdd3

2 files changed

Lines changed: 39 additions & 34 deletions

File tree

src/uucore/src/lib/features/safe_traversal.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ mod tests {
708708
}
709709

710710
#[test]
711+
#[allow(clippy::unnecessary_cast)]
711712
fn test_file_info() {
712713
let temp_dir = TempDir::new().unwrap();
713714
let file_path = temp_dir.path().join("test_file");
@@ -716,7 +717,6 @@ mod tests {
716717
let dir_fd = DirFd::open(temp_dir.path()).unwrap();
717718
let stat = dir_fd.stat_at(OsStr::new("test_file"), true).unwrap();
718719
let file_info = FileInfo::from_stat(&stat);
719-
#[allow(clippy::unnecessary_cast)]
720720
assert_eq!(file_info.device(), stat.st_dev as u64);
721721
assert_eq!(file_info.inode(), stat.st_ino as u64);
722722
}
@@ -756,6 +756,7 @@ mod tests {
756756
}
757757

758758
#[test]
759+
#[allow(clippy::unnecessary_cast)]
759760
fn test_metadata_wrapper() {
760761
let temp_dir = TempDir::new().unwrap();
761762
let file_path = temp_dir.path().join("test_file");

tests/by-util/test_du.rs

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -212,41 +212,45 @@ fn test_du_soft_link() {
212212
return;
213213
}
214214
}
215-
du_soft_link(result.stdout_str());
216-
}
217215

218-
#[cfg(target_vendor = "apple")]
219-
fn du_soft_link(s: &str) {
220-
// 'macos' host variants may have `du` output variation for soft links
221-
assert!((s == "12\tsubdir/links\n") || (s == "16\tsubdir/links\n"));
222-
}
223-
#[cfg(target_os = "windows")]
224-
fn du_soft_link(s: &str) {
225-
assert_eq!(s, "8\tsubdir/links\n");
226-
}
227-
#[cfg(target_os = "freebsd")]
228-
fn du_soft_link(s: &str) {
229-
// FreeBSD may have different block allocations depending on filesystem
230-
// Accept both common sizes
231-
let valid_sizes = ["12\tsubdir/links\n", "16\tsubdir/links\n"];
232-
assert!(
233-
valid_sizes.contains(&s),
234-
"Expected one of {:?}, got {}",
235-
valid_sizes,
236-
s
237-
);
238-
}
239-
#[cfg(all(
240-
not(target_vendor = "apple"),
241-
not(target_os = "windows"),
242-
not(target_os = "freebsd")
243-
))]
244-
fn du_soft_link(s: &str) {
245-
// MS-WSL linux has altered expected output
246-
if uucore::os::is_wsl_1() {
216+
let s = result.stdout_str();
217+
println!("Output: {s}");
218+
#[cfg(target_vendor = "apple")]
219+
{
220+
// 'macos' host variants may have `du` output variation for soft links
221+
assert!((s == "12\tsubdir/links\n") || (s == "16\tsubdir/links\n"));
222+
}
223+
224+
#[cfg(target_os = "windows")]
225+
{
247226
assert_eq!(s, "8\tsubdir/links\n");
248-
} else {
249-
assert_eq!(s, "16\tsubdir/links\n");
227+
}
228+
229+
#[cfg(target_os = "freebsd")]
230+
{
231+
// FreeBSD may have different block allocations depending on filesystem
232+
// Accept both common sizes
233+
let valid_sizes = ["12\tsubdir/links\n", "16\tsubdir/links\n"];
234+
assert!(
235+
valid_sizes.contains(&s),
236+
"Expected one of {:?}, got {}",
237+
valid_sizes,
238+
s
239+
);
240+
}
241+
242+
#[cfg(all(
243+
not(target_vendor = "apple"),
244+
not(target_os = "windows"),
245+
not(target_os = "freebsd")
246+
))]
247+
{
248+
// MS-WSL linux has altered expected output
249+
if uucore::os::is_wsl_1() {
250+
assert_eq!(s, "8\tsubdir/links\n");
251+
} else {
252+
assert_eq!(s, "16\tsubdir/links\n");
253+
}
250254
}
251255
}
252256

0 commit comments

Comments
 (0)