youki icon indicating copy to clipboard operation
youki copied to clipboard

Make failure message great again

Open lizhemingi opened this issue 3 years ago • 10 comments

Right now if we had a test failed when run cargo test, the failure message is missing and we can not locate the assert that failed directly.

And if comment the tests code in tty.rs, the failure message show up again. Just like the failure message is eaten by the tty.

Failure test without commenting tests in tty.rs. image

Failure test with commenting tests in tty.rs. image

It would be a little annoying for debugging when CI failed. So maybe we should find a way to make failure message come back.

cc @utam0k

lizhemingi avatar Jul 20 '21 14:07 lizhemingi

/assign

lizhemingi avatar Jul 20 '21 15:07 lizhemingi

@utam0k I wasn't sure if you want to add --nocapture to cargo test on CI as a solution? This issue is asking for that.

yihuaf avatar Aug 24 '21 04:08 yihuaf

@utam0k I wasn't sure if you want to add --nocapture to cargo test on CI as a solution? This issue is asking for that.

That may be fine for CI, but what about local execution unit tests...

utam0k avatar Aug 24 '21 12:08 utam0k

Sorry I don't follow. For local unit test, you also run cargo test -- --nocapture to see the error output in case test fails when developing. It works exactly the same.

yihuaf avatar Aug 24 '21 18:08 yihuaf

@utam0k @yihuaf

I think nocapture can not meet the requirement of this issue.

https://doc.rust-lang.org/cargo/commands/cargo-test.html#display-options

It seems that the nocapture option means do not capture the output of our tested binary, something like println in our code.

But this issue is looking for the output information by rust test, something like which assert in which file is failed (The difference between two screenshots in the description.)

But maybe add nocapture to CI is also a good advice.

lizhemingi avatar Aug 25 '21 02:08 lizhemingi

I agree with this. However, I don't think this is the root solution.

But maybe add nocapture to CI is also a good advice.

utam0k avatar Aug 25 '21 12:08 utam0k

It seems that the nocapture option means do not capture the output of our tested binary, something like println in our code. But this issue is looking for the output information by rust test, something like which assert in which file is failed (The difference between two screenshots in the description.)

I may be misunderstanding the request for this issue. From the link, I read: By default the Rust test harness hides output from test execution to keep results readable. Test output can be recovered (e.g., for debugging) by passing --nocapture to the test binaries:

The information about which assert failed in which line is exactly the info outputted by --nocapture, in addition to the logs and println. There is also the -v and -vv flag to output additional info for the test build scripts and etc.

Anyhow, you seem to have a clear idea of what you'd like to accomplish in this issue, so I will leave you to it.

yihuaf avatar Aug 26 '21 18:08 yihuaf

The information about which assert failed in which line is exactly the info outputted by --nocapture, in addition to the logs and println. There is also the -v and -vv flag to output additional info for the test build scripts and etc.

I do have a try on add nocapture to the test, and it won't help.(I deliberately change the code to make test failed) image The output here does not have which assert in which file failed.

And if comment the tests code in tty.rs, the failure message show up again. Just like the failure message is eaten by the tty.

And here is the point I think.

Anyhow, you seem to have a clear idea of what you'd like to accomplish in this issue, so I will leave you to it.

Actually I have no idea how to deal with it right now, any suggestion is welcome.

lizhemingi avatar Aug 27 '21 01:08 lizhemingi

And if comment the tests code in tty.rs, the failure message show up again. Just like the failure message is eaten by the tty.

And here is the point I think.

Somehow I overlooked this line. Stupid me... You are right, what I mentioned is not a solution. The root cause is likely something else isolated to the tty tests.

yihuaf avatar Aug 27 '21 02:08 yihuaf

And if comment the tests code in tty.rs, the failure message show up again. Just like the failure message is eaten by the tty.

And here is the point I think.

Somehow I overlooked this line. Stupid me... You are right, what I mentioned is not a solution. The root cause is likely something else isolated to the tty tests.

ah never mind, the screen shot is too big to see the words. 😆

lizhemingi avatar Aug 27 '21 02:08 lizhemingi