mod common;
use common::{
count_occurrences, mds_bin, record_run_flag, spawn_watch_ready, wait_for_tap, write_atomic,
ChildGuard, RunFlag, StderrTap, ORDER_MARKER_LINE, ORDER_MARKER_SOURCE,
};
use std::fs::File;
use std::io::Write as _;
use std::path::Path;
use std::process::{Command, Stdio};
use std::time::{Duration, Instant};
const TRUNCATE_HOLD: Duration = Duration::from_millis(500);
const EMPTY_HOLD_DEADLINE: Duration = Duration::from_secs(1);
const TIMEOUT: Duration = Duration::from_secs(2);
const OUTPUT_POLL: Duration = Duration::from_millis(5);
const REPEAT_EVERY: Duration = Duration::from_millis(100);
const REPEAT_ROUNDS: u32 = 50;
const MAX_STATES: usize = 32;
const EMPTY_OUTPUT_NOTICE: &str = "Wrote an empty output:";
fn spawn_ready(cmd: &mut Command) -> (ChildGuard, StderrTap) {
let (child, tap, stdout_tap) = spawn_watch_ready(cmd);
assert!(stdout_tap.is_none(), "these tests never pipe stdout");
(ChildGuard(child), tap)
}
#[derive(Default)]
struct OutputLog {
states: Vec<(String, Instant)>,
first_empty: Option<Instant>,
}
impl OutputLog {
fn record(&mut self, path: &Path) -> Option<String> {
let content = std::fs::read_to_string(path).ok()?;
let now = Instant::now();
if content.is_empty() && self.first_empty.is_none() {
self.first_empty = Some(now);
}
let changed = self.states.last().is_none_or(|(last, _)| *last != content);
if changed && self.states.len() < MAX_STATES {
self.states.push((content.clone(), now));
}
Some(content)
}
fn first_holding(&self, needle: &str) -> Option<Instant> {
self.states
.iter()
.find(|(content, _)| content.contains(needle))
.map(|&(_, at)| at)
}
fn contents(&self) -> Vec<&str> {
self.states.iter().map(|(c, _)| c.as_str()).collect()
}
fn poll_for(&mut self, path: &Path, span: Duration) {
let until = Instant::now() + span;
while Instant::now() < until {
self.record(path);
std::thread::sleep(OUTPUT_POLL);
}
}
#[track_caller]
fn wait_for(&mut self, path: &Path, needle: &str, timeout: Duration) {
let deadline = Instant::now() + timeout;
loop {
if self.record(path).is_some_and(|c| c.contains(needle)) {
return;
}
assert!(
Instant::now() < deadline,
"{}: {} never held {needle:?} within {timeout:?}; states read: {:?}",
std::panic::Location::caller(),
path.display(),
self.contents()
);
std::thread::sleep(OUTPUT_POLL);
}
}
}
struct Hold {
file: File,
started: Instant,
}
#[derive(Clone, Copy)]
struct HoldTiming {
started: Instant,
written: Instant,
}
impl Hold {
fn start(path: &Path) -> Hold {
let started = Instant::now();
let file = File::create(path)
.unwrap_or_else(|e| panic!("cannot truncate {}: {e}", path.display()));
Hold { file, started }
}
fn write_and_close(mut self, content: &str) -> HoldTiming {
self.file
.write_all(content.as_bytes())
.expect("write through the held handle");
let written = Instant::now();
drop(self.file);
HoldTiming {
started: self.started,
written,
}
}
}
impl HoldTiming {
fn ended_before_deadline(&self) -> bool {
self.written.duration_since(self.started) < EMPTY_HOLD_DEADLINE
}
fn held(&self) -> Duration {
self.written.duration_since(self.started)
}
}
#[track_caller]
fn assert_no_empty_before_the_deadline(log: &OutputLog, started: Instant, what: &str) {
if let Some(empty_at) = log.first_empty {
let after = empty_at.duration_since(started);
assert!(
after >= EMPTY_HOLD_DEADLINE,
"{what}: an empty output was published {after:?} after the truncation, before \
the {EMPTY_HOLD_DEADLINE:?} deadline could have passed; states read: {:?}",
log.contents()
);
}
}
fn strict_claims_apply(test: &str, timing: &HoldTiming, what: &str) -> bool {
flag_strict_claims(
test,
timing.ended_before_deadline(),
&format!("{what}: {}", hold_against_the_deadline(timing)),
)
}
fn hold_against_the_deadline(timing: &HoldTiming) -> String {
format!(
"hold {:?} vs deadline {EMPTY_HOLD_DEADLINE:?}",
timing.held()
)
}
fn flag_strict_claims(test: &str, strict: bool, details: &str) -> bool {
let (flag, judged) = if strict {
(RunFlag::Conclusive, "strict claims judged")
} else {
(RunFlag::Inconclusive, "only the deadline claim judged")
};
record_run_flag(test, flag, &format!("{details}; {judged}"));
strict
}
#[track_caller]
fn stderr_through_the_marker(src: &Path, tap: StderrTap, child: &mut ChildGuard) -> String {
std::fs::write(src, ORDER_MARKER_SOURCE).expect("write the order marker in place");
wait_for_tap(&tap, ORDER_MARKER_LINE, TIMEOUT);
tap.finish_text(child)
}
fn before_the_marker(stderr: &str) -> &str {
let at = stderr
.find(ORDER_MARKER_LINE)
.expect("the order marker's diagnostic is on stderr");
let head = &stderr[..at];
head.rfind("mds::").map_or(head, |code| &head[..code])
}
#[track_caller]
fn assert_holding_printed_nothing(stderr: &str, rebuilds: usize, what: &str) {
let before = before_the_marker(stderr);
assert_eq!(
count_occurrences(before, "mds::"),
0,
"{what}: no diagnostic may be printed while the file is held empty; \
stderr:\n{stderr}"
);
let lines: Vec<&str> = before.lines().filter(|l| !l.trim().is_empty()).collect();
let unexpected: Vec<&&str> = lines
.iter()
.filter(|l| {
!(l.starts_with("Watching ")
|| l.starts_with("Compiled to ")
|| l.starts_with("Recompiled "))
})
.collect();
assert!(
unexpected.is_empty(),
"{what}: holding a rebuild prints nothing; unexpected lines {unexpected:?}; \
stderr:\n{stderr}"
);
assert_eq!(
lines
.iter()
.filter(|l| l.starts_with("Recompiled "))
.count(),
rebuilds,
"{what}: exactly {rebuilds} rebuild(s) for the content finally written; \
stderr:\n{stderr}"
);
}
fn held_truncate_of_the_entry(test: &str, extra: &[&str], what: &str) {
let dir = tempfile::tempdir().unwrap();
let src = dir.path().join("t.mds");
std::fs::write(&src, "version 1\n").unwrap();
let out = dir.path().join("t.md");
let (mut child, tap) = spawn_ready(
mds_bin()
.arg("watch")
.arg(&src)
.args(extra)
.stdout(Stdio::null()),
);
let mut log = OutputLog::default();
log.wait_for(&out, "version 1", TIMEOUT);
let hold = Hold::start(&src);
log.poll_for(&out, TRUNCATE_HOLD);
let timing = hold.write_and_close("version 2\n");
log.wait_for(&out, "version 2", TIMEOUT);
log.poll_for(&out, TRUNCATE_HOLD);
let stderr = stderr_through_the_marker(&src, tap, &mut child);
assert_no_empty_before_the_deadline(&log, timing.started, what);
assert_eq!(
std::fs::read_to_string(&out).unwrap(),
"version 2\n",
"{what}: the output holds the content finally written"
);
if strict_claims_apply(test, &timing, what) {
assert!(
log.first_empty.is_none(),
"{what}: the output must never be empty while the entry is held truncated; \
states read: {:?}; stderr:\n{stderr}",
log.contents()
);
assert_holding_printed_nothing(&stderr, 1, what);
}
}
#[test]
fn held_truncate_of_the_entry_at_debounce_0_never_publishes_an_empty_output() {
held_truncate_of_the_entry(
"held_truncate_of_the_entry_at_debounce_0_never_publishes_an_empty_output",
&["--debounce", "0"],
"--debounce 0",
);
}
#[test]
fn held_truncate_of_the_entry_at_the_default_debounce_never_publishes_an_empty_output() {
held_truncate_of_the_entry(
"held_truncate_of_the_entry_at_the_default_debounce_never_publishes_an_empty_output",
&[],
"default debounce",
);
}
#[test]
fn held_truncate_of_the_entry_with_poll_interval_0_never_publishes_an_empty_output() {
held_truncate_of_the_entry(
"held_truncate_of_the_entry_with_poll_interval_0_never_publishes_an_empty_output",
&["--debounce", "0", "--poll-interval", "0"],
"--debounce 0 --poll-interval 0",
);
}
struct DependencyCase<'a> {
test: &'a str,
what: &'a str,
watched: &'a Path,
source: &'a Path,
output: &'a Path,
dependency: &'a Path,
rewrite: &'a str,
extra: &'a [&'a str],
before: &'a str,
after: &'a str,
}
fn held_truncate_of_a_dependency(case: &DependencyCase<'_>) {
let what = case.what;
let out = case.output;
let (mut child, tap) = spawn_ready(
mds_bin()
.arg("watch")
.arg(case.watched)
.args(case.extra)
.args(["--debounce", "0"])
.stdout(Stdio::null()),
);
let mut log = OutputLog::default();
log.wait_for(out, case.before, TIMEOUT);
let hold = Hold::start(case.dependency);
log.poll_for(out, TRUNCATE_HOLD);
let timing = hold.write_and_close(case.rewrite);
log.wait_for(out, case.after, TIMEOUT);
let stderr = stderr_through_the_marker(case.source, tap, &mut child);
assert_no_empty_before_the_deadline(&log, timing.started, what);
if strict_claims_apply(case.test, &timing, what) {
assert_eq!(
log.states.len(),
2,
"{what}: the output changes once, from the old content straight to the new; \
states read: {:?}",
log.contents()
);
assert_holding_printed_nothing(&stderr, 1, what);
}
}
#[test]
fn held_truncate_of_an_imported_partial_triggers_nothing_until_written() {
let dir = tempfile::tempdir().unwrap();
let partial = dir.path().join("_p.mds");
std::fs::write(
&partial,
"@define val():\nPartial one\n@end\n\n@export val\n",
)
.unwrap();
let entry = dir.path().join("t.mds");
std::fs::write(&entry, "@import \"./_p.mds\" as p\n{{p.val()}}\n").unwrap();
held_truncate_of_a_dependency(&DependencyCase {
test: "held_truncate_of_an_imported_partial_triggers_nothing_until_written",
what: "an imported partial",
watched: &entry,
source: &entry,
output: &dir.path().join("t.md"),
dependency: &partial,
rewrite: "@define val():\nPartial two\n@end\n\n@export val\n",
extra: &[],
before: "Partial one",
after: "Partial two",
});
}
#[test]
fn held_truncate_of_the_vars_file_triggers_nothing_until_written() {
let dir = tempfile::tempdir().unwrap();
let vars = dir.path().join("vars.json");
std::fs::write(&vars, r#"{"v": "one"}"#).unwrap();
let entry = dir.path().join("t.mds");
std::fs::write(&entry, "Vars {{v}}\n").unwrap();
held_truncate_of_a_dependency(&DependencyCase {
test: "held_truncate_of_the_vars_file_triggers_nothing_until_written",
what: "the vars file",
watched: &entry,
source: &entry,
output: &dir.path().join("t.md"),
dependency: &vars,
rewrite: r#"{"v": "two"}"#,
extra: &["--vars", vars.to_str().unwrap()],
before: "Vars one",
after: "Vars two",
});
}
#[test]
fn dir_mode_held_truncate_of_the_vars_file_triggers_nothing_until_written() {
let dir = tempfile::tempdir().unwrap();
let vars = dir.path().join("vars.json");
std::fs::write(&vars, r#"{"v": "one"}"#).unwrap();
let root = dir.path().join("src");
std::fs::create_dir(&root).unwrap();
let source = root.join("t.mds");
std::fs::write(&source, "Vars {{v}}\n").unwrap();
let out = dir.path().join("out");
held_truncate_of_a_dependency(&DependencyCase {
test: "dir_mode_held_truncate_of_the_vars_file_triggers_nothing_until_written",
what: "directory mode, the vars file",
watched: &root,
source: &source,
output: &out.join("t.md"),
dependency: &vars,
rewrite: r#"{"v": "two"}"#,
extra: &[
"--out-dir",
out.to_str().unwrap(),
"--vars",
vars.to_str().unwrap(),
],
before: "Vars one",
after: "Vars two",
});
}
#[cfg(debug_assertions)]
fn held_truncate_after_the_look(case: &DependencyCase<'_>) {
held_truncate_in_a_pause(case, case.source, "MDS_TEST_PAUSE_AFTER_LOOK");
}
#[cfg(debug_assertions)]
fn held_truncate_in_a_pause(case: &DependencyCase<'_>, saved: &Path, pause: &str) {
let what = case.what;
let out = case.output;
let gate = tempfile::tempdir().unwrap();
let (go, paused) = (gate.path().join("go"), gate.path().join("go.paused"));
let (mut child, tap) = spawn_ready(
mds_bin()
.arg("watch")
.arg(case.watched)
.args(case.extra)
.args(["--debounce", "0", "--poll-interval", "0"])
.env(pause, &go)
.stdout(Stdio::null()),
);
let mut log = OutputLog::default();
log.wait_for(out, case.before, TIMEOUT);
let content = std::fs::read_to_string(saved).unwrap();
write_atomic(saved, &content);
let paused_by = Instant::now() + TIMEOUT;
while !paused.exists() {
assert!(
Instant::now() < paused_by,
"{what}: setup: no rebuild paused after its look; stderr: {}",
tap.text()
);
std::thread::sleep(OUTPUT_POLL);
}
let hold = Hold::start(case.dependency);
std::fs::write(&go, "").unwrap();
log.poll_for(out, TRUNCATE_HOLD);
let timing = hold.write_and_close(case.rewrite);
log.wait_for(out, case.after, TIMEOUT);
let stderr = stderr_through_the_marker(case.source, tap, &mut child);
assert_no_empty_before_the_deadline(&log, timing.started, what);
if strict_claims_apply(case.test, &timing, what) {
assert_eq!(
log.states.len(),
2,
"{what}: the output changes once, from the old content straight to the new; \
states read: {:?}",
log.contents()
);
assert_holding_printed_nothing(&stderr, 1, what);
}
}
#[cfg(debug_assertions)]
#[test]
fn an_imported_partial_truncated_after_the_look_triggers_nothing_until_written() {
let dir = tempfile::tempdir().unwrap();
let partial = dir.path().join("_p.mds");
std::fs::write(
&partial,
"@define val():\nPartial one\n@end\n\n@export val\n",
)
.unwrap();
let entry = dir.path().join("t.mds");
std::fs::write(&entry, "@import \"./_p.mds\" as p\n{{p.val()}}\n").unwrap();
held_truncate_after_the_look(&DependencyCase {
test: "an_imported_partial_truncated_after_the_look_triggers_nothing_until_written",
what: "an imported partial, truncated after the look",
watched: &entry,
source: &entry,
output: &dir.path().join("t.md"),
dependency: &partial,
rewrite: "@define val():\nPartial two\n@end\n\n@export val\n",
extra: &[],
before: "Partial one",
after: "Partial two",
});
}
#[cfg(debug_assertions)]
#[test]
fn the_vars_file_truncated_after_the_look_triggers_nothing_until_written() {
let dir = tempfile::tempdir().unwrap();
let vars = dir.path().join("vars.json");
std::fs::write(&vars, r#"{"v": "one"}"#).unwrap();
let entry = dir.path().join("t.mds");
std::fs::write(&entry, "Vars {{v}}\n").unwrap();
held_truncate_after_the_look(&DependencyCase {
test: "the_vars_file_truncated_after_the_look_triggers_nothing_until_written",
what: "the vars file, truncated after the look",
watched: &entry,
source: &entry,
output: &dir.path().join("t.md"),
dependency: &vars,
rewrite: r#"{"v": "two"}"#,
extra: &["--vars", vars.to_str().unwrap()],
before: "Vars one",
after: "Vars two",
});
}
#[cfg(debug_assertions)]
#[test]
fn dir_mode_the_vars_file_truncated_after_the_look_triggers_nothing_until_written() {
let dir = tempfile::tempdir().unwrap();
let vars = dir.path().join("vars.json");
std::fs::write(&vars, r#"{"v": "one"}"#).unwrap();
let root = dir.path().join("src");
std::fs::create_dir(&root).unwrap();
let source = root.join("t.mds");
std::fs::write(&source, "Vars {{v}}\n").unwrap();
let out = dir.path().join("out");
held_truncate_after_the_look(&DependencyCase {
test: "dir_mode_the_vars_file_truncated_after_the_look_triggers_nothing_until_written",
what: "directory mode, the vars file, truncated after the look",
watched: &root,
source: &source,
output: &out.join("t.md"),
dependency: &vars,
rewrite: r#"{"v": "two"}"#,
extra: &[
"--out-dir",
out.to_str().unwrap(),
"--vars",
vars.to_str().unwrap(),
],
before: "Vars one",
after: "Vars two",
});
}
#[cfg(debug_assertions)]
#[test]
fn dir_mode_an_imported_partial_truncated_after_the_look_triggers_nothing_until_written() {
let dir = tempfile::tempdir().unwrap();
let root = dir.path().join("src");
std::fs::create_dir(&root).unwrap();
let partial = root.join("_p.mds");
std::fs::write(
&partial,
"@define val():\nPartial one\n@end\n\n@export val\n",
)
.unwrap();
let source = root.join("t.mds");
std::fs::write(&source, "@import \"./_p.mds\" as p\n{{p.val()}}\n").unwrap();
let out = dir.path().join("out");
held_truncate_after_the_look(&DependencyCase {
test:
"dir_mode_an_imported_partial_truncated_after_the_look_triggers_nothing_until_written",
what: "directory mode, an imported partial, truncated after the look",
watched: &root,
source: &source,
output: &out.join("t.md"),
dependency: &partial,
rewrite: "@define val():\nPartial two\n@end\n\n@export val\n",
extra: &["--out-dir", out.to_str().unwrap()],
before: "Partial one",
after: "Partial two",
});
}
#[cfg(debug_assertions)]
#[test]
fn the_entry_truncated_after_its_rebuild_read_it_never_publishes_an_empty_output() {
let dir = tempfile::tempdir().unwrap();
let entry = dir.path().join("t.mds");
std::fs::write(&entry, "Entry one\n").unwrap();
held_truncate_in_a_pause(
&DependencyCase {
test: "the_entry_truncated_after_its_rebuild_read_it_never_publishes_an_empty_output",
what: "the entry, truncated after its rebuild read it",
watched: &entry,
source: &entry,
output: &dir.path().join("t.md"),
dependency: &entry,
rewrite: "Entry two\n",
extra: &[],
before: "Entry one",
after: "Entry two",
},
&entry,
"MDS_TEST_PAUSE_AFTER_READ",
);
}
#[cfg(debug_assertions)]
#[test]
fn the_vars_file_truncated_after_its_rebuild_read_it_triggers_nothing_until_written() {
let dir = tempfile::tempdir().unwrap();
let vars = dir.path().join("vars.json");
std::fs::write(&vars, r#"{"v": "one"}"#).unwrap();
let entry = dir.path().join("t.mds");
std::fs::write(&entry, "Vars {{v}}\n").unwrap();
held_truncate_in_a_pause(
&DependencyCase {
test:
"the_vars_file_truncated_after_its_rebuild_read_it_triggers_nothing_until_written",
what: "the vars file, truncated after its rebuild read it",
watched: &entry,
source: &entry,
output: &dir.path().join("t.md"),
dependency: &vars,
rewrite: r#"{"v": "two"}"#,
extra: &["--vars", vars.to_str().unwrap()],
before: "Vars one",
after: "Vars two",
},
&entry,
"MDS_TEST_PAUSE_AFTER_READ",
);
}
#[cfg(debug_assertions)]
fn a_save_ending_between_the_read_and_the_late_look(case: &DependencyCase<'_>, saved: &Path) {
let what = case.what;
let out = case.output;
let gate = tempfile::tempdir().unwrap();
let (look_go, look_paused) = (gate.path().join("look"), gate.path().join("look.paused"));
let (late_go, late_paused) = (gate.path().join("late"), gate.path().join("late.paused"));
let (mut child, tap) = spawn_ready(
mds_bin()
.arg("watch")
.arg(case.watched)
.args(case.extra)
.args(["--debounce", "0", "--poll-interval", "0"])
.env("MDS_TEST_PAUSE_AFTER_LOOK", &look_go)
.env("MDS_TEST_PAUSE_BEFORE_LATE_LOOK", &late_go)
.stdout(Stdio::null()),
);
let mut log = OutputLog::default();
log.wait_for(out, case.before, TIMEOUT);
let content = std::fs::read_to_string(saved).unwrap();
write_atomic(saved, &content);
wait_for_the_pause(&look_paused, &tap, what);
File::create(case.dependency).expect("truncate the file");
std::fs::write(&look_go, "").unwrap();
wait_for_the_pause(&late_paused, &tap, what);
std::fs::write(case.dependency, case.rewrite).expect("write the file again");
std::fs::write(&late_go, "").unwrap();
log.wait_for(out, case.after, TIMEOUT);
let stderr = stderr_through_the_marker(case.source, tap, &mut child);
assert!(
!log.contents().contains(&""),
"{what}: the empty read is never published; states read: {:?}; stderr:\n{stderr}",
log.contents()
);
assert!(
!before_the_marker(&stderr).contains(EMPTY_OUTPUT_NOTICE),
"{what}: no empty output is written; stderr:\n{stderr}"
);
assert_holding_printed_nothing(&stderr, 1, what);
}
#[cfg(debug_assertions)]
#[test]
fn the_entry_saved_between_its_rebuild_s_read_and_late_look_never_publishes_an_empty_output() {
let dir = tempfile::tempdir().unwrap();
let entry = dir.path().join("t.mds");
std::fs::write(&entry, "Entry one\n").unwrap();
a_save_ending_between_the_read_and_the_late_look(
&DependencyCase {
test: "the_entry_saved_between_its_rebuild_s_read_and_late_look_never_publishes_an_empty_output",
what: "the entry, saved between its rebuild's read and late look",
watched: &entry,
source: &entry,
output: &dir.path().join("t.md"),
dependency: &entry,
rewrite: "Entry two\n",
extra: &[],
before: "Entry one",
after: "Entry two",
},
&entry,
);
}
#[cfg(debug_assertions)]
#[test]
fn the_vars_file_saved_between_its_rebuild_s_read_and_late_look_reports_nothing() {
let dir = tempfile::tempdir().unwrap();
let vars = dir.path().join("vars.json");
std::fs::write(&vars, r#"{"v": "one"}"#).unwrap();
let entry = dir.path().join("t.mds");
std::fs::write(&entry, "Vars {{v}}\n").unwrap();
a_save_ending_between_the_read_and_the_late_look(
&DependencyCase {
test: "the_vars_file_saved_between_its_rebuild_s_read_and_late_look_reports_nothing",
what: "the vars file, saved between its rebuild's read and late look",
watched: &entry,
source: &entry,
output: &dir.path().join("t.md"),
dependency: &vars,
rewrite: r#"{"v": "two"}"#,
extra: &["--vars", vars.to_str().unwrap()],
before: "Vars one",
after: "Vars two",
},
&entry,
);
}
#[cfg(debug_assertions)]
#[test]
fn dir_mode_a_source_saved_between_its_batch_s_read_and_late_look_never_publishes_an_empty_output()
{
let dir = tempfile::tempdir().unwrap();
let root = dir.path().join("src");
std::fs::create_dir(&root).unwrap();
let source = root.join("t.mds");
std::fs::write(&source, "Source one\n").unwrap();
let out = dir.path().join("out");
a_save_ending_between_the_read_and_the_late_look(
&DependencyCase {
test: "dir_mode_a_source_saved_between_its_batch_s_read_and_late_look_never_publishes_an_empty_output",
what: "directory mode, a source saved between its batch's read and late look",
watched: &root,
source: &source,
output: &out.join("t.md"),
dependency: &source,
rewrite: "Source two\n",
extra: &["--out-dir", out.to_str().unwrap()],
before: "Source one",
after: "Source two",
},
&source,
);
}
#[cfg(debug_assertions)]
#[test]
fn dir_mode_the_vars_file_truncated_after_its_batch_read_it_triggers_nothing_until_written() {
let dir = tempfile::tempdir().unwrap();
let vars = dir.path().join("vars.json");
std::fs::write(&vars, r#"{"v": "one"}"#).unwrap();
let root = dir.path().join("src");
std::fs::create_dir(&root).unwrap();
let source = root.join("t.mds");
std::fs::write(&source, "Vars {{v}}\n").unwrap();
let out = dir.path().join("out");
held_truncate_in_a_pause(
&DependencyCase {
test: "dir_mode_the_vars_file_truncated_after_its_batch_read_it_triggers_nothing_until_written",
what: "directory mode, the vars file, truncated after its batch read it",
watched: &root,
source: &source,
output: &out.join("t.md"),
dependency: &vars,
rewrite: r#"{"v": "two"}"#,
extra: &[
"--out-dir",
out.to_str().unwrap(),
"--vars",
vars.to_str().unwrap(),
],
before: "Vars one",
after: "Vars two",
},
&source,
"MDS_TEST_PAUSE_AFTER_BATCH_SPLIT",
);
}
#[cfg(debug_assertions)]
#[test]
fn dir_mode_a_source_truncated_while_a_batch_rebuilds_another_is_held() {
let dir = tempfile::tempdir().unwrap();
let root = dir.path().join("src");
std::fs::create_dir(&root).unwrap();
let a = root.join("a.mds");
let b = root.join("b.mds");
std::fs::write(&a, "A one\n").unwrap();
std::fs::write(&b, "B one\n").unwrap();
let out = dir.path().join("out");
held_truncate_in_a_pause(
&DependencyCase {
test: "dir_mode_a_source_truncated_while_a_batch_rebuilds_another_is_held",
what: "directory mode, a source truncated while another's batch runs",
watched: &root,
source: &a,
output: &out.join("a.md"),
dependency: &a,
rewrite: "A two\n",
extra: &["--out-dir", out.to_str().unwrap()],
before: "A one",
after: "A two",
},
&b,
"MDS_TEST_PAUSE_AFTER_LOOK",
);
}
#[test]
fn dir_mode_held_truncate_defers_the_whole_batch() {
let dir = tempfile::tempdir().unwrap();
let root = dir.path().join("src");
std::fs::create_dir(&root).unwrap();
let a = root.join("a.mds");
let b = root.join("b.mds");
std::fs::write(&a, "A one\n").unwrap();
std::fs::write(&b, "B one\n").unwrap();
let out = dir.path().join("out");
let (a_out, b_out) = (out.join("a.md"), out.join("b.md"));
let (mut child, tap) = spawn_ready(
mds_bin()
.arg("watch")
.arg(&root)
.arg("--out-dir")
.arg(&out)
.args(["--debounce", "0"])
.stdout(Stdio::null()),
);
let (mut a_log, mut b_log) = (OutputLog::default(), OutputLog::default());
a_log.wait_for(&a_out, "A one", TIMEOUT);
b_log.wait_for(&b_out, "B one", TIMEOUT);
let hold = Hold::start(&a);
let edit_after = TRUNCATE_HOLD / 5;
let edit_at = hold.started + edit_after;
let until = hold.started + TRUNCATE_HOLD;
let mut edited_at: Option<Instant> = None;
while edited_at.is_none() || Instant::now() < until {
if edited_at.is_none() && Instant::now() >= edit_at {
write_atomic(&b, "B two\n");
edited_at = Some(Instant::now());
}
a_log.record(&a_out);
b_log.record(&b_out);
std::thread::sleep(OUTPUT_POLL);
}
let edited_at = edited_at.expect("the loop edits before it ends");
let timing = hold.write_and_close("A two\n");
a_log.wait_for(&a_out, "A two", TIMEOUT);
b_log.wait_for(&b_out, "B two", TIMEOUT);
let stderr = stderr_through_the_marker(&a, tap, &mut child);
let what = "directory mode";
assert_no_empty_before_the_deadline(&a_log, timing.started, what);
let edited = edited_at.duration_since(timing.started);
let strict = timing.ended_before_deadline() && edited < EMPTY_HOLD_DEADLINE;
if flag_strict_claims(
"dir_mode_held_truncate_defers_the_whole_batch",
strict,
&format!(
"{what}: {}, the other source edited {edited:?} into it",
hold_against_the_deadline(&timing)
),
) {
assert!(
a_log.first_empty.is_none(),
"{what}: a.md must never be empty while a.mds is held truncated; states: {:?}",
a_log.contents()
);
let b_published = b_log
.first_holding("B two")
.expect("b.md reached its new content");
assert!(
b_published >= timing.written,
"{what}: the other source's edit must wait for the held one — b.md held \
`B two` {:?} before a.mds was written; stderr:\n{stderr}",
timing.written.duration_since(b_published)
);
assert_holding_printed_nothing(&stderr, 2, what);
}
}
#[test]
fn dir_mode_a_source_created_during_a_hold_is_compiled_with_a_vars_edit() {
let dir = tempfile::tempdir().unwrap();
let vars = dir.path().join("vars.json");
std::fs::write(&vars, r#"{"v": "one"}"#).unwrap();
let root = dir.path().join("src");
std::fs::create_dir(&root).unwrap();
let a = root.join("a.mds");
std::fs::write(&a, "A {{v}}\n").unwrap();
let out = dir.path().join("out");
let (a_out, new_out) = (out.join("a.md"), out.join("new.md"));
let (_child, _tap) = spawn_ready(
mds_bin()
.arg("watch")
.arg(&root)
.arg("--out-dir")
.arg(&out)
.arg("--vars")
.arg(&vars)
.args(["--debounce", "0", "--poll-interval", "0"])
.stdout(Stdio::null()),
);
OutputLog::default().wait_for(&a_out, "A one", TIMEOUT);
std::fs::write(&a, "").unwrap();
std::fs::write(root.join("new.mds"), "New {{v}}\n").unwrap();
write_atomic(&vars, r#"{"v": "two"}"#);
OutputLog::default().wait_for(&new_out, "New two", EMPTY_HOLD_DEADLINE + TIMEOUT);
}
#[cfg(debug_assertions)]
#[test]
fn dir_mode_a_source_truncated_after_its_rebuild_looked_is_held() {
let dir = tempfile::tempdir().unwrap();
let root = dir.path().join("src");
std::fs::create_dir(&root).unwrap();
let a = root.join("a.mds");
std::fs::write(&a, "A one\n").unwrap();
let out = dir.path().join("out");
let a_out = out.join("a.md");
let (go, paused) = (dir.path().join("go"), dir.path().join("go.paused"));
let (mut child, tap) = spawn_ready(
mds_bin()
.arg("watch")
.arg(&root)
.arg("--out-dir")
.arg(&out)
.args(["--debounce", "0", "--poll-interval", "0"])
.env("MDS_TEST_PAUSE_AFTER_BATCH_SPLIT", &go)
.stdout(Stdio::null()),
);
let mut log = OutputLog::default();
log.wait_for(&a_out, "A one", TIMEOUT);
write_atomic(&a, "A two\n");
let paused_by = Instant::now() + TIMEOUT;
while !paused.exists() {
assert!(
Instant::now() < paused_by,
"setup: the rebuild never paused; stderr: {}",
tap.text()
);
std::thread::sleep(OUTPUT_POLL);
}
let hold = Hold::start(&a);
std::fs::write(&go, "").unwrap();
log.poll_for(&a_out, TRUNCATE_HOLD);
let timing = hold.write_and_close("A three\n");
log.wait_for(&a_out, "A three", TIMEOUT);
let stderr = stderr_through_the_marker(&a, tap, &mut child);
let what = "directory mode, truncated after the look";
assert_no_empty_before_the_deadline(&log, timing.started, what);
if strict_claims_apply(
"dir_mode_a_source_truncated_after_its_rebuild_looked_is_held",
&timing,
what,
) {
assert!(
log.first_empty.is_none(),
"{what}: a.md must never be empty while a.mds is held truncated; states: {:?}",
log.contents()
);
assert_holding_printed_nothing(&stderr, 1, what);
}
}
#[cfg(debug_assertions)]
struct NewSourcePaused {
child: ChildGuard,
tap: StderrTap,
source: std::path::PathBuf,
output: std::path::PathBuf,
go: std::path::PathBuf,
_dir: tempfile::TempDir,
}
#[cfg(debug_assertions)]
fn a_new_source_s_batch_stopped_after_its_look(content: &str) -> NewSourcePaused {
let dir = tempfile::tempdir().unwrap();
let root = dir.path().join("src");
std::fs::create_dir(&root).unwrap();
let out = dir.path().join("out");
std::fs::create_dir(&out).unwrap();
let (go, paused) = (dir.path().join("go"), dir.path().join("go.paused"));
let (child, tap) = spawn_ready(
mds_bin()
.arg("watch")
.arg(&root)
.arg("--out-dir")
.arg(&out)
.args(["--debounce", "0", "--poll-interval", "0"])
.env("MDS_TEST_PAUSE_AFTER_LOOK", &go)
.stdout(Stdio::null()),
);
let source = root.join("n.mds");
write_atomic(&source, content);
let paused_by = Instant::now() + TIMEOUT;
while !paused.exists() {
assert!(
Instant::now() < paused_by,
"setup: the new source's batch never paused after its look; stderr: {}",
tap.text()
);
std::thread::sleep(OUTPUT_POLL);
}
NewSourcePaused {
child,
tap,
source,
output: out.join("n.md"),
go,
_dir: dir,
}
}
#[cfg(debug_assertions)]
#[test]
fn dir_mode_a_source_created_and_truncated_after_its_batch_looked_is_held() {
let NewSourcePaused {
mut child,
tap,
source,
output,
go,
_dir,
} = a_new_source_s_batch_stopped_after_its_look("N one\n");
let hold = Hold::start(&source);
std::fs::write(&go, "").unwrap();
let mut log = OutputLog::default();
log.poll_for(&output, TRUNCATE_HOLD);
let timing = hold.write_and_close("N two\n");
log.wait_for(&output, "N two", TIMEOUT);
let stderr = stderr_through_the_marker(&source, tap, &mut child);
let what = "directory mode, a source created and truncated after its batch looked";
assert_no_empty_before_the_deadline(&log, timing.started, what);
if strict_claims_apply(
"dir_mode_a_source_created_and_truncated_after_its_batch_looked_is_held",
&timing,
what,
) {
assert_eq!(
log.contents(),
["N two\n"],
"{what}: the output is published once, with the content finally written; \
stderr:\n{stderr}"
);
assert_holding_printed_nothing(&stderr, 1, what);
}
}
#[cfg(debug_assertions)]
#[test]
fn dir_mode_a_source_created_and_saved_after_its_batch_looked_publishes_the_save() {
let NewSourcePaused {
mut child,
tap,
source,
output,
go,
_dir,
} = a_new_source_s_batch_stopped_after_its_look("N one\n");
write_atomic(&source, "N two, saved after the look\n");
std::fs::write(&go, "").unwrap();
let mut log = OutputLog::default();
log.wait_for(&output, "N two, saved after the look", TIMEOUT);
let stderr = stderr_through_the_marker(&source, tap, &mut child);
let what = "directory mode, a source created and saved after its batch looked";
assert_eq!(
log.contents(),
["N two, saved after the look\n"],
"{what}: the output is published once, with what was saved; stderr:\n{stderr}"
);
assert_holding_printed_nothing(&stderr, 1, what);
}
#[cfg(debug_assertions)]
#[track_caller]
fn wait_for_the_pause(paused: &Path, tap: &StderrTap, step: &str) {
let paused_by = Instant::now() + TIMEOUT;
while !paused.exists() {
assert!(
Instant::now() < paused_by,
"setup: {step}: the batch never paused after its look; stderr: {}",
tap.text()
);
std::thread::sleep(OUTPUT_POLL);
}
}
#[cfg(debug_assertions)]
#[test]
fn dir_mode_a_failing_source_truncated_after_a_batch_for_another_looked_is_held() {
let dir = tempfile::tempdir().unwrap();
let root = dir.path().join("src");
std::fs::create_dir(&root).unwrap();
let out = dir.path().join("out");
std::fs::create_dir(&out).unwrap();
let (go, paused) = (dir.path().join("go"), dir.path().join("go.paused"));
let (mut child, tap) = spawn_ready(
mds_bin()
.arg("watch")
.arg(&root)
.arg("--out-dir")
.arg(&out)
.args(["--debounce", "0", "--poll-interval", "0"])
.env("MDS_TEST_PAUSE_AFTER_LOOK", &go)
.stdout(Stdio::null()),
);
let (failing, flush, other) = (root.join("e.mds"), root.join("f.mds"), root.join("a.mds"));
let output = out.join("e.md");
write_atomic(&failing, "E {{e_undefined}}\n");
wait_for_the_pause(&paused, &tap, "the failing source's batch");
std::fs::write(&go, "").unwrap();
wait_for_tap(&tap, "undefined variable 'e_undefined'", TIMEOUT);
write_atomic(&flush, "F {{f_undefined}}\n");
wait_for_tap(&tap, "undefined variable 'f_undefined'", TIMEOUT);
std::fs::rename(&go, dir.path().join("go.spent")).unwrap();
std::fs::rename(&paused, dir.path().join("go.paused.spent")).unwrap();
write_atomic(&other, "A one\n");
wait_for_the_pause(&paused, &tap, "the batch of a.mds");
let hold = Hold::start(&failing);
std::fs::write(&go, "").unwrap();
let mut log = OutputLog::default();
log.poll_for(&output, TRUNCATE_HOLD);
let timing = hold.write_and_close("E fixed\n");
log.wait_for(&output, "E fixed", TIMEOUT);
let stderr = stderr_through_the_marker(&failing, tap, &mut child);
let what = "directory mode, a failing source truncated after a batch for another looked";
assert_no_empty_before_the_deadline(&log, timing.started, what);
if strict_claims_apply(
"dir_mode_a_failing_source_truncated_after_a_batch_for_another_looked_is_held",
&timing,
what,
) {
assert_eq!(
log.contents(),
["E fixed\n"],
"{what}: the output is published once, with the content finally written; \
stderr:\n{stderr}"
);
let rebuilds = before_the_marker(&stderr)
.lines()
.filter(|line| line.starts_with("Recompiled ") && line.contains("e.md"))
.count();
assert_eq!(
rebuilds, 1,
"{what}: exactly one rebuild of e.md; stderr:\n{stderr}"
);
}
}
#[cfg(debug_assertions)]
#[test]
fn dir_mode_a_dependency_a_held_compile_read_empty_holds_the_batch_its_truncation_starts() {
let base = tempfile::tempdir().unwrap();
let (root, shared) = (base.path().join("root"), base.path().join("shared"));
std::fs::create_dir(&root).unwrap();
std::fs::create_dir(&shared).unwrap();
std::fs::write(base.path().join(".git"), "").unwrap();
std::fs::write(
shared.join("_x.mds"),
"@define greet():\nX one\n@end\n\n@export greet\n",
)
.unwrap();
let page = root.join("page.mds");
std::fs::write(&page, "@import \"../shared/_x.mds\" as x\n{{x.greet()}}\n").unwrap();
let out = base.path().join("out");
let output = out.join("page.md");
let (go, paused) = (base.path().join("go"), base.path().join("go.paused"));
let (mut child, tap) = spawn_ready(
mds_bin()
.arg("watch")
.arg(&root)
.arg("--out-dir")
.arg(&out)
.args(["--debounce", "50", "--poll-interval", "0"])
.env("MDS_TEST_PAUSE_AFTER_LOOK", &go)
.stdout(Stdio::null()),
);
let mut log = OutputLog::default();
log.wait_for(&output, "X one", TIMEOUT);
let missing = shared.join("_y.mds");
write_atomic(&page, "@import \"../shared/_y.mds\" as y\n@include y\n");
wait_for_the_pause(&paused, &tap, "the batch of the page's save");
std::fs::write(&go, "").unwrap();
wait_for_tap(&tap, "_y.mds", TIMEOUT);
std::fs::rename(&go, base.path().join("go.spent")).unwrap();
std::fs::rename(&paused, base.path().join("go.paused.spent")).unwrap();
write_atomic(&missing, "Y one\n");
wait_for_the_pause(&paused, &tap, "the batch of the creation of _y.mds");
let hold = Hold::start(&missing);
std::fs::write(&go, "").unwrap();
log.poll_for(&output, TRUNCATE_HOLD);
let timing = hold.write_and_close("Y two\n");
log.wait_for(&output, "Y two", TIMEOUT);
let stderr = stderr_through_the_marker(&page, tap, &mut child);
let what = "directory mode, a dependency beside the root truncated after its batch looked";
assert_no_empty_before_the_deadline(&log, timing.started, what);
if strict_claims_apply(
"dir_mode_a_dependency_a_held_compile_read_empty_holds_the_batch_its_truncation_starts",
&timing,
what,
) {
assert_eq!(
log.contents(),
["X one\n", "Y two\n"],
"{what}: the output goes from the first import to the content finally written, \
never empty; stderr:\n{stderr}"
);
let before = before_the_marker(&stderr);
assert_eq!(
count_occurrences(before, EMPTY_OUTPUT_NOTICE),
0,
"{what}: no empty output is announced; stderr:\n{stderr}"
);
let rebuilds = before
.lines()
.filter(|line| line.starts_with("Recompiled ") && line.contains("page.md"))
.count();
assert_eq!(
rebuilds, 1,
"{what}: exactly one rebuild of page.md, for the content finally written; \
stderr:\n{stderr}"
);
}
}
#[cfg(debug_assertions)]
#[test]
fn dir_mode_a_dependency_a_failed_held_compile_read_empty_holds_the_batch_its_truncation_starts() {
let base = tempfile::tempdir().unwrap();
let (root, shared) = (base.path().join("root"), base.path().join("shared"));
std::fs::create_dir(&root).unwrap();
std::fs::create_dir(&shared).unwrap();
std::fs::write(base.path().join(".git"), "").unwrap();
std::fs::write(
shared.join("_x.mds"),
"@define greet():\nX one\n@end\n\n@export greet\n",
)
.unwrap();
let page = root.join("page.mds");
std::fs::write(&page, "@import \"../shared/_x.mds\" as x\n{{x.greet()}}\n").unwrap();
let out = base.path().join("out");
let output = out.join("page.md");
let (go, paused) = (base.path().join("go"), base.path().join("go.paused"));
let (mut child, tap) = spawn_ready(
mds_bin()
.arg("watch")
.arg(&root)
.arg("--out-dir")
.arg(&out)
.args(["--debounce", "50", "--poll-interval", "0"])
.env("MDS_TEST_PAUSE_AFTER_LOOK", &go)
.stdout(Stdio::null()),
);
let mut log = OutputLog::default();
log.wait_for(&output, "X one", TIMEOUT);
let missing = shared.join("_y.mds");
write_atomic(&page, "@import \"../shared/_y.mds\" as y\n{{y.greet()}}\n");
wait_for_the_pause(&paused, &tap, "the batch of the page's save");
std::fs::write(&go, "").unwrap();
wait_for_tap(&tap, "_y.mds", TIMEOUT);
std::fs::rename(&go, base.path().join("go.spent")).unwrap();
std::fs::rename(&paused, base.path().join("go.paused.spent")).unwrap();
write_atomic(&missing, "@define greet():\nY one\n@end\n\n@export greet\n");
wait_for_the_pause(&paused, &tap, "the batch of the creation of _y.mds");
let hold = Hold::start(&missing);
std::fs::write(&go, "").unwrap();
log.poll_for(&output, TRUNCATE_HOLD);
let timing = hold.write_and_close("@define greet():\nY two\n@end\n\n@export greet\n");
log.wait_for(&output, "Y two", TIMEOUT);
let stderr = stderr_through_the_marker(&page, tap, &mut child);
let what = "directory mode, a dependency beside the root truncated after its batch looked, \
read empty by a compile that fails on it";
assert_no_empty_before_the_deadline(&log, timing.started, what);
if strict_claims_apply(
"dir_mode_a_dependency_a_failed_held_compile_read_empty_holds_the_batch_its_truncation_starts",
&timing,
what,
) {
assert_eq!(
log.contents(),
["X one\n", "Y two\n"],
"{what}: the output goes from the first import to the content finally written; \
stderr:\n{stderr}"
);
let before = before_the_marker(&stderr);
assert_eq!(
(
count_occurrences(before, "mds::"),
count_occurrences(before, "mds::file_not_found"),
),
(1, 1),
"{what}: only the missing file of the first save is reported, never the failure \
on the empty file; stderr:\n{stderr}"
);
}
}
fn truncate_and_close(extra: &[&str], quiet: bool, what: &str) {
let dir = tempfile::tempdir().unwrap();
let src = dir.path().join("t.mds");
std::fs::write(&src, "version 1\n").unwrap();
let out = dir.path().join("t.md");
let mut cmd = mds_bin();
cmd.arg("watch")
.arg(&src)
.args(["--debounce", "0"])
.args(extra);
if quiet {
cmd.arg("--quiet");
}
let (mut child, tap) = spawn_ready(cmd.stdout(Stdio::null()));
let mut log = OutputLog::default();
log.wait_for(&out, "version 1", TIMEOUT);
let started = Instant::now();
drop(File::create(&src).expect("truncate the entry"));
let bound = EMPTY_HOLD_DEADLINE + TIMEOUT;
let until = started + bound;
while log.first_empty.is_none() && Instant::now() < until {
log.record(&out);
std::thread::sleep(OUTPUT_POLL);
}
let empty_at = log.first_empty.unwrap_or_else(|| {
panic!(
"{what}: an emptied entry must be published within {bound:?}; states read: {:?}",
log.contents()
)
});
let stderr = stderr_through_the_marker(&src, tap, &mut child);
let notices = if quiet { 0 } else { 1 };
assert_eq!(
count_occurrences(&stderr, EMPTY_OUTPUT_NOTICE),
notices,
"{what}: publishing the empty output prints {notices} notice(s) (published \
{:?} after the truncation); stderr:\n{stderr}",
empty_at.duration_since(started)
);
}
#[test]
fn truncate_and_close_publishes_the_empty_output_within_the_deadline_with_one_notice() {
truncate_and_close(&[], false, "default");
}
#[test]
fn truncate_and_close_with_poll_interval_0_publishes_the_empty_output_on_its_own_deadline() {
truncate_and_close(&["--poll-interval", "0"], false, "--poll-interval 0");
}
#[test]
fn truncate_and_close_under_quiet_publishes_the_empty_output_without_a_notice() {
truncate_and_close(&[], true, "--quiet");
}
fn repeated_truncation(poll_interval: &str) {
let what = format!("--poll-interval {poll_interval}");
let dir = tempfile::tempdir().unwrap();
let src = dir.path().join("t.mds");
std::fs::write(&src, "version 1\n").unwrap();
let out = dir.path().join("t.md");
let (mut child, tap) = spawn_ready(
mds_bin()
.arg("watch")
.arg(&src)
.args(["--debounce", "0", "--poll-interval", poll_interval])
.stdout(Stdio::null()),
);
let mut log = OutputLog::default();
log.wait_for(&out, "version 1", TIMEOUT);
let stream_started = Instant::now();
for _ in 0..REPEAT_ROUNDS {
drop(File::create(&src).expect("truncate the entry"));
log.poll_for(&out, REPEAT_EVERY);
}
let stream_ended = Instant::now();
if log.first_empty.is_none() {
log.poll_for(&out, EMPTY_HOLD_DEADLINE + TIMEOUT);
}
let stderr = stderr_through_the_marker(&src, tap, &mut child);
match log.first_empty {
Some(at) => assert!(
at < stream_ended,
"{what}: the empty output was published {:?} AFTER the stream of truncations \
ended — later events extended the deadline; stderr:\n{stderr}",
at.duration_since(stream_ended)
),
None => panic!(
"{what}: the empty output was never published, during the {:?} stream or after \
it; states read: {:?}; stderr:\n{stderr}",
stream_ended.duration_since(stream_started),
log.contents()
),
}
}
#[test]
fn repeated_truncation_publishes_the_empty_output_before_the_stream_ends_poll_0() {
repeated_truncation("0");
}
#[test]
fn repeated_truncation_publishes_the_empty_output_before_the_stream_ends_poll_1000() {
repeated_truncation("1000");
}
#[test]
fn a_source_empty_at_startup_compiles_to_empty_immediately() {
let dir = tempfile::tempdir().unwrap();
let src = dir.path().join("t.mds");
File::create(&src).unwrap();
let out = dir.path().join("t.md");
let (mut child, tap) = spawn_ready(
mds_bin()
.arg("watch")
.arg(&src)
.args(["--debounce", "0"])
.stdout(Stdio::null()),
);
assert_eq!(
std::fs::read_to_string(&out).ok().as_deref(),
Some(""),
"file mode: the empty output exists as soon as the watcher is ready"
);
let stderr = stderr_through_the_marker(&src, tap, &mut child);
assert_eq!(
count_occurrences(&stderr, EMPTY_OUTPUT_NOTICE),
0,
"file mode: no notice for a source that was empty from the start; stderr:\n{stderr}"
);
let dir = tempfile::tempdir().unwrap();
let root = dir.path().join("src");
std::fs::create_dir(&root).unwrap();
let src = root.join("e.mds");
File::create(&src).unwrap();
let out = dir.path().join("out");
let (mut child, tap) = spawn_ready(
mds_bin()
.arg("watch")
.arg(&root)
.arg("--out-dir")
.arg(&out)
.args(["--debounce", "0"])
.stdout(Stdio::null()),
);
assert_eq!(
std::fs::read_to_string(out.join("e.md")).ok().as_deref(),
Some(""),
"directory mode: the empty output exists as soon as the watcher is ready"
);
let stderr = stderr_through_the_marker(&src, tap, &mut child);
assert_eq!(
count_occurrences(&stderr, EMPTY_OUTPUT_NOTICE),
0,
"directory mode: no notice for a source that was empty from the start; \
stderr:\n{stderr}"
);
}