-
Notifications
You must be signed in to change notification settings - Fork 34
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
Proptesting CLI apps #43
Comments
Some more assorted notes of the top of my head: Temp dirsWhen we generating temporary directories, there are a few aspects one might want to control:
It seems to me that providing a bunch of Extra: Interactive CLI programsSome CLI programs are interactive; for those kinds of programs, you not only have input/output, but the requested inputs and requested outputs can depend on previous input/output pairs. Sometimes multiple inputs are also requested based on previous inputs. This can probably be modeled with State Machines (see: proptest-rs/proptest#28). In my BSc thesis (see: http://publications.lib.chalmers.se/records/fulltext/251311/251311.pdf, repo: https://github.com/DATX02-17-26/DATX02-17-26), we discuss a Haskell DSL that is related to this (see the testing bit, the other parts are irrelevant for CLI apps). Extra: Testing protocolsFor testing protocols, which is tangentially related to CLI apps, there's the MSc thesis "Bidirectional Testing of Communicating Systems" which provides the tool called cc @MaximilianAlgehed on the feasibility of reusing ideas from SessionCheck here. |
Love the idea and would like to help with whatever we come up with but also want to bring up some concerns. Also, in case people aren't aware, we have both assert_cmd and assert_fs that we can leverage. Some challenges
btw for interactivity, we might want to explore how we can reuse or be inspired by rexpect |
@Centril I'm no rust expert, but I don't think it matters here. But I'm more curious why you need the bidirectionality which SessionCheck offers, have you got two programs interacting using the CLI? Best, |
If y'all need examples, then |
@Centril and I talked a bit about writing property tests for CLI apps. The general idea is to write input generation and assertions on CLI app invocations without much overhead (e.g. without having to deal with manually formatting types as CLI arguments).
The most trivial implementation that already works is probably this:
It generates random strings and asserts that echos gives us back the same string it was fed with.
We found that aside from the prop-testing specific challenges, there are also CLI-specific helpers needed, e.g. to easily generate temp dirs with (also generated) files, and that OS-specific or environment specific settings need to be able to be passed as arguments (or to be overwritten to reduce/eliminate dependence on global state).
In general, we think that we can use assert_cli to write these helpers. What we need to find is a way to express relations between arguments (inputs) and the asserts (like "stdout contains").
For the record but not meant as a concrete suggestions as something to implement today, I proposed a macro/DLS like:
that passes two arguments to a binary called
brighten
and asserts that, given valid arguments, the tool writes a string to stdout that can be parsed asColor
. Obviously missing here is a way to setup the environment. Side-effect of this syntax is that generating invalid (or omitting) arguments and asserting that the program fails is easy.The text was updated successfully, but these errors were encountered: