Skip to content
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

Can #[files] use relative paths #271

Open
griff opened this issue Aug 15, 2024 · 4 comments
Open

Can #[files] use relative paths #271

griff opened this issue Aug 15, 2024 · 4 comments

Comments

@griff
Copy link

griff commented Aug 15, 2024

I have a project I contribute to that uses Nix to build a Rust project that uses the #[files(...)] feature of rstest. But because I am on macOS which compiles and runs the tests in different directories and because #[files(...)] encodes absolute paths the tests fail on my machine.

Would it be possible to use a relative path?

Right now I am more or less the only one using macOS and I can get around it for now by using cargo for local development but if we ever setup CI for macOS this will also break there.

@la10736
Copy link
Owner

la10736 commented Aug 16, 2024 via email

@griff
Copy link
Author

griff commented Aug 17, 2024

It fails with unable to read JSON: Os { code: 2, kind: NotFound, message: "No such file or directory" } when I run the tests because it was built in a temporary directory that no longer exists when I run the tests (I don't control that it does this).

On linux this is not a problem because Nix uses mount namespaces to give the temporary directory where it builds tests the same absolute path as the temporary directory where it runs the tests and so the absolute paths of the test resources match.

I thought tests were always run in the directory where the manifest is. Could another way be that you can set an environment variable that is read at runtime to locate the test resource base directory?

@la10736
Copy link
Owner

la10736 commented Aug 21, 2024

Tests can be run everywhere: the simplest example is in a workspace where you cannot guest where the user invoke the test execution. Anyway tests are runnable in the target folder and we cannot never guess where the glob path is resolved on compile time.

What I can do is to introduce a environment variable like RSTEST_ROOT_PACKAGE evaluated when the tests are compiled and used to replace the cargo manifest path after that the glob pattern are resolved to find the test resources: I guess that can workaround to your issue.

The sad news is that I don't know when I can implement this feature, I can plan to do this while I'll implement #212 but I cannot say a date: sorry.

@la10736
Copy link
Owner

la10736 commented Sep 29, 2024

PR #277 should fit your needs: you can use #[base_dir = ${BASE_DIR:-}] that use the cargo root when BASE_DIR is not set and your provided one when is defined. I'll publish it ASAP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants