Skip to content
This repository was archived by the owner on Dec 29, 2021. It is now read-only.
This repository was archived by the owner on Dec 29, 2021. It is now read-only.

Feature: Or-Operator #19

Description

@colin-kiegel

Just another random idea. :-)

Maybe you could introduce an 'or' operator, where 'or' would have lowest precedence:

Assert::command(&["foo"])
    .succeeds().and().prints("42")
    .or().fails().and().prints("not ready yet..");

Internally this could be achieved by splitting Assert

pub struct Assert {
    cmd: Vec<String>,
    expect: Vec<Expect>, // <-- delegate to a sub component,
                         //     which we can now put in vec
                         //     `.or` would simply push a fresh layer
}

struct Expect {
    success: Option<bool>,
    exit_code: Option<i32>,
    stdout: Option<OutputAssertion>,
    stderr: Option<OutputAssertion>,
}

The biggest challenge would be displaying failures. Here is a suggestion, that should be more or less readable even for large chunks or in the multi-line case - each or-branch will report only the first assertion that failed

'CLI assertion failed: `([1/2] stdout of `echo 42` expected to contain `"41"`)` (output was: `"42\n"`)'
or `([2/2] stdout of `echo 42` expected to contain `"1337"`)` (output was: `"42\n"`)'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions