Refactor check

This commit is contained in:
Johann Hemmann 2024-01-04 16:10:34 +01:00
parent 971fc1b3e8
commit dbeb27e05d

View file

@ -555,27 +555,16 @@ mod tests {
use crate::fixture;
use super::{RunnableTestKind::*, *};
fn check(
ra_fixture: &str,
// FIXME: fold this into `expect` as well
actions: &[RunnableTestKind],
expect: Expect,
) {
fn check(ra_fixture: &str, expect: Expect) {
let (analysis, position) = fixture::position(ra_fixture);
let mut runnables = analysis.runnables(position.file_id).unwrap();
runnables.sort_by_key(|it| (it.nav.full_range.start(), it.nav.name.clone()));
let mut navigation_targets = Vec::with_capacity(runnables.len());
let mut test_kinds = Vec::with_capacity(runnables.len());
for runnable in runnables {
test_kinds.push(runnable.test_kind());
navigation_targets.push(runnable.nav);
}
expect.assert_debug_eq(&navigation_targets);
assert_eq!(actions, test_kinds.as_slice());
let mut result = analysis
.runnables(position.file_id)
.unwrap()
.into_iter()
.map(|runnable| (runnable.test_kind(), runnable.nav))
.collect::<Vec<_>>();
result.sort_by_key(|(_, nav)| (nav.full_range.start(), nav.name.clone()));
expect.assert_debug_eq(&result);
}
fn check_tests(ra_fixture: &str, expect: Expect) {
@ -613,9 +602,10 @@ mod not_a_root {
fn main() {}
}
"#,
&[TestMod, Bin, Bin, Test, Test, Test, Bench],
expect![[r#"
[
(
TestMod,
NavigationTarget {
file_id: FileId(
0,
@ -624,6 +614,9 @@ mod not_a_root {
name: "",
kind: Module,
},
),
(
Bin,
NavigationTarget {
file_id: FileId(
0,
@ -633,6 +626,9 @@ mod not_a_root {
name: "main",
kind: Function,
},
),
(
Bin,
NavigationTarget {
file_id: FileId(
0,
@ -642,6 +638,9 @@ mod not_a_root {
name: "__cortex_m_rt_main_trampoline",
kind: Function,
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -651,6 +650,9 @@ mod not_a_root {
name: "test_foo",
kind: Function,
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -660,6 +662,9 @@ mod not_a_root {
name: "test_full_path",
kind: Function,
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -669,6 +674,9 @@ mod not_a_root {
name: "test_foo",
kind: Function,
},
),
(
Bench,
NavigationTarget {
file_id: FileId(
0,
@ -678,6 +686,7 @@ mod not_a_root {
name: "bench",
kind: Function,
},
),
]
"#]],
);
@ -779,9 +788,10 @@ trait Test {
/// ```
impl Test for StructWithRunnable {}
"#,
&[Bin, DocTest, DocTest, DocTest, DocTest, DocTest, DocTest, DocTest, DocTest],
expect![[r#"
[
(
Bin,
NavigationTarget {
file_id: FileId(
0,
@ -791,6 +801,9 @@ impl Test for StructWithRunnable {}
name: "main",
kind: Function,
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -798,6 +811,9 @@ impl Test for StructWithRunnable {}
full_range: 15..74,
name: "should_have_runnable",
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -805,6 +821,9 @@ impl Test for StructWithRunnable {}
full_range: 76..148,
name: "should_have_runnable_1",
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -812,6 +831,9 @@ impl Test for StructWithRunnable {}
full_range: 150..254,
name: "should_have_runnable_2",
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -819,6 +841,9 @@ impl Test for StructWithRunnable {}
full_range: 256..320,
name: "should_have_no_runnable_3",
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -826,6 +851,9 @@ impl Test for StructWithRunnable {}
full_range: 322..398,
name: "should_have_no_runnable_4",
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -833,6 +861,9 @@ impl Test for StructWithRunnable {}
full_range: 900..965,
name: "StructWithRunnable",
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -842,6 +873,9 @@ impl Test for StructWithRunnable {}
name: "impl",
kind: Impl,
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -851,6 +885,7 @@ impl Test for StructWithRunnable {}
name: "impl",
kind: Impl,
},
),
]
"#]],
);
@ -872,9 +907,10 @@ impl Data {
fn foo() {}
}
"#,
&[Bin, DocTest],
expect![[r#"
[
(
Bin,
NavigationTarget {
file_id: FileId(
0,
@ -884,6 +920,9 @@ impl Data {
name: "main",
kind: Function,
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -891,6 +930,7 @@ impl Data {
full_range: 44..98,
name: "foo",
},
),
]
"#]],
);
@ -912,9 +952,10 @@ impl Data<'a> {
fn foo() {}
}
"#,
&[Bin, DocTest],
expect![[r#"
[
(
Bin,
NavigationTarget {
file_id: FileId(
0,
@ -924,6 +965,9 @@ impl Data<'a> {
name: "main",
kind: Function,
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -931,6 +975,7 @@ impl Data<'a> {
full_range: 52..106,
name: "foo",
},
),
]
"#]],
);
@ -952,9 +997,10 @@ impl<T, U> Data<'a, T, U> {
fn foo() {}
}
"#,
&[Bin, DocTest],
expect![[r#"
[
(
Bin,
NavigationTarget {
file_id: FileId(
0,
@ -964,6 +1010,9 @@ impl<T, U> Data<'a, T, U> {
name: "main",
kind: Function,
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -971,6 +1020,7 @@ impl<T, U> Data<'a, T, U> {
full_range: 70..124,
name: "foo",
},
),
]
"#]],
);
@ -992,9 +1042,10 @@ impl<const N: usize> Data<N> {
fn foo() {}
}
"#,
&[Bin, DocTest],
expect![[r#"
[
(
Bin,
NavigationTarget {
file_id: FileId(
0,
@ -1004,6 +1055,9 @@ impl<const N: usize> Data<N> {
name: "main",
kind: Function,
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -1011,6 +1065,7 @@ impl<const N: usize> Data<N> {
full_range: 79..133,
name: "foo",
},
),
]
"#]],
);
@ -1032,9 +1087,10 @@ impl<'a, T, const N: usize> Data<'a, T, N> {
fn foo() {}
}
"#,
&[Bin, DocTest],
expect![[r#"
[
(
Bin,
NavigationTarget {
file_id: FileId(
0,
@ -1044,6 +1100,9 @@ impl<'a, T, const N: usize> Data<'a, T, N> {
name: "main",
kind: Function,
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -1051,6 +1110,7 @@ impl<'a, T, const N: usize> Data<'a, T, N> {
full_range: 100..154,
name: "foo",
},
),
]
"#]],
);
@ -1066,9 +1126,10 @@ mod test_mod {
fn test_foo1() {}
}
"#,
&[TestMod, Test],
expect![[r#"
[
(
TestMod,
NavigationTarget {
file_id: FileId(
0,
@ -1079,6 +1140,9 @@ mod test_mod {
kind: Module,
description: "mod test_mod",
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -1088,6 +1152,7 @@ mod test_mod {
name: "test_foo1",
kind: Function,
},
),
]
"#]],
);
@ -1120,9 +1185,10 @@ mod root_tests {
mod nested_tests_4 {}
}
"#,
&[TestMod, TestMod, Test, Test, TestMod, Test],
expect![[r#"
[
(
TestMod,
NavigationTarget {
file_id: FileId(
0,
@ -1133,6 +1199,9 @@ mod root_tests {
kind: Module,
description: "mod nested_tests_0",
},
),
(
TestMod,
NavigationTarget {
file_id: FileId(
0,
@ -1143,6 +1212,9 @@ mod root_tests {
kind: Module,
description: "mod nested_tests_1",
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -1152,6 +1224,9 @@ mod root_tests {
name: "nested_test_11",
kind: Function,
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -1161,6 +1236,9 @@ mod root_tests {
name: "nested_test_12",
kind: Function,
},
),
(
TestMod,
NavigationTarget {
file_id: FileId(
0,
@ -1171,6 +1249,9 @@ mod root_tests {
kind: Module,
description: "mod nested_tests_2",
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -1180,6 +1261,7 @@ mod root_tests {
name: "nested_test_2",
kind: Function,
},
),
]
"#]],
);
@ -1195,9 +1277,10 @@ $0
#[cfg(feature = "foo")]
fn test_foo1() {}
"#,
&[TestMod, Test],
expect![[r#"
[
(
TestMod,
NavigationTarget {
file_id: FileId(
0,
@ -1206,6 +1289,9 @@ fn test_foo1() {}
name: "",
kind: Module,
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -1215,6 +1301,7 @@ fn test_foo1() {}
name: "test_foo1",
kind: Function,
},
),
]
"#]],
);
@ -1230,9 +1317,10 @@ $0
#[cfg(all(feature = "foo", feature = "bar"))]
fn test_foo1() {}
"#,
&[TestMod, Test],
expect![[r#"
[
(
TestMod,
NavigationTarget {
file_id: FileId(
0,
@ -1241,6 +1329,9 @@ fn test_foo1() {}
name: "",
kind: Module,
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -1250,6 +1341,7 @@ fn test_foo1() {}
name: "test_foo1",
kind: Function,
},
),
]
"#]],
);
@ -1265,7 +1357,6 @@ mod test_mod {
fn foo1() {}
}
"#,
&[],
expect![[r#"
[]
"#]],
@ -1287,9 +1378,10 @@ impl Foo {
fn foo() {}
}
"#,
&[DocTest],
expect![[r#"
[
(
DocTest,
NavigationTarget {
file_id: FileId(
1,
@ -1297,6 +1389,7 @@ impl Foo {
full_range: 27..81,
name: "foo",
},
),
]
"#]],
);
@ -1333,9 +1426,10 @@ mod tests {
gen2!();
gen_main!();
"#,
&[TestMod, TestMod, Test, Test, TestMod, Bin],
expect![[r#"
[
(
TestMod,
NavigationTarget {
file_id: FileId(
0,
@ -1344,6 +1438,9 @@ gen_main!();
name: "",
kind: Module,
},
),
(
TestMod,
NavigationTarget {
file_id: FileId(
0,
@ -1354,6 +1451,9 @@ gen_main!();
kind: Module,
description: "mod tests",
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -1362,6 +1462,9 @@ gen_main!();
name: "foo_test",
kind: Function,
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -1370,6 +1473,9 @@ gen_main!();
name: "foo_test2",
kind: Function,
},
),
(
TestMod,
NavigationTarget {
file_id: FileId(
0,
@ -1379,6 +1485,9 @@ gen_main!();
kind: Module,
description: "mod tests2",
},
),
(
Bin,
NavigationTarget {
file_id: FileId(
0,
@ -1387,6 +1496,7 @@ gen_main!();
name: "main",
kind: Function,
},
),
]
"#]],
);
@ -1412,9 +1522,10 @@ macro_rules! foo {
}
foo!();
"#,
&[Test, Test, Test, TestMod],
expect![[r#"
[
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -1423,6 +1534,9 @@ foo!();
name: "foo0",
kind: Function,
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -1431,6 +1545,9 @@ foo!();
name: "foo1",
kind: Function,
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -1439,6 +1556,9 @@ foo!();
name: "foo2",
kind: Function,
},
),
(
TestMod,
NavigationTarget {
file_id: FileId(
0,
@ -1448,6 +1568,7 @@ foo!();
kind: Module,
description: "mod foo_tests",
},
),
]
"#]],
);
@ -1466,7 +1587,6 @@ mod tests {
fn t() {}
}
"#,
&[],
expect![[r#"
[]
"#]],
@ -1486,9 +1606,10 @@ fn t0() {}
#[test]
fn t1() {}
"#,
&[TestMod],
expect![[r#"
[
(
TestMod,
NavigationTarget {
file_id: FileId(
0,
@ -1499,6 +1620,7 @@ fn t1() {}
kind: Module,
description: "mod m",
},
),
]
"#]],
);
@ -1517,9 +1639,10 @@ fn t0() {}
#[test]
fn t1() {}
"#,
&[TestMod, Test, Test],
expect![[r#"
[
(
TestMod,
NavigationTarget {
file_id: FileId(
1,
@ -1528,6 +1651,9 @@ fn t1() {}
name: "m",
kind: Module,
},
),
(
Test,
NavigationTarget {
file_id: FileId(
1,
@ -1537,6 +1663,9 @@ fn t1() {}
name: "t0",
kind: Function,
},
),
(
Test,
NavigationTarget {
file_id: FileId(
1,
@ -1546,6 +1675,7 @@ fn t1() {}
name: "t1",
kind: Function,
},
),
]
"#]],
);
@ -1566,9 +1696,10 @@ mod module {
fn t1() {}
}
"#,
&[TestMod, Test, Test],
expect![[r#"
[
(
TestMod,
NavigationTarget {
file_id: FileId(
0,
@ -1579,6 +1710,9 @@ mod module {
kind: Module,
description: "mod module",
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -1588,6 +1722,9 @@ mod module {
name: "t0",
kind: Function,
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -1597,6 +1734,7 @@ mod module {
name: "t1",
kind: Function,
},
),
]
"#]],
);
@ -1782,9 +1920,10 @@ impl<A, C, const D: u32> Data<'a, A, 12, C, D> {
fn foo() {}
}
"#,
&[Bin, DocTest],
expect![[r#"
[
(
Bin,
NavigationTarget {
file_id: FileId(
0,
@ -1794,6 +1933,9 @@ impl<A, C, const D: u32> Data<'a, A, 12, C, D> {
name: "main",
kind: Function,
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -1801,6 +1943,7 @@ impl<A, C, const D: u32> Data<'a, A, 12, C, D> {
full_range: 121..156,
name: "foo",
},
),
]
"#]],
);
@ -1830,9 +1973,10 @@ impl Foo<Foo<(), ()>, ()> {
fn t() {}
}
"#,
&[DocTest, DocTest, DocTest, DocTest],
expect![[r#"
[
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -1842,6 +1986,9 @@ impl Foo<Foo<(), ()>, ()> {
name: "impl",
kind: Impl,
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -1849,6 +1996,9 @@ impl Foo<Foo<(), ()>, ()> {
full_range: 63..101,
name: "t",
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -1858,6 +2008,9 @@ impl Foo<Foo<(), ()>, ()> {
name: "impl",
kind: Impl,
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -1865,6 +2018,7 @@ impl Foo<Foo<(), ()>, ()> {
full_range: 153..186,
name: "t",
},
),
]
"#]],
);
@ -1890,7 +2044,6 @@ macro_rules! foo {
};
}
"#,
&[],
expect![[r#"
[]
"#]],
@ -1910,9 +2063,10 @@ macro_rules! foo {
};
}
"#,
&[DocTest],
expect![[r#"
[
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -1920,6 +2074,7 @@ macro_rules! foo {
full_range: 1..94,
name: "foo",
},
),
]
"#]],
);
@ -1965,9 +2120,10 @@ mod r#mod {
impl<T> r#trait for r#struct<T> {}
}
"#,
&[TestMod, Test, DocTest, DocTest, DocTest, DocTest, DocTest, DocTest],
expect![[r#"
[
(
TestMod,
NavigationTarget {
file_id: FileId(
0,
@ -1978,6 +2134,9 @@ mod r#mod {
kind: Module,
description: "mod r#mod",
},
),
(
Test,
NavigationTarget {
file_id: FileId(
0,
@ -1987,6 +2146,9 @@ mod r#mod {
name: "r#fn",
kind: Function,
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -1995,6 +2157,9 @@ mod r#mod {
name: "r#for",
container_name: "r#mod",
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -2003,6 +2168,9 @@ mod r#mod {
name: "r#struct",
container_name: "r#mod",
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -2012,6 +2180,9 @@ mod r#mod {
name: "impl",
kind: Impl,
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -2019,6 +2190,9 @@ mod r#mod {
full_range: 216..260,
name: "r#fn",
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -2026,6 +2200,9 @@ mod r#mod {
full_range: 323..367,
name: "r#fn",
},
),
(
DocTest,
NavigationTarget {
file_id: FileId(
0,
@ -2035,6 +2212,7 @@ mod r#mod {
name: "impl",
kind: Impl,
},
),
]
"#]],
)