Skip to content

Commit

Permalink
Merge pull request #18757 from roife/fix-17812
Browse files Browse the repository at this point in the history
feat: support updating snapshot tests with codelens/hovering/runnables
  • Loading branch information
Veykril authored Jan 1, 2025
2 parents 085ad10 + 7b3dffd commit a612fc9
Show file tree
Hide file tree
Showing 13 changed files with 540 additions and 97 deletions.
6 changes: 6 additions & 0 deletions crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5933,6 +5933,12 @@ impl HasCrate for Adt {
}
}

impl HasCrate for Impl {
fn krate(&self, db: &dyn HirDatabase) -> Crate {
self.module(db).krate()
}
}

impl HasCrate for Module {
fn krate(&self, _: &dyn HirDatabase) -> Crate {
Module::krate(*self)
Expand Down
68 changes: 54 additions & 14 deletions crates/ide/src/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ fn main() {
},
kind: Bin,
cfg: None,
update_test: UpdateTest {
expect_test: false,
insta: false,
snapbox: false,
},
},
),
},
Expand Down Expand Up @@ -401,6 +406,11 @@ fn main() {
},
kind: Bin,
cfg: None,
update_test: UpdateTest {
expect_test: false,
insta: false,
snapbox: false,
},
},
),
},
Expand Down Expand Up @@ -537,6 +547,11 @@ fn main() {
},
kind: Bin,
cfg: None,
update_test: UpdateTest {
expect_test: false,
insta: false,
snapbox: false,
},
},
),
},
Expand Down Expand Up @@ -597,6 +612,11 @@ fn main() {}
},
kind: Bin,
cfg: None,
update_test: UpdateTest {
expect_test: false,
insta: false,
snapbox: false,
},
},
),
},
Expand Down Expand Up @@ -709,6 +729,11 @@ fn main() {
},
kind: Bin,
cfg: None,
update_test: UpdateTest {
expect_test: false,
insta: false,
snapbox: false,
},
},
),
},
Expand Down Expand Up @@ -744,6 +769,20 @@ mod tests {
"#,
expect![[r#"
[
Annotation {
range: 3..7,
kind: HasReferences {
pos: FilePositionWrapper {
file_id: FileId(
0,
),
offset: 3,
},
data: Some(
[],
),
},
},
Annotation {
range: 3..7,
kind: Runnable(
Expand All @@ -760,23 +799,14 @@ mod tests {
},
kind: Bin,
cfg: None,
update_test: UpdateTest {
expect_test: false,
insta: false,
snapbox: false,
},
},
),
},
Annotation {
range: 3..7,
kind: HasReferences {
pos: FilePositionWrapper {
file_id: FileId(
0,
),
offset: 3,
},
data: Some(
[],
),
},
},
Annotation {
range: 18..23,
kind: Runnable(
Expand All @@ -796,6 +826,11 @@ mod tests {
path: "tests",
},
cfg: None,
update_test: UpdateTest {
expect_test: false,
insta: false,
snapbox: false,
},
},
),
},
Expand All @@ -822,6 +857,11 @@ mod tests {
},
},
cfg: None,
update_test: UpdateTest {
expect_test: false,
insta: false,
snapbox: false,
},
},
),
},
Expand Down
148 changes: 127 additions & 21 deletions crates/ide/src/hover/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3260,6 +3260,11 @@ fn foo_$0test() {}
},
},
cfg: None,
update_test: UpdateTest {
expect_test: false,
insta: false,
snapbox: false,
},
},
),
]
Expand All @@ -3277,28 +3282,33 @@ mod tests$0 {
}
"#,
expect![[r#"
[
Runnable(
Runnable {
use_name_in_title: false,
nav: NavigationTarget {
file_id: FileId(
0,
),
full_range: 0..46,
focus_range: 4..9,
name: "tests",
kind: Module,
description: "mod tests",
},
kind: TestMod {
path: "tests",
},
cfg: None,
[
Runnable(
Runnable {
use_name_in_title: false,
nav: NavigationTarget {
file_id: FileId(
0,
),
full_range: 0..46,
focus_range: 4..9,
name: "tests",
kind: Module,
description: "mod tests",
},
),
]
"#]],
kind: TestMod {
path: "tests",
},
cfg: None,
update_test: UpdateTest {
expect_test: false,
insta: false,
snapbox: false,
},
},
),
]
"#]],
);
}

Expand Down Expand Up @@ -10029,3 +10039,99 @@ fn bar() {
"#]],
);
}

#[test]
fn test_runnables_with_snapshot_tests() {
check_actions(
r#"
//- /lib.rs crate:foo deps:expect_test,insta,snapbox
use expect_test::expect;
use insta::assert_debug_snapshot;
use snapbox::Assert;
#[test]
fn test$0() {
let actual = "new25";
expect!["new25"].assert_eq(&actual);
Assert::new()
.action_env("SNAPSHOTS")
.eq(actual, snapbox::str!["new25"]);
assert_debug_snapshot!(actual);
}
//- /lib.rs crate:expect_test
struct Expect;
impl Expect {
fn assert_eq(&self, actual: &str) {}
}
#[macro_export]
macro_rules! expect {
($e:expr) => Expect; // dummy
}
//- /lib.rs crate:insta
#[macro_export]
macro_rules! assert_debug_snapshot {
($e:expr) => {}; // dummy
}
//- /lib.rs crate:snapbox
pub struct Assert;
impl Assert {
pub fn new() -> Self { Assert }
pub fn action_env(&self, env: &str) -> &Self { self }
pub fn eq(&self, actual: &str, expected: &str) {}
}
#[macro_export]
macro_rules! str {
($e:expr) => ""; // dummy
}
"#,
expect![[r#"
[
Reference(
FilePositionWrapper {
file_id: FileId(
0,
),
offset: 92,
},
),
Runnable(
Runnable {
use_name_in_title: false,
nav: NavigationTarget {
file_id: FileId(
0,
),
full_range: 81..301,
focus_range: 92..96,
name: "test",
kind: Function,
},
kind: Test {
test_id: Path(
"test",
),
attr: TestAttr {
ignore: false,
},
},
cfg: None,
update_test: UpdateTest {
expect_test: true,
insta: true,
snapbox: true,
},
},
),
]
"#]],
);
}
Loading

0 comments on commit a612fc9

Please sign in to comment.