Skip to content

Commit 80327e0

Browse files
authored
Merge pull request #8602 from cakebaker/touch_simplify_some_tests
touch: simplify some tests by using `new_ucmd!()`
2 parents d71ab03 + 086795d commit 80327e0

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

tests/by-util/test_touch.rs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,11 @@ fn test_touch_set_only_atime() {
286286

287287
#[test]
288288
fn test_touch_set_only_mtime_failed() {
289-
let (_at, mut ucmd) = at_and_ucmd!();
290289
let file = "test_touch_set_only_mtime";
291290

292-
ucmd.args(&["-t", "2015010112342", "-m", file]).fails();
291+
new_ucmd!()
292+
.args(&["-t", "2015010112342", "-m", file])
293+
.fails();
293294
}
294295

295296
#[test]
@@ -351,17 +352,17 @@ fn test_touch_set_both_offset_date_and_reference() {
351352

352353
#[test]
353354
fn test_touch_set_both_time_and_date() {
354-
let (_at, mut ucmd) = at_and_ucmd!();
355355
let file = "test_touch_set_both_time_and_date";
356356

357-
ucmd.args(&[
358-
"-t",
359-
"2015010112342",
360-
"-d",
361-
"Thu Jan 01 12:34:00 2015",
362-
file,
363-
])
364-
.fails();
357+
new_ucmd!()
358+
.args(&[
359+
"-t",
360+
"2015010112342",
361+
"-d",
362+
"Thu Jan 01 12:34:00 2015",
363+
file,
364+
])
365+
.fails();
365366
}
366367

367368
#[test]
@@ -699,10 +700,10 @@ fn test_touch_set_date_relative_smoke() {
699700

700701
#[test]
701702
fn test_touch_set_date_wrong_format() {
702-
let (_at, mut ucmd) = at_and_ucmd!();
703703
let file = "test_touch_set_date_wrong_format";
704704

705-
ucmd.args(&["-d", "2005-43-21", file])
705+
new_ucmd!()
706+
.args(&["-d", "2005-43-21", file])
706707
.fails()
707708
.stderr_contains("Unable to parse date: 2005-43-21");
708709
}
@@ -726,7 +727,6 @@ fn test_touch_mtime_dst_succeeds() {
726727
#[test]
727728
#[cfg(unix)]
728729
fn test_touch_mtime_dst_fails() {
729-
let (_at, mut ucmd) = at_and_ucmd!();
730730
let file = "test_touch_set_mtime_dst_fails";
731731

732732
// Some timezones use daylight savings time, this leads to problems if the
@@ -735,37 +735,37 @@ fn test_touch_mtime_dst_fails() {
735735
// invalid.
736736
// See https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
737737
// for information on the TZ variable, which where the string is copied from.
738-
ucmd.env("TZ", "EST+5EDT,M3.2.0/2,M11.1.0/2")
738+
new_ucmd!()
739+
.env("TZ", "EST+5EDT,M3.2.0/2,M11.1.0/2")
739740
.args(&["-m", "-t", "202003080200", file])
740741
.fails();
741742
}
742743

743744
#[test]
744745
#[cfg(unix)]
745746
fn test_touch_system_fails() {
746-
let (_at, mut ucmd) = at_and_ucmd!();
747747
let file = "/";
748-
ucmd.args(&[file])
748+
new_ucmd!()
749+
.args(&[file])
749750
.fails()
750751
.stderr_contains("setting times of '/'");
751752
}
752753

753754
#[test]
754755
#[cfg(not(target_os = "windows"))]
755756
fn test_touch_trailing_slash() {
756-
let (_at, mut ucmd) = at_and_ucmd!();
757757
let file = "no-file/";
758-
ucmd.args(&[file]).fails().stderr_only(format!(
758+
new_ucmd!().args(&[file]).fails().stderr_only(format!(
759759
"touch: cannot touch '{file}': No such file or directory\n"
760760
));
761761
}
762762

763763
#[test]
764764
#[cfg(target_os = "windows")]
765765
fn test_touch_trailing_slash_windows() {
766-
let (_at, mut ucmd) = at_and_ucmd!();
767766
let file = "no-file/";
768-
ucmd.args(&[file])
767+
new_ucmd!()
768+
.args(&[file])
769769
.fails()
770770
.stderr_contains(format!("touch: cannot touch '{file}'"));
771771
}
@@ -927,17 +927,15 @@ fn test_touch_no_dereference_dangling() {
927927
#[test]
928928
#[cfg(not(target_os = "openbsd"))]
929929
fn test_touch_dash() {
930-
let (_, mut ucmd) = at_and_ucmd!();
931-
932-
ucmd.args(&["-h", "-"]).succeeds().no_stderr().no_stdout();
930+
new_ucmd!().args(&["-h", "-"]).succeeds().no_output();
933931
}
934932

935933
#[test]
936934
fn test_touch_invalid_date_format() {
937-
let (_at, mut ucmd) = at_and_ucmd!();
938935
let file = "test_touch_invalid_date_format";
939936

940-
ucmd.args(&["-m", "-t", "+1000000000000 years", file])
937+
new_ucmd!()
938+
.args(&["-m", "-t", "+1000000000000 years", file])
941939
.fails()
942940
.stderr_contains("touch: invalid date format '+1000000000000 years'");
943941
}

0 commit comments

Comments
 (0)