Skip to content

Commit c6ec491

Browse files
committed
sleep: fix test for windows
1 parent d869673 commit c6ec491

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

tests/by-util/test_sleep.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,21 +238,36 @@ fn test_sleep_when_input_has_whitespace_then_no_error(#[case] input: &str) {
238238
.no_output();
239239
}
240240

241+
#[cfg(not(windows))]
241242
#[rstest]
242-
#[case::only_space(" ")]
243-
#[case::only_tab("\t")]
244-
#[case::only_newline("\n")]
245-
fn test_sleep_when_input_has_only_whitespace_then_error(#[case] input: &str) {
243+
#[case::only_space(" ", "' '")]
244+
#[case::only_tab("\t", "$'\\t'")]
245+
#[case::only_newline("\n", "$'\\n'")]
246+
fn test_sleep_when_input_has_only_whitespace_then_error(
247+
#[case] input: &str,
248+
#[case] expected: &str,
249+
) {
246250
new_ucmd!()
247251
.arg(input)
248252
.timeout(Duration::from_secs(10))
249253
.fails()
250-
.usage_error(match input {
251-
" " => "invalid time interval ' '",
252-
"\t" => "invalid time interval $'\\t'",
253-
"\n" => "invalid time interval $'\\n'",
254-
_ => "",
255-
});
254+
.usage_error(format!("invalid time interval {expected}"));
255+
}
256+
257+
#[cfg(windows)]
258+
#[rstest]
259+
#[case::only_space(" ", "' '")]
260+
#[case::only_tab("\t", "$'`t'")]
261+
#[case::only_newline("\n", "$'`n'")]
262+
fn test_sleep_when_input_has_only_whitespace_then_error(
263+
#[case] input: &str,
264+
#[case] expected: &str,
265+
) {
266+
new_ucmd!()
267+
.arg(input)
268+
.timeout(Duration::from_secs(10))
269+
.fails()
270+
.usage_error(format!("invalid time interval {expected}"));
256271
}
257272

258273
#[test]

0 commit comments

Comments
 (0)