Skip to content

Commit f057cc6

Browse files
sylvestrecakebaker
authored andcommitted
tests: replace .no_stdout().no_stderr() chains with .no_output()
Bulk rename of the antipattern across 19 test files (136 occurrences). .no_output() is the established shorthand in the uutests framework for asserting both empty stdout and empty stderr.
1 parent 8aa9d9c commit f057cc6

19 files changed

Lines changed: 136 additions & 342 deletions

tests/by-util/test_chgrp.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ fn basic_succeeds() {
306306
ucmd.arg(group.as_raw().to_string())
307307
.arg("f1")
308308
.succeeds()
309-
.no_stdout()
310-
.no_stderr();
309+
.no_output();
311310
}
312311
}
313312

tests/by-util/test_chmod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,7 @@ fn test_chmod_symlink_non_existing_file_recursive() {
615615
.arg("755")
616616
.arg(test_directory)
617617
.succeeds()
618-
.no_stderr()
619-
.no_stdout();
618+
.no_output();
620619

621620
let expected_stdout = &format!(
622621
// spell-checker:disable-next-line

tests/by-util/test_chown.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ fn test_chown_only_user_id_nonexistent_user() {
517517
let at = &ts.fixtures;
518518
at.touch("f");
519519
if let Ok(result) = run_ucmd_as_root(&ts, &["12345", "f"]) {
520-
result.success().no_stdout().no_stderr();
520+
result.success().no_output();
521521
} else {
522522
print!("Test skipped; requires root user");
523523
}
@@ -585,7 +585,7 @@ fn test_chown_only_group_id_nonexistent_group() {
585585
let at = &ts.fixtures;
586586
at.touch("f");
587587
if let Ok(result) = run_ucmd_as_root(&ts, &[":12345", "f"]) {
588-
result.success().no_stdout().no_stderr();
588+
result.success().no_output();
589589
} else {
590590
print!("Test skipped; requires root user");
591591
}

tests/by-util/test_cp.rs

Lines changed: 30 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,7 @@ fn test_cp_arg_update_none() {
479479
.arg(TEST_HOW_ARE_YOU_SOURCE)
480480
.arg("--update=none")
481481
.succeeds()
482-
.no_stderr()
483-
.no_stdout();
482+
.no_output();
484483
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "How are you?\n");
485484
}
486485

@@ -503,8 +502,7 @@ fn test_cp_arg_update_all() {
503502
.arg(TEST_HOW_ARE_YOU_SOURCE)
504503
.arg("--update=all")
505504
.succeeds()
506-
.no_stderr()
507-
.no_stdout();
505+
.no_output();
508506

509507
assert_eq!(
510508
at.read(TEST_HOW_ARE_YOU_SOURCE),
@@ -528,8 +526,7 @@ fn test_cp_arg_update_older_dest_not_older_than_src() {
528526
.arg(new)
529527
.arg("--update=older")
530528
.succeeds()
531-
.no_stderr()
532-
.no_stdout();
529+
.no_output();
533530

534531
assert_eq!(at.read(new), "new content\n");
535532
}
@@ -551,8 +548,7 @@ fn test_cp_arg_update_older_dest_not_older_than_src_no_verbose_output() {
551548
.arg("--verbose")
552549
.arg("--update=older")
553550
.succeeds()
554-
.no_stderr()
555-
.no_stdout();
551+
.no_output();
556552

557553
assert_eq!(at.read(new), "new content\n");
558554
}
@@ -576,8 +572,7 @@ fn test_cp_arg_update_older_dest_older_than_src() {
576572
.arg(old)
577573
.arg("--update=older")
578574
.succeeds()
579-
.no_stderr()
580-
.no_stdout();
575+
.no_output();
581576

582577
assert_eq!(at.read(old), "new content\n");
583578
}
@@ -624,12 +619,7 @@ fn test_cp_arg_update_short_no_overwrite() {
624619

625620
at.write(new, new_content);
626621

627-
ucmd.arg(old)
628-
.arg(new)
629-
.arg("-u")
630-
.succeeds()
631-
.no_stderr()
632-
.no_stdout();
622+
ucmd.arg(old).arg(new).arg("-u").succeeds().no_output();
633623

634624
assert_eq!(at.read(new), "new content\n");
635625
}
@@ -650,12 +640,7 @@ fn test_cp_arg_update_short_overwrite() {
650640

651641
at.write(new, new_content);
652642

653-
ucmd.arg(new)
654-
.arg(old)
655-
.arg("-u")
656-
.succeeds()
657-
.no_stderr()
658-
.no_stdout();
643+
ucmd.arg(new).arg(old).arg("-u").succeeds().no_output();
659644

660645
assert_eq!(at.read(old), "new content\n");
661646
}
@@ -682,8 +667,7 @@ fn test_cp_arg_update_none_then_all() {
682667
.arg("--update=none")
683668
.arg("--update=all")
684669
.succeeds()
685-
.no_stderr()
686-
.no_stdout();
670+
.no_output();
687671

688672
assert_eq!(at.read(new), "old content\n");
689673
}
@@ -710,8 +694,7 @@ fn test_cp_arg_update_all_then_none() {
710694
.arg("--update=all")
711695
.arg("--update=none")
712696
.succeeds()
713-
.no_stderr()
714-
.no_stdout();
697+
.no_output();
715698

716699
assert_eq!(at.read(new), "new content\n");
717700
}
@@ -2940,8 +2923,7 @@ fn test_no_preserve_mode() {
29402923
.arg("dest")
29412924
.umask(libc::mode_t::from(umask))
29422925
.succeeds()
2943-
.no_stderr()
2944-
.no_stdout();
2926+
.no_output();
29452927
// remove sticky bit, setuid and setgid bit; apply umask
29462928
let expected_perms = PERMS_ALL & !0o7000 & u32::from(!umask);
29472929
assert_eq!(
@@ -2970,8 +2952,7 @@ fn test_preserve_mode() {
29702952
.arg("dest")
29712953
.arg("-p")
29722954
.succeeds()
2973-
.no_stderr()
2974-
.no_stdout();
2955+
.no_output();
29752956
assert_eq!(
29762957
at.plus("dest").metadata().unwrap().mode() & 0o7777,
29772958
PERMS_ALL
@@ -2984,11 +2965,7 @@ fn test_canonicalize_symlink() {
29842965
at.mkdir("dir");
29852966
at.touch("dir/file");
29862967
at.relative_symlink_file("../dir/file", "dir/file-ln");
2987-
ucmd.arg("dir/file-ln")
2988-
.arg(".")
2989-
.succeeds()
2990-
.no_stderr()
2991-
.no_stdout();
2968+
ucmd.arg("dir/file-ln").arg(".").succeeds().no_output();
29922969
}
29932970

29942971
#[test]
@@ -3053,8 +3030,7 @@ fn test_copy_through_dangling_symlink_no_dereference() {
30533030
.arg("dangle")
30543031
.arg("d2")
30553032
.succeeds()
3056-
.no_stderr()
3057-
.no_stdout();
3033+
.no_output();
30583034
}
30593035

30603036
#[test]
@@ -3128,8 +3104,7 @@ fn test_copy_through_dangling_symlink_no_dereference_permissions() {
31283104
// V V V V
31293105
ucmd.args(&["-P", "-p", "dangle", "d2"])
31303106
.succeeds()
3131-
.no_stderr()
3132-
.no_stdout();
3107+
.no_output();
31333108
assert!(at.symlink_exists("d2"), "symlink wasn't created");
31343109

31353110
// `-p` means `--preserve=mode,ownership,timestamps`
@@ -3203,8 +3178,7 @@ fn test_cp_fifo() {
32033178
.arg("fifo")
32043179
.arg("fifo2")
32053180
.succeeds()
3206-
.no_stderr()
3207-
.no_stdout();
3181+
.no_output();
32083182
assert!(at.is_fifo("fifo2"));
32093183

32103184
let metadata = std::fs::metadata(at.subdir.join("fifo2")).unwrap();
@@ -3351,8 +3325,7 @@ fn test_cp_socket() {
33513325
.arg("socket")
33523326
.arg("socket2")
33533327
.succeeds()
3354-
.no_stderr()
3355-
.no_stdout();
3328+
.no_output();
33563329

33573330
let metadata = std::fs::metadata(at.subdir.join("socket2")).unwrap();
33583331
let permission = uucore::fs::display_permissions(&metadata, true);
@@ -3411,8 +3384,7 @@ fn test_cp_r_symlink() {
34113384
.arg("tmp")
34123385
.arg("tmp2")
34133386
.succeeds()
3414-
.no_stderr()
3415-
.no_stdout();
3387+
.no_output();
34163388

34173389
// Is symlink2 still a symlink, and does it point at the same place?
34183390
assert!(at.is_symlink("tmp2/symlink"));
@@ -3561,8 +3533,7 @@ fn test_cp_parents_2_dirs() {
35613533
at.mkdir("d");
35623534
ucmd.args(&["-a", "--parents", "a/b/c", "d"])
35633535
.succeeds()
3564-
.no_stderr()
3565-
.no_stdout();
3536+
.no_output();
35663537
assert!(at.dir_exists("d/a/b/c"));
35673538
}
35683539

@@ -3735,8 +3706,7 @@ fn test_remove_destination_symbolic_link_loop() {
37353706
at.touch("f");
37363707
ucmd.args(&["--remove-destination", "f", "loop"])
37373708
.succeeds()
3738-
.no_stdout()
3739-
.no_stderr();
3709+
.no_output();
37403710
assert!(at.file_exists("loop"));
37413711
}
37423712

@@ -3747,10 +3717,7 @@ fn test_cp_symbolic_link_loop() {
37473717
at.symlink_file("loop", "loop");
37483718
at.plus("loop");
37493719
at.touch("f");
3750-
ucmd.args(&["-f", "f", "loop"])
3751-
.succeeds()
3752-
.no_stdout()
3753-
.no_stderr();
3720+
ucmd.args(&["-f", "f", "loop"]).succeeds().no_output();
37543721
assert!(at.file_exists("loop"));
37553722
}
37563723

@@ -3799,10 +3766,7 @@ fn test_copy_dir_preserve_permissions() {
37993766
// | | | to this destination
38003767
// | | | |
38013768
// V V V V
3802-
ucmd.args(&["-p", "-R", "d1", "d2"])
3803-
.succeeds()
3804-
.no_stderr()
3805-
.no_stdout();
3769+
ucmd.args(&["-p", "-R", "d1", "d2"]).succeeds().no_output();
38063770
assert!(at.dir_exists("d2"));
38073771

38083772
// Assert that the permissions are preserved.
@@ -3822,10 +3786,7 @@ fn test_copy_dir_preserve_subdir_permissions() {
38223786
at.set_mode("a1/a2", 0o0555);
38233787
at.set_mode("a1", 0o0777);
38243788

3825-
ucmd.args(&["-p", "-r", "a1", "b1"])
3826-
.succeeds()
3827-
.no_stderr()
3828-
.no_stdout();
3789+
ucmd.args(&["-p", "-r", "a1", "b1"]).succeeds().no_output();
38293790

38303791
// Make sure everything is preserved
38313792
assert!(at.dir_exists("b1"));
@@ -3847,8 +3808,7 @@ fn test_copy_dir_preserve_readonly_source_with_files() {
38473808

38483809
ucmd.args(&["-p", "-r", "src", "dest"])
38493810
.succeeds()
3850-
.no_stderr()
3851-
.no_stdout();
3811+
.no_output();
38523812

38533813
assert!(at.dir_exists("dest"));
38543814
assert_eq!(at.read("dest/file.txt"), "hello");
@@ -3920,8 +3880,7 @@ fn test_same_file_force_backup() {
39203880
at.touch("f");
39213881
ucmd.args(&["--force", "--backup", "f", "f"])
39223882
.succeeds()
3923-
.no_stdout()
3924-
.no_stderr();
3883+
.no_output();
39253884
assert!(at.file_exists("f~"));
39263885
}
39273886

@@ -3947,7 +3906,7 @@ fn test_copy_contents_fifo() {
39473906
// At this point the child process should have terminated
39483907
// successfully with no output. The `outfile` should have the
39493908
// contents of `fifo` copied into it.
3950-
child.wait().unwrap().no_stdout().no_stderr().success();
3909+
child.wait().unwrap().no_output().success();
39513910
assert_eq!(at.read("outfile"), "foo");
39523911
}
39533912

@@ -3968,8 +3927,7 @@ fn test_reflink_never_sparse_always() {
39683927

39693928
ucmd.args(&["--reflink=never", "--sparse=always", "src", "dest"])
39703929
.succeeds()
3971-
.no_stdout()
3972-
.no_stderr();
3930+
.no_output();
39733931
at.file_exists("dest");
39743932

39753933
let src_metadata = std::fs::metadata(at.plus("src")).unwrap();
@@ -4046,8 +4004,7 @@ fn test_src_base_dot() {
40464004
.current_dir(at.plus("y"))
40474005
.args(&["--verbose", "-r", "../x/.", "."])
40484006
.succeeds()
4049-
.no_stderr()
4050-
.no_stdout();
4007+
.no_output();
40514008
assert!(!at.dir_exists("y/x"));
40524009
}
40534010

@@ -4065,10 +4022,7 @@ fn test_non_utf8_src() {
40654022
let (at, mut ucmd) = at_and_ucmd!();
40664023
let src = non_utf8_name("src");
40674024
std::fs::File::create(at.plus(&src)).unwrap();
4068-
ucmd.args(&[src, "dest".into()])
4069-
.succeeds()
4070-
.no_stderr()
4071-
.no_stdout();
4025+
ucmd.args(&[src, "dest".into()]).succeeds().no_output();
40724026
assert!(at.file_exists("dest"));
40734027
}
40744028

@@ -4079,8 +4033,7 @@ fn test_non_utf8_dest() {
40794033
let dest = non_utf8_name("dest");
40804034
ucmd.args(&[TEST_HELLO_WORLD_SOURCE.as_ref(), &*dest])
40814035
.succeeds()
4082-
.no_stderr()
4083-
.no_stdout();
4036+
.no_output();
40844037
assert!(at.file_exists(dest));
40854038
}
40864039

@@ -4092,8 +4045,7 @@ fn test_non_utf8_target() {
40924045
at.mkdir(&dest);
40934046
ucmd.args(&["-t".as_ref(), &*dest, TEST_HELLO_WORLD_SOURCE.as_ref()])
40944047
.succeeds()
4095-
.no_stderr()
4096-
.no_stdout();
4048+
.no_output();
40974049
let mut copied_file = PathBuf::from(dest);
40984050
copied_file.push(TEST_HELLO_WORLD_SOURCE);
40994051
assert!(at.file_exists(copied_file));

tests/by-util/test_csplit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,7 @@ fn test_skip_to_no_match5() {
931931
let (at, mut ucmd) = at_and_ucmd!();
932932
ucmd.args(&["numbers50.txt", "%nope%", "{*}"])
933933
.succeeds()
934-
.no_stderr()
935-
.no_stdout();
934+
.no_output();
936935

937936
let count = glob(&at.plus_as_string("xx*"))
938937
.expect("counting splits")

0 commit comments

Comments
 (0)