-
Notifications
You must be signed in to change notification settings - Fork 18
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
Running "standard" unix commands #168
Comments
I've been considering allowing people to register functions as bins. My main intention was so users can have cross-platform behavior with their commands but we could extend the idea further by passing some state, like the CWD, to the function and allowing it to mutate the state. |
Yeah, that would be helpful. Another issue is with the CWD, since I need to use a different tempdir for each test ideally, so they don't step on each other; and I don't think I can do that currently, unless I have one |
A challenge with that is that we can only have one file system snapshot per trycmd/md file. I was also concerned about forcing people to put everything inside a single code fence. This can be worked around by creating a directory for each code fence. |
Something that will be frustrating is if every test author has to write their own set of these functions. It might be nice for us to create crates on top of trycmd that provide these and register them in bulk. Ideas include
One of the things I'm thinking about with this is answering the question "what would have prevented cargo-add from having to switch from trycmd to snapbox" |
Yes, that's a good idea. Another way to handle it could be to have an "unknown command" handler. So eg. it might look like this:
The closure would be called whenever TryCmd can't find a command, and it would default to outputting an error or warning. |
I lean towards explicitly registering each one
|
Maybe related to this idea, but I'd like to be able to show examples in my documentation that use standard input. My usual way to document this is something like:
So users can copy-paste it and get the same result (and then modify as needed). It would be great to be able to test that these examples work using trycmd. In addition to this issue, I see #101 and #102, but all these issues are a bit more complicated than providing stdin (the simplest command being to |
@jpmckinney could you create another issue for piping? |
Will do! Edit: #172 |
We can also use something like duckscript as a cross-platform shell |
I'm trying to write a testable README for a command that processes files. I'd love to have file redirection work: $ echo Hello, world >demo-file
$ my-command --frob demo-file
Frobnicated demo-file. The easiest way might be to be able a variant of |
Since I really miss cram, I'm very tempted to make a PR that adds a "shell mode" where all command lines that don't look like binaries or environment variable setting are just passed to The biggest speed bump is that currently the code eagerly parses the binary name out of the command line, whereas with shell mode you'd be better off letting commands remain as a string, and parse at the time of needing to execute something. There's not really a singular Would you be willing to entertain such a change? It could be a toggle that's disabled by default, to remain in the current registered-binaries-only world. |
I've read through the trycmd code base and done an experimental spike on the code changes needed. I feel like supporting "real shell" scripts properly is too much at odds with the TOML-based test code in trycmd. I think "real shell" support would be better off living in a separate project. |
FWIW I've moved to a custom testing framework built on |
@cloudhead Can you share what you're doing with snapbox? snapbox is part of this repository, so it's still relevant :) |
Sure: this is the alternative to It supports stuff like setting env vars, expecting failure etc., and is very simple. |
I'm testing a tool that requires for example creating a git repository and cd'ing into it, something like:
It seems like it's possible to "register" some of these commands using
register_bin
, but some commands likecd
are actual shell built-ins. What is the correct way to write this test in such a way that it can be read as realistic example as well?The text was updated successfully, but these errors were encountered: