Feature request: Better support for non-CLI usage - or: nextest-as-a-lib #2619
TobiasvdVen
started this conversation in
Feature requests
Replies: 1 comment 1 reply
-
|
Thanks for the report. In general I'm okay accepting minor changes like making methods I appreciate what the bon folks are doing, but (if required) would prefer a manually-implemented builder pattern for the avoidance of proc-macro magic. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Motivation
I have a pet project that is basically a GUI for running tests.
I'd like to leverage nextest for the actual mechanics of discovering, running and parsing tests. If I can do this in code, rather than needing to parse CLI output, that would be vastly preferable.
There's a few minor things blocking my ability to do so, however, mainly related to visibility.
I've outlined what seems to me a "minimal" way to be able to do what I need in the "Proposal" section.
What I'm wondering is, is this something that nextest wants to support? Is it strictly intended to be used as a CLI tool, or is it also meant to serve as a lib?
Proposal
Having poked around a bit, it seems nextest is composed and run with
CargoNextestApp::parse()as its primary starting point. Through this API, it seems there is currently no way to leverage theTestEventstream thatTestRunner::execute(...)provides.To gain access to that, it seems to me that the
CargoOptionstype must be madepub(instead ofpub(crate)). This then allows access toCargoOptions::compute_binary_list(), which produces the binaries that are needed to run the tests. The functionacquire_graph_data()must also be madepub, as the metadata it gathers is required for the previous step.Likewise, the fields of
OutputContextmust be madepub(instead ofpub(crate)), as theOutputContextis required for the functions above. There may be a way to avoid this, as anOutputContextis presumably not a true dependency when one is running without wanting nextest to actually write to the process output.There also needs to be a way to construct and initialize a
CargoOptionsinstance. I have a Fork over here where I've made these minimal changes. I use bon to facilitate theCargoOptionsconstruction though, and I'm hesitant to create a PR for these changes. Adding a whole crate just for an edge-case like this may be too much. I'm curious about others' thoughts.Alternatives
As an alternative to
bon, it would be possible to manually craft a builder pattern, or just add a massivenewfunction and rely on consumers of nextest to deal with the construction ofCargoOptions(at least it would be possible that way, as long as thenewispub).There may also be alternatives that modify the existing API landscape. This could reduce the number of additional types or functions that need to be made
pub, by changing at what point they are injected.Additional context
As additional context, this is a rough example of how the nextest API could be used to run some tests, given the changes outlined above:
Beta Was this translation helpful? Give feedback.
All reactions