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

stderr().is() fails due to cargo output #45

Closed
steveej opened this issue Oct 8, 2017 · 3 comments
Closed

stderr().is() fails due to cargo output #45

steveej opened this issue Oct 8, 2017 · 3 comments

Comments

@steveej
Copy link

steveej commented Oct 8, 2017

Hey, during my first attempts of writing integration tests I've stumbled upon an issue when the program is supposed to exit with an error output.

My test looks like this:

    #[test]
    fn called_without_args() {
        assert_cli::Assert::main_binary()
            .fails_with(::libc::EINVAL)
            .and()
            .stderr().is(MISSING_ARGUMENTS_OUTPUT)
            .unwrap();
    }
test integration::called_without_args ... FAILED

failures:

---- integration::called_without_args stdout ----
        thread 'integration::called_without_args' panicked at 'CLI assertion failed: `cargo run --` StdErr mismatch: diff:

+Compiling invsearch v0.1.0 (file:///.../invsearch.rs)
    Finished dev [unoptimized + debuginfo] target(s) in 0.62 secs
     Running `target/debug/invsearch`
 No arguments provided. Please provide files to parse.
', /home/steveej/.cargo/registry/src/gb.xjqchip.workers.dev-1ecc6299db9ec823/assert_cli-0.5.3/src/assert.rs:319:12
note: Run with `RUST_BACKTRACE=1` for a backtrace.

The issue is that the error outputs of cargo and the integration test are mixed and the test fails because it's not an exact match.
I know that I could just use .contains(..) instead of .is(..), but IMHO that's only a workaround.

Please let me know if I'm doing something unexpected, as this is my very first attempt of writing (integration) tests in Rust.

@killercup
Copy link
Collaborator

Oh, that is a very good point. That we use cargo run behind the scenes to run the main binary should only be an implementation detail. I guess this code:

https://github.com/killercup/assert_cli/blob/875c4b156b9c5015d22d00d52bc9528764e69b79/src/assert.rs#L27

should also pass --quiet to cargo.

@epage
Copy link
Collaborator

epage commented Oct 9, 2017

Something that would help in testing this and the crate all-around is to create a bin for it. It'd be handy for it to have command line flags for it to print to stdout/stderr, process stdin, process env variables, return arbitrary codes, etc.

epage added a commit to epage/assert_cli that referenced this issue Oct 13, 2017
We use cargo run behind the scenes to run the main binary but that
should only be an implementation detail.

Fixes assert-rs#45
epage added a commit to epage/assert_cli that referenced this issue Oct 13, 2017
We use cargo run behind the scenes to run the main binary but that
should only be an implementation detail.

Fixes assert-rs#45
epage added a commit to epage/assert_cli that referenced this issue Oct 13, 2017
We use cargo run behind the scenes to run the main binary but that
should only be an implementation detail.

Fixes assert-rs#45
epage added a commit to epage/assert_cli that referenced this issue Oct 17, 2017
We use cargo run behind the scenes to run the main binary but that
should only be an implementation detail.

Fixes assert-rs#45
@epage epage closed this as completed in #50 Oct 17, 2017
@steveej
Copy link
Author

steveej commented Oct 18, 2017

Thanks @epage!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants