coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

test utilities: easy way to simulate terminal context

Open cre4ture opened this issue 1 year ago • 5 comments

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

cre4ture avatar Jan 22 '24 17:01 cre4ture

Is it ready to merge already, or are we waiting for further improvements ?

RenjiSann avatar Feb 05 '24 21:02 RenjiSann

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.

cre4ture avatar Feb 07 '24 21:02 cre4ture

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.

cre4ture avatar Feb 08 '24 21:02 cre4ture

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Feb 25 '24 17:02 github-actions[bot]

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Feb 25 '24 18:02 github-actions[bot]

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Feb 25 '24 21:02 github-actions[bot]

thanks

sylvestre avatar Mar 01 '24 17:03 sylvestre