Skip to content

tests/util: Enhance CmdResult #4259

@Joining7943

Description

@Joining7943

I would love to enhance the existing functionality of CmdResult by a few points.

Use ExitStatus instead of code and success

We get the ExitStatus from the wait methods in UChild, so no extraction of code and success is required to initialize the CmdResult. On unix platforms we could provide a method in CmdResult to assert signals or whatever is available in std::os::unix::ExitStatusExt.

Rename stderr_is to stderr_trimmed_is and provide a stderr_is method which asserts the stderr untrimmed

This method gave a hard time once, until I found out that stderr is trimmed. The trimming should be more obvious.

Provide stdout_apply, stdout_str_apply, stderr_apply and stderr_str_apply methods which apply a function to the stdout (stderr) and return a CmdResult

Such method calls could for example look like

ucommand.run().stdout_str_apply(str::trim).stdout_only("hello world");
ucommand.run().stdout_apply(|s| &s[0..5]).stdout_only("hello");

This has the advantage, that we can stay in the CmdResult chain, instead of breaking out with let stdout = ucommand.run().stdout_str(), then doing something with stdout and then asserting this stdout manually.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions