avoid `eq_op` in test code by llogiq · Pull Request #7811 · rust-lang/rust-clipp...
source link: https://github.com/rust-lang/rust-clippy/pull/7811
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
New issue
avoid eq_op
in test code
#7811
Merged
Conversation
Add a check to eq_op
that will avoid linting in functions annotated with #[test]
Please write a short comment explaining your change (or "none" for internal only changes)
changelog: avoid eq_op
in test functions
r? @xFrednet
(rust-highfive has picked a reviewer for you, use r? to override)
I did Re-run jobs
on CI some times, but for some reason it's canceled in the middle of installing toolchain and CI failed.
Yeah, that's really strange. Tests work locally, so I'm not too worried.
Hey, just a small NIT, the rest LGTM
Outdated Show resolved
I now have extended our compile-test harness to compile tests in test/ui_test
. However, it appears my test function detection is ineffective. Does anyone have an idea on how to reliably detect test code in HIR (which is already expanded to $deity knows what)?
The dev guide has something to say about how tests are compiled. So basically all we get is a pub
and a reexport. I guess the only way to get at this is to look into the span's ExpnData
and see if we can detect something test-alike.
Zulip user DevinR528 found a solution. As looking into the expansion data doesn't seem to help, I'm going to incorporate that for now. Thanks, Devin!
The error seems unrelated but persistent even on re-running the jobs.
Ah, I see! I change the compiletest parameters without cloning the Config, and as a result, everything afterwards gets compiled with --test
!
Luckily that's easy to fix.
Now all tests pass this should be ready for review.
let parent_mod = tcx.parent_module(id);
let mut vis = VisitConstTestStruct { names, found: false };
tcx.hir().visit_item_likes_in_module(parent_mod, &mut vis);
vis.found
You could use tcx.item_children
instead of a visitor here. I would just check item.name
and #[rustc_test_marker]
and then you don't need to go into item.kind
.
Also I think you can't do tcx.parent_module
since you can have
fn f() { #[test] fn t() {} // the test marker is in a fn not a module }
so maybe move this logic inside the parent iteration where you find ItemKind::Fn
.
I'd consider nested test methods a degenerate case and if those who do this get a false positive, they likely deserve it .
@camsteffen I've added the #[rustc_test_marker]
check, which works, but I couldn't get the item_children
query to work. So I kept the visitor for now.
@xFrednet r?
Jup, I'll try to review this today. The code I already saw was looking good . One NIT I already found, could you document that lints using is_test_module_or_function
and is_test_function
have to add a ui test to tests/ui_test/
to make sure that the tests are included in the compilation? You can just add that in the doc comment of the function.
@xFrednet Done!
@xFrednet now r?
LGTM!
Thank you for the changes!
@bors r+
Commit e88c956 has been approved by xFrednet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
No milestone
Successfully merging this pull request may close these issues.
None yet
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK