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

fix: Do not warn tests outside a module for integration tests #13038

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

berkus
Copy link

@berkus berkus commented Jul 4, 2024

Fixes a false positive that triggers tests_outside_test_module in integration tests. As per The Rust Book the integration tests do not need neither #[cfg(test)] nor a separate module because they are separate binary crates.

changelog: [tests_outside_test_module] Do not lint for integration tests
fixes #11024

@rustbot
Copy link
Collaborator

rustbot commented Jul 4, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Alexendoo (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 4, 2024
@berkus
Copy link
Author

berkus commented Jul 4, 2024

I am asking for some guidance on how to test the lint on the unit tests though - the test suite I see in clippy is actually integration tests.

@Alexendoo
Copy link
Member

Being in tests does not mean that it's an integration test, e.g. mod tests; is not uncommon - https://github.com/rust-lang/rust/tree/9ffe52e05b063f5fea020d501216a35559ca8620/compiler/rustc_errors/src/markdown/tests

Similarly an integration test can live outside the tests directory - https://github.com/DioxusLabs/dioxus/blob/e1ea213d056d22dcc801a68b0f24300d32b0c90d/packages/desktop/Cargo.toml#L101-L104

@berkus
Copy link
Author

berkus commented Jul 4, 2024

Being in tests does not mean that it's an integration test, e.g. mod tests; is not uncommon - https://github.com/rust-lang/rust/tree/9ffe52e05b063f5fea020d501216a35559ca8620/compiler/rustc_errors/src/markdown/tests

in this case I believe it should work, as the test file path will not start with tests. I can try and add a test for it, again if I understand how to do unit testing in clippy source.

Similarly an integration test can live outside the tests directory - https://github.com/DioxusLabs/dioxus/blob/e1ea213d056d22dcc801a68b0f24300d32b0c90d/packages/desktop/Cargo.toml#L101-L104

For such custom paths there should be some Cargo manifest parsing, I guess. Again, any guidelines to an accepted approach are appreciated.

@Alexendoo
Copy link
Member

in this case I believe it should work, as the test file path will not start with tests. I can try and add a test for it, again if I understand how to do unit testing in clippy source.

Ah I missed that it checked the first path component, that can be a problem in workspaces as the working directory would be the workspace root rather than the package root. Tests inside an integration test can also live in submodules

For such custom paths there should be some Cargo manifest parsing, I guess. Again, any guidelines to an accepted approach are appreciated.

Sorry to say I don't have a good answer here, we generally try to avoid parsing Cargo things

@Alexendoo
Copy link
Member

@Alexendoo Alexendoo added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jul 17, 2024
@xFrednet
Copy link
Member

xFrednet commented Aug 3, 2024

Hey @berkus , this is a ping from triage, since there hasn't been any activity in some time. Are you still planning to continue this implementation?

If you have any questions, you're always welcome to ask them in this PR or on Zulip.

@rustbot author

@berkus
Copy link
Author

berkus commented Aug 3, 2024

Hi, yes, i will get back on it next week.

@berkus berkus force-pushed the fix/11024-integration-tests branch from d7ef35e to 0a9eb84 Compare August 7, 2024 11:36
@berkus berkus force-pushed the fix/11024-integration-tests branch from 0a9eb84 to 67a50c9 Compare August 7, 2024 11:48
@berkus
Copy link
Author

berkus commented Sep 7, 2024

it's approximated by checking the last path component of the directory the crate entry point is located in

I've applied this, but need to update tests; short on time recently, will get back to it soon.

@oxalica
Copy link
Contributor

oxalica commented Sep 17, 2024

Got here from #11119 which is also about false positive in integration tests. Seems your is_integration_test function in this PR would be useful for that too. Could we move it to clippy_utils for use in is_in_test? So we can also fix #11119 by the way.

@berkus
Copy link
Author

berkus commented Sep 18, 2024

Yeah that should be possible, I will find some time to fix the remaining tests and move the fn - this week!

@bors
Copy link
Contributor

bors commented Sep 22, 2024

☔ The latest upstream changes (presumably #13440) made this pull request unmergeable. Please resolve the merge conflicts.

@berkus
Copy link
Author

berkus commented Nov 11, 2024

Ok @bors will do. Still finding time to mess with the tests setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tests_outside_test_module can be triggered in integration tests
6 participants