Skip to content

Commit d8d3eaa

Browse files
committed
watch: handle WATCH_INTERVAL
1 parent dd470f4 commit d8d3eaa

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/uu/watch/src/watch.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub fn uu_app() -> Command {
118118
.long("interval")
119119
.help("Seconds to wait between updates")
120120
.default_value("2")
121+
.env("WATCH_INTERVAL")
121122
.value_name("SECONDS"),
122123
)
123124
.arg(

tests/by-util/test_watch.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ const TRUE_CMD: &str = "%SYSTEMROOT%\\System32\\rundll32.exe";
1414
#[cfg(not(windows))]
1515
const TRUE_CMD: &str = "true";
1616

17+
18+
#[cfg(windows)]
19+
const ECHO_HELLO_CMD: &str = "echo | set /p dummyName=hello";
20+
21+
#[cfg(not(windows))]
22+
const ECHO_HELLO_CMD: &str = "echo -n hello";
23+
1724
#[test]
1825
fn test_invalid_arg() {
1926
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
@@ -62,3 +69,13 @@ fn test_valid_interval_comma() {
6269
.no_stderr()
6370
.no_stdout();
6471
}
72+
73+
#[test]
74+
fn test_interval_environment_variable() {
75+
let mut p = new_ucmd!().arg(ECHO_HELLO_CMD).env("WATCH_INTERVAL", "0.3").run_no_wait();
76+
// With 0.5 seconds runtime, the watched command is called twice if
77+
// `WATCH_INTERVAL` (0.3 seconds) is taken into account, but only once if the default
78+
// interval (2 seconds) is used.
79+
p.make_assertion_with_delay(500).is_alive();
80+
p.kill().make_assertion().with_all_output().no_stderr().stdout_is_bytes(b"hellohello");
81+
}

0 commit comments

Comments
 (0)