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

Allow checking for any command exit value. #99

Closed
vincentdephily opened this issue Apr 4, 2018 · 4 comments
Closed

Allow checking for any command exit value. #99

vincentdephily opened this issue Apr 4, 2018 · 4 comments

Comments

@vincentdephily
Copy link

This is pretty much what Assert::fails_with(self, expect_exit_code: i32) provides, except that an exit code of 0 is accepted. The current implementation fails the assertion if expect_exit_code=0 and the command returns with an exit code of 0.

Rationale for the functionality: I'm testing for specific exit codes with something that looks like:

        let t = vec![
            (&["all","fine"], 0),
            (&["user","error"], 1),
            (&["program","error"], 2),
        ];
        for (args, exit) in t {
            Assert::main_binary().with_args(args).fails_with(exit).unwrap();
        }

But this fails unless I special-case exit==0 to remove the fails_with() call. It's not hard, but it's ugly and surprising.

I'm not sure if fails_with() should be modified to accept 0 as an argument (ie this issue is a bug) or if a new function (say exits_with()) should be created (ie this issue is a feature request). Tell me which and I'll try to send a PR.

assert_cli 0.5.4 rust 1.25.0

@epage
Copy link
Collaborator

epage commented Apr 4, 2018

Yeah, the problem with fails being in the name, it implies more than just an exit code check.

The good news is that in the API refactor that is under way, we are narrowing the focus of the call to just be about asserting the exit code

See https://github.com/assert-rs/assert_cli/pull/98/files#diff-518bd9db9fa60ba5991cb1df6489cb2fR509

@vincentdephily
Copy link
Author

Ok, so no need for a PR on this isolated issue and we can just close it when pr #98 lands ? Or will the new API take a while to arrive and an interim fix is useful ?

@epage
Copy link
Collaborator

epage commented Apr 5, 2018

If you need it now and want to create a PR, go ahead. #98 is still early in the process.

@epage
Copy link
Collaborator

epage commented May 29, 2018

Addressed in assert_cmd
https://github.com/assert-rs/assert_cmd
assert_cli is going to morph into a wider-focused tool, including things like assert_fs. See #41

@epage epage closed this as completed May 29, 2018
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

2 participants