-
Notifications
You must be signed in to change notification settings - Fork 1
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
Make examples work from any subdirectory #11
Comments
@joseluis, thanks for the wonderful suggestion, but the main purpose of examples, according to me, is for people to look at the code usage and run it via cargo's functionality.: cargo run --example <example name> The examples aren't supposed to be run from outside the library, and that's why the paths are hard coded in the examples.. |
yes, that doesn't change. The thing is if you run that command from the examples folder they fail because the output path can't be found. having said that, it's ok if you prefer the way it is now, so feel free to close the issue & pr. |
Correct me if I am wrong, but the command: cargo run --example <example name> is supposed to be run from the libray root and not from the examples folder, right? Also I surely like your suggestion but implementing it is currently not high on my priority, but in the future I would like to return back to it. |
Well, cargo commands for building, running, checking, testing, etc. can be run from the root or from any subdirectory inside the project. That's also how git works. That changes if there's an assumption of the calling path, like in this case, from inside the examples code. there's no standard solution for this conflict of assumptions that can be confusing when looking at a project for the first time, only mitigations in the form of better error messages, specify how examples are supposed to be run in the readme, or add some boilerplate like in this PR. |
Since their output path is currently hardcoded, they fail when run outside the project's root.
I've created a proof-of-concept in PR #12 that enables them to be run from anywher inside the project.
This could also be applied to the integration tests. But in that case it may be more convenient to put the path() function in a common module instead of repeating it on each file.
The text was updated successfully, but these errors were encountered: