watch: handle WATCH_INTERVAL

This commit is contained in:
Etienne Wodey
2025-03-23 22:02:35 +01:00
parent b74e85a147
commit 20d7f2907b
2 changed files with 24 additions and 0 deletions
+1
View File
@@ -118,6 +118,7 @@ pub fn uu_app() -> Command {
.long("interval")
.help("Seconds to wait between updates")
.default_value("2")
.env("WATCH_INTERVAL")
.value_name("SECONDS"),
)
.arg(
+23
View File
@@ -14,6 +14,12 @@ const TRUE_CMD: &str = "%SYSTEMROOT%\\System32\\rundll32.exe";
#[cfg(not(windows))]
const TRUE_CMD: &str = "true";
#[cfg(windows)]
const ECHO_HELLO_CMD: &str = "echo | set /p dummyName=hello";
#[cfg(not(windows))]
const ECHO_HELLO_CMD: &str = "printf hello";
#[test]
fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
@@ -62,3 +68,20 @@ fn test_valid_interval_comma() {
.no_stderr()
.no_stdout();
}
#[test]
fn test_interval_environment_variable() {
let mut p = new_ucmd!()
.arg(ECHO_HELLO_CMD)
.env("WATCH_INTERVAL", "0.3")
.run_no_wait();
// With 0.5 seconds runtime, the watched command is called twice if
// `WATCH_INTERVAL` (0.3 seconds) is taken into account, but only once if the default
// interval (2 seconds) is used.
p.make_assertion_with_delay(500).is_alive();
p.kill()
.make_assertion()
.with_all_output()
.no_stderr()
.stdout_is_bytes(b"hellohello");
}