-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
Unable to use trybuild with macros that read files #202
Comments
You should use: std::env::set_var(
"CARGO_MANIFEST_DIR_OVERRIDE",
std::env::var_os("CARGO_MANIFEST_DIR").unwrap(),
); at the top of your #[test] that runs trybuild and then this in the macro: let cargo_manifest_dir = std::env::var_os("CARGO_MANIFEST_DIR_OVERRIDE")
.or(std::env::var_os("CARGO_MANIFEST_DIR"))
.unwrap(); |
This works, thanks. Just one problem that I noticed: My macro outputs "Help: Searching in directory $CARGO_MANIFEST_DIR" when the file it was looking for doesn't exist, which by its nature, will not always be the same path. However, trybuild for some reason doesn't replace that directory with |
I think the replacement isn't happening because of this: https://github.com/dtolnay/trybuild/blob/master/src/directory.rs#L18 Is there a particular reason why you only replace the source directory with trailing slashes? |
Filed separately as #204. |
First of all, thanks for this amazing tool!
I'm trying to test a macro which reads files from the source directory of the crate. It reads the
CARGO_MANIFEST_DIR
environment variable (please let me know if there's a better way to do this) and resolves files relative to that directory. Unfortunately, with trybuild it points to$DIR/target/tests/<crate-name>
, which doesn't contain the files I need.Is it possible to have
CARGO_MANIFEST_DIR
point to the manifest that defines the test, or to the directory where the test file is located in?The text was updated successfully, but these errors were encountered: