Skip to content

Commit a592ac3

Browse files
authored
Merge pull request #363 from airwoodix/watch-env-interval
watch: handle WATCH_INTERVAL
2 parents b74e85a + 20d7f29 commit a592ac3

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ const TRUE_CMD: &str = "%SYSTEMROOT%\\System32\\rundll32.exe";
1414
#[cfg(not(windows))]
1515
const TRUE_CMD: &str = "true";
1616

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

0 commit comments

Comments
 (0)