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

Access files in parent directory to a repo #205

Closed
stonecharioteer opened this issue Aug 3, 2023 · 9 comments
Closed

Access files in parent directory to a repo #205

stonecharioteer opened this issue Aug 3, 2023 · 9 comments

Comments

@stonecharioteer
Copy link

I'm trying to use files in a folder in the root level of a repository, while the tests are in a submodule.

github-repo/
├─ submodule/
│  ├─ src/
│  │  ├─ lib.rs (this contains the tests)
├─ test_inputs/

I'm unable to use #[files("../test_inputs/") in the lib.rs file so I can glob the particular files I want in test_inputs, but so far, I have only been getting errors related to how I cannot remove prefix path. I tried giving an absolute path as well (I'd really prefer to not do this), and that didn't work either. What choices do I have here?

@la10736
Copy link
Owner

la10736 commented Aug 3, 2023

Unfortunately is not possible to use files that are not in your crate. I'll try to fix it in the next days or maybe weeks is much more realistic.

Absolute path should not work either but you can try with a link.... it could works.

@stonecharioteer
Copy link
Author

Thanks for getting back to me. I tried this with a symlink also, that didn't work either.

@stonecharioteer
Copy link
Author

If you could walk me through how to fix / debug this, I would love to contribute to your repo. This is something really nice that needs to be more popular for Rust tooling.

@la10736
Copy link
Owner

la10736 commented Aug 10, 2023

Thx! I really appreciate your help... but I've just started to fix it. The real issue here is not to find where is the bug but understand how to define a correct behavior for these cases: every case use the file path also to build the test name to make it simple to identify what are the files involved in the failed tests. So, I cannot use the absolute path to build the tests name and every strategy that involve some kind of shrinking is wrong for some use cases.

Maybe the best is to use a path relative to crate folder but the . character is sanitized to fit in a valid rust ident (replaced by _). I guess that the best compromise is to replace ../ with _UP: with this rule a relative path like ../../some/folder/more/file.txt become _UP/_UP/some/folder/more/file.txt and the sanitized name will be _UP_UP_some_folder_more_file_txt. Otherwise we can just ignore the ../ segments but in this case we should find the maximum common prefix of all files and then remove it from the absolute path instead of remove the crate path as is today... I don't love this approach because the tests names are not stable and can change if you add or remove some files.

@not-my-profile
Copy link

not-my-profile commented Aug 11, 2023

github-repo/
├─ submodule/
│  ├─ src/
│  │  ├─ lib.rs (this contains the tests)
├─ test_inputs/

I very much think that this is backwards ... the test_inputs should be a submodule of the test code ... not the other way around. I don't think that this should be supported by rstest.

la10736 added a commit that referenced this issue Aug 12, 2023
la10736 added a commit that referenced this issue Aug 12, 2023
la10736 added a commit that referenced this issue Aug 12, 2023
la10736 added a commit that referenced this issue Aug 12, 2023
@la10736
Copy link
Owner

la10736 commented Aug 12, 2023

Ok ... _UP in test names is not the best choice but I didn't find any better way to express this behavior.
I've implemented it and I hope I'll publish a new version tomorrow ... maybe the 0.18.2: I'm considering it just a bug fix.

@la10736 la10736 closed this as completed Aug 12, 2023
@la10736
Copy link
Owner

la10736 commented Aug 13, 2023

0.18.2 published

@stonecharioteer
Copy link
Author

Great! Thanks for your work. Is it possible, btw, to customize the test case names? Right now, the way we've set things up gives us really similar test case names, since we have multiple nested data directories. I'd like to say "hey, generate the test case names only from the last 3 segments of the path" or something.

@la10736
Copy link
Owner

la10736 commented Aug 31, 2023

Ok,
can you open a new ticket for that with also a proposed syntax that we can discuss?

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

3 participants