more: tests: cleanup processes in test_valid_arg

Added cleanup in test_alive to ensure all spawned processes are
terminated on successful test execution.

This also fixes a race condition that could occur: the check for
process is_alive might be executing while more is still parsing
the arguments.
This commit is contained in:
Martin Kunkel 2025-08-04 21:39:02 +02:00
parent 45457cf718
commit ff001139ea

View file

@ -46,14 +46,22 @@ fn test_valid_arg() {
fn test_alive(args: &[&str]) {
let (at, mut ucmd) = at_and_ucmd!();
let file = "test_file";
at.touch(file);
ucmd.args(args)
.arg(file)
.run_no_wait()
.make_assertion()
.is_alive();
let content = "test content";
let file = "test_file";
at.write(file, content);
let mut cmd = ucmd.args(args).arg(file).run_no_wait();
// wait for more to start and display the file
while cmd.is_alive() && !cmd.stdout_all().contains(content) {
cmd.delay(50);
}
assert!(cmd.is_alive(), "Command should still be alive");
// cleanup
cmd.kill();
}
#[test]