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

Disable result_unwrap_used / option_unwrap_used in tests #1015

Closed
llogiq opened this issue Jun 16, 2016 · 3 comments · Fixed by #8802
Closed

Disable result_unwrap_used / option_unwrap_used in tests #1015

llogiq opened this issue Jun 16, 2016 · 3 comments · Fixed by #8802
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience. L-tests Lint: Lints test code T-middle Type: Probably requires verifiying types

Comments

@llogiq
Copy link
Contributor

llogiq commented Jun 16, 2016

If clippy is used as a dependency, the lints can pick up test code. Since that code does not need to have full-blown error handling, unwrap is ok.

To solve this, we can use get_parent to walk up the parent chain and check all items for #[test] annotations.

@llogiq llogiq added T-middle Type: Probably requires verifiying types C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages L-tests Lint: Lints test code E-medium Call for participation: Medium difficulty level problem and requires some initial experience. labels Jun 16, 2016
@link2xt
Copy link

link2xt commented May 3, 2022

This will not work properly if test module contains helper functions that do unwrap() and #[test] function calls this helper function rather than unwrap(). Such lints should be disabled for the whole test module.

@llogiq
Copy link
Contributor Author

llogiq commented May 4, 2022

We now have an is_in_test function in clippy_utils that checks both function and module path.

@smoelius
Copy link
Contributor

smoelius commented May 6, 2022

Should this be configurable? I.e., is the change in behavior a concern?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience. L-tests Lint: Lints test code T-middle Type: Probably requires verifiying types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants