aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/tests.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-10 08:25:12 +0000
committerGitHub <[email protected]>2021-02-10 08:25:12 +0000
commit8ece5ad0c00a11c2ca60cd0d8f86b3b0d31c9996 (patch)
tree1291cdae663a1b2b86029f56630371b141e6dee7 /crates/assists/src/tests.rs
parent36465b34b3b7f991ebf85680924acdb809b0494e (diff)
parentbfa99f20ffeaf2ef6f2647f2fc8c7b708c7d75d3 (diff)
Merge #7619
7619: Add #[track_caller] to assist tests r=matklad a=yoshuawuyts This points the source of a failed assertion to the code which called it, rather than the location within the assertion helper method. While working on https://github.com/rust-analyzer/rust-analyzer/pull/7617 I had trouble locating some failing tests, and it was only by adding these attributes during development that I was able to locate them. This is only applied to test helpers, which means it comes at no runtime cost. And even then: I didn't experience any noticeable performance with this enabled or disabled. Mostly just a more pleasant experience debugging test failures (: Co-authored-by: Yoshua Wuyts <[email protected]>
Diffstat (limited to 'crates/assists/src/tests.rs')
-rw-r--r--crates/assists/src/tests.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/crates/assists/src/tests.rs b/crates/assists/src/tests.rs
index 32bd8698b..b27f6bf75 100644
--- a/crates/assists/src/tests.rs
+++ b/crates/assists/src/tests.rs
@@ -49,14 +49,17 @@ pub(crate) fn check_assist_by_label(
49// FIXME: instead of having a separate function here, maybe use 49// FIXME: instead of having a separate function here, maybe use
50// `extract_ranges` and mark the target as `<target> </target>` in the 50// `extract_ranges` and mark the target as `<target> </target>` in the
51// fixture? 51// fixture?
52#[track_caller]
52pub(crate) fn check_assist_target(assist: Handler, ra_fixture: &str, target: &str) { 53pub(crate) fn check_assist_target(assist: Handler, ra_fixture: &str, target: &str) {
53 check(assist, ra_fixture, ExpectedResult::Target(target), None); 54 check(assist, ra_fixture, ExpectedResult::Target(target), None);
54} 55}
55 56
57#[track_caller]
56pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) { 58pub(crate) fn check_assist_not_applicable(assist: Handler, ra_fixture: &str) {
57 check(assist, ra_fixture, ExpectedResult::NotApplicable, None); 59 check(assist, ra_fixture, ExpectedResult::NotApplicable, None);
58} 60}
59 61
62#[track_caller]
60fn check_doc_test(assist_id: &str, before: &str, after: &str) { 63fn check_doc_test(assist_id: &str, before: &str, after: &str) {
61 let after = trim_indent(after); 64 let after = trim_indent(after);
62 let (db, file_id, selection) = RootDatabase::with_range_or_offset(&before); 65 let (db, file_id, selection) = RootDatabase::with_range_or_offset(&before);
@@ -95,6 +98,7 @@ enum ExpectedResult<'a> {
95 Target(&'a str), 98 Target(&'a str),
96} 99}
97 100
101#[track_caller]
98fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label: Option<&str>) { 102fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label: Option<&str>) {
99 let (db, file_with_caret_id, range_or_offset) = RootDatabase::with_range_or_offset(before); 103 let (db, file_with_caret_id, range_or_offset) = RootDatabase::with_range_or_offset(before);
100 let text_without_caret = db.file_text(file_with_caret_id).to_string(); 104 let text_without_caret = db.file_text(file_with_caret_id).to_string();