coreutils
coreutils copied to clipboard
test utilities: easy way to simulate terminal context
addresses #5785 and addresses #1857 replaces if accepted PR #5858
let me know what you think. It's very easy to use. Just do a .simulate_terminal(true)
and thats it.
I implemented in such a way that also stdin piping still works and also the capturing of stdout and stderr works as usual.
Example:
#[test]
fn test_simulation_of_terminal_true() {
let scene = TestScenario::new(util_name!());
let out = scene
.ucmd()
.arg("sh")
.arg("is_atty.sh")
.terminal_simulation(true)
.succeeds();
assert_eq!(
String::from_utf8_lossy(out.stdout()),
"stdin is atty\r\nstdout is atty\r\nstderr is atty\r\n"
);
assert_eq!(
String::from_utf8_lossy(out.stderr()),
"This is an error message.\r\n"
);
}
where is_atty.sh
looks like this:
#!/bin/bash
if [ -t 0 ] ; then
echo "stdin is atty"
else
echo "stdin is not atty"
fi
if [ -t 1 ] ; then
echo "stdout is atty"
else
echo "stdout is not atty"
fi
if [ -t 2 ] ; then
echo "stderr is atty"
else
echo "stderr is not atty"
fi
echo "This is an error message." > /dev/stderr
true
Is it ready to merge already, or are we waiting for further improvements ?
What is missing is a review and approval from one of the maintainers. @sylvestre - I also did the squash commit now. Let me know what you think.
One final question: have you seen any intermittently failing tests with this? Can we assume that this implementation is robust enough not to make our test suite fail unexpectedly (even more so then it already does 😅)
I think its stable.
GNU testsuite comparison:
Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)
GNU testsuite comparison:
Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)
GNU testsuite comparison:
Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)
thanks