-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests/util
: Implement enhancements of CmdResult
#4259
#4261
tests/util
: Implement enhancements of CmdResult
#4259
#4261
Conversation
410c896
to
d269c62
Compare
GNU testsuite comparison:
|
GNU testsuite comparison:
|
fc77e49
to
b2e4a22
Compare
GNU testsuite comparison:
|
Instead of applying cmdresult.stdout_is("cat: some error");
// becomes
cmdresult.stdout_is("cat: some error\n");
// instead of
cmdresult
.stdout_trimmed_is("cat: some error");
// or
cmdresult
.stdout_str_apply(str::trim)
.stdout_is("cat: some error"); because that's a more precise test anyway. |
I'd actually prefer, too. I'll try to change as much of these usages. |
What do you think of |
The functionality is good, but I'd prefer if it was a separate setting on |
In |
d3756ea
to
4d311be
Compare
It would work if we only construct the raw |
GNU testsuite comparison:
|
Ok, that would work, but is it worth it? This solution is less involved and provides pretty much the same functionality. Or is there any other gain in tracking the |
GNU testsuite comparison:
|
We could use it to provide better error messages maybe? I'm not sure either. |
Me neither. But, I actually like your idea, also because this is the way how a builder like However, would you be fine with keeping |
036c75f
to
6a54f3c
Compare
This pr would be ready so far. Please tell me if you're ok with keeping the Please note that I updated the pr description. Some tests in |
GNU testsuite comparison:
|
Do you think they're useful on their own? If were gonna do the same thing a different way soon and remove these I don't think we need to include them here. |
tests/common/util.rs
Outdated
/// Return the exit status of the child process, if any. | ||
/// | ||
/// Returns None if the child process is still running or hasn't been started. | ||
pub fn maybe_exit_status(&self) -> Option<ExitStatus> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think try_exit_status
is idiomatic Rust
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dunno, just tried something here. I searched the stdlib
once and found no clear answer on how a naming scheme should look like for methods that return an Option
. Try
is definitely a good choice for methods that return a Result
. Most of the time methods that return an Option
are not given a special prefix, seldomly they are prefixed with try
or even maybe
. Sometimes they prefix variables that contain an option with maybe
. If you'd agree, in our case it's probably best to remove the maybe
prefix, since this is just a getter and we don't really try
to get something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I overlooked, that I named another method exit_status
already. It's try_exit_status
, then, if that's preferred over maybe_exit_status
.
tests/common/util.rs
Outdated
pub fn stderr_trimmed_is<T: AsRef<str>>(&self, msg: T) -> &Self { | ||
assert_eq!(self.stderr_str().trim(), msg.as_ref()); | ||
self | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this now that we check the newlines explicitly? I think the problem you found with tr
show that checking the newlines explicitly is the way to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this now that we check the newlines explicitly?
Nope. I'll remove the method.
ok, let's remove them and address this in another pr. |
461003f
to
db6e429
Compare
GNU testsuite comparison:
|
Everything alright with this pr? I addressed all your comments. If it's ok I don't squash the commits any further. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah looks good! Just one more nit. As a final squash maybe you could add the signals feature to the commit that introduced the need for them.
tests/common/util.rs
Outdated
/// zero-exit from running the Command? | ||
/// see [`success`] | ||
success: bool, | ||
// /// exit status for command (if there is one) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a double comment here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
548df96
to
eee6cdc
Compare
Sure, no problem. |
GNU testsuite comparison:
|
eee6cdc
to
338e951
Compare
@tertsdiepraam my account was suspended since last week. I'm not sure about the reason for the suspend, but github unsuspended my account today after I wrote to the github support several times. Seems, that all prs, issues etc. which I created, disappeared for that period. However, it looks like noting's lost and I rebased onto |
…tdout, stderr before asserting
…rite tests for CmdResult
… unix systems Add tests for these signal methods. Include `signals` feature in Cargo.toml uucore dev-dependencies.
…n arbitrary assertions
…derr_trimmed_is. Fix tests assert whitespace instead of trimming it. Disable some tests in `test_tr` because `tr` produces too many newlines.
…`, `stdout_is_bytes`
338e951
to
78a3810
Compare
GNU testsuite comparison:
|
Glad to see you're back! |
yeah me too! Honestly missed that working on |
This pr enhances
CmdResult
. The following changes are introduced inCmdResult
:stderr_str_apply
,stderr_apply
,stdout_str_apply
,stdout_apply
to apply a function to thestderr
orstdout
returning a newCmdResult
on which the assertions inCmdResult
can be run.stderr_str_check
,stderr_check
,stdout_str_check
,stdout_check
. Enables running arbitrary functions returing abool
to verify thestdout
orstderr
in addition to the assertionsCmdResult
already provides.stderr
instderr_is
. Add a separate methodstderr_trimmed_is
for assertingstderr
trimmed of whitespace.code
andsuccess
fields and instead store theExitStatus
of the child process in theexit_status
field. Asignal_is
,signal_name_is
to assert the receivedsignal
on unix systems.stderr_is_bytes
andstdout_is_bytes
to include (in addition to the diff of the bytes arrays) thestdout
,stderr
converted from bytes to a string if possible. If not possible the UTF-8 error message is shown instead of the string.The integration tests needed to be adjusted to the new situation in
stderr_is
and now assert whitespace which was previously trimmed.Some tests in
test_tr
fail now and needed to be disabled until fixed.tr
produces sometimes two newlines at the end of the output instead of just one. I cross checked some those tests randomly with gnu'str
, to ensure that only one newline is expected.Closes #4259