Using testing crates in non testing code

Hello people!

For my first toy project in Rust, I've started working on Pharaoh, a functional testing tool for command lines application. The idea of the project is a program that takes test specifications in yaml files and runs them.

The project can be found here:

First of all, any tips or reviews are appreciated!

I'm not super fan of the Box> everywhere, but I'm not quite sure how to deal with it in an elegant way since for now I'm in the I/O heavy part of the code.

My big question: I've used the crate assert_cmd in my own tests, and I realize that what I want to do in the real code is pretty similar: after all, I want to run a program and compare its outputs to the expectations. Rather than reinventing the wheel, it would be great if I could reuse that crate, maybe along with assert_fs which I've found that could be useful for me. But since those are designed for tests, they panic on assert, and are not usable as-is for my program.

On a more general note, I would love to take advantage of the existing infrastructure to run all my tests and gather the results, but I'm not sure I can manipulate the testing API programmatically. Am I doomed to recode everything myself?

Thanks for all the input!

Look on std::panic.
Usually it's considered a bad idea to catch panic, but this is what happens in tests and if you are doing some kind of testing tool… this is probably the way to go.

Oh, that's a great idea! I'm going to look into it, thanks!

You could also propose to assert_cmd to add a fallible API for a future version. I think even in the context of test cases it could be valuable. For example : being able to combine results and only make the test fail if a particular combination of results failed.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.