feat(adapter): add path field for server v0.1.10

This commit is contained in:
kbwo 2024-12-25 23:34:31 +09:00
parent a766099b76
commit 855d2c0094
8 changed files with 50 additions and 9 deletions

View file

@ -136,6 +136,7 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
let test_items: Vec<TestItem> = vec![TestItem {
id: "rocks::dependency::tests::parse_dependency".to_string(),
name: "rocks::dependency::tests::parse_dependency".to_string(),
path: "/home/example/projects/rocks-lib/src/rocks/dependency.rs".to_string(),
start_position: Range {
start: Position {
line: 85,

View file

@ -131,6 +131,7 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
let test_items: Vec<TestItem> = vec![TestItem {
id: "rocks::dependency::tests::parse_dependency".to_string(),
name: "rocks::dependency::tests::parse_dependency".to_string(),
path: "/home/example/projects/rocks-lib/src/rocks/dependency.rs".to_string(),
start_position: Range {
start: Position {
line: 85,

View file

@ -263,6 +263,7 @@ mod tests {
TestItem {
id: String::from("addTest"),
name: String::from("addTest"),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 7,
@ -287,6 +288,7 @@ mod tests {
TestItem {
id: String::from("fail1"),
name: String::from("fail1"),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 11,
@ -311,6 +313,7 @@ mod tests {
TestItem {
id: String::from("fail2"),
name: String::from("fail2"),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 15,

View file

@ -261,6 +261,7 @@ mod tests {
vec![TestItem {
id: String::from("index::fail"),
name: String::from("index::fail"),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 1,

View file

@ -270,6 +270,7 @@ mod tests {
TestItem {
id: "synchronous passing test".to_string(),
name: "synchronous passing test".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 5,
@ -294,6 +295,7 @@ mod tests {
TestItem {
id: "synchronous failing test".to_string(),
name: "synchronous failing test".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 10,
@ -318,6 +320,7 @@ mod tests {
TestItem {
id: "asynchronous passing test".to_string(),
name: "asynchronous passing test".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 15,
@ -342,6 +345,7 @@ mod tests {
TestItem {
id: "asynchronous failing test".to_string(),
name: "asynchronous failing test".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 21,
@ -366,6 +370,7 @@ mod tests {
TestItem {
id: "failing test using Promises".to_string(),
name: "failing test using Promises".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 27,
@ -390,6 +395,7 @@ mod tests {
TestItem {
id: "callback passing test".to_string(),
name: "callback passing test".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 36,
@ -414,6 +420,7 @@ mod tests {
TestItem {
id: "callback failing test".to_string(),
name: "callback failing test".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 42,
@ -438,6 +445,7 @@ mod tests {
TestItem {
id: "top level test".to_string(),
name: "top level test".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 51,
@ -462,6 +470,7 @@ mod tests {
TestItem {
id: "skip option".to_string(),
name: "skip option".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 63,
@ -486,6 +495,7 @@ mod tests {
TestItem {
id: "skip option with message".to_string(),
name: "skip option with message".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 68,
@ -510,6 +520,7 @@ mod tests {
TestItem {
id: "skip() method".to_string(),
name: "skip() method".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 72,
@ -534,6 +545,7 @@ mod tests {
TestItem {
id: "skip() method with message".to_string(),
name: "skip() method with message".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 77,
@ -558,6 +570,7 @@ mod tests {
TestItem {
id: "todo option".to_string(),
name: "todo option".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 84,
@ -582,6 +595,7 @@ mod tests {
TestItem {
id: "todo option with message".to_string(),
name: "todo option with message".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 90,
@ -606,6 +620,7 @@ mod tests {
TestItem {
id: "todo() method".to_string(),
name: "todo() method".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 94,
@ -630,6 +645,7 @@ mod tests {
TestItem {
id: "todo() method with message".to_string(),
name: "todo() method with message".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 98,
@ -654,6 +670,7 @@ mod tests {
TestItem {
id: "A thing::should work".to_string(),
name: "A thing::should work".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 105,
@ -678,6 +695,7 @@ mod tests {
TestItem {
id: "A thing::should be ok".to_string(),
name: "A thing::should be ok".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 109,
@ -702,6 +720,7 @@ mod tests {
TestItem {
id: "A thing::a nested thing::should work".to_string(),
name: "A thing::a nested thing::should work".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 114,
@ -726,6 +745,7 @@ mod tests {
TestItem {
id: "only: this test is run".to_string(),
name: "only: this test is run".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 123,
@ -750,6 +770,7 @@ mod tests {
TestItem {
id: "only: this test is not run".to_string(),
name: "only: this test is not run".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 142,
@ -774,6 +795,7 @@ mod tests {
TestItem {
id: "A suite::this test is run A ".to_string(),
name: "A suite::this test is run A ".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 149,
@ -798,6 +820,7 @@ mod tests {
TestItem {
id: "A suite::this test is not run B".to_string(),
name: "A suite::this test is not run B".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 153,
@ -822,6 +845,7 @@ mod tests {
TestItem {
id: "this test is run C".to_string(),
name: "this test is run C".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 161,
@ -846,6 +870,7 @@ mod tests {
TestItem {
id: "this test is run D".to_string(),
name: "this test is run D".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 165,
@ -870,6 +895,7 @@ mod tests {
TestItem {
id: "import from external file. this must be fail".to_string(),
name: "import from external file. this must be fail".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 170,

View file

@ -240,6 +240,7 @@ mod tests {
TestItem {
id: "CalculatorTest::testAdd".to_string(),
name: "CalculatorTest::testAdd".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 9,
@ -264,6 +265,7 @@ mod tests {
TestItem {
id: "CalculatorTest::testSubtract".to_string(),
name: "CalculatorTest::testSubtract".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 16,
@ -288,6 +290,7 @@ mod tests {
TestItem {
id: "CalculatorTest::testFail1".to_string(),
name: "CalculatorTest::testFail1".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 23,

View file

@ -240,6 +240,7 @@ pub fn discover_with_treesitter(
let test_item = TestItem {
id: test_id.clone(),
name: test_id,
path: file_path.to_string(),
start_position: Range {
start: Position {
line: test_start_position.row as u32,
@ -293,18 +294,21 @@ pub fn parse_cargo_diagnostics(
// relaive path
let relative_file_path = m.get(2).unwrap().as_str().to_string();
// name of the file without extension
let file_stem = Path::new(&relative_file_path)
.file_stem()
.unwrap()
.to_str()
.unwrap();
let executed_test_id = id_with_file.replace(&(file_stem.to_string() + "::"), "");
if let Some(file_path) = file_paths.iter().find(|path| {
path.contains(workspace_root.join(&relative_file_path).to_str().unwrap())
}) {
let matched_test_item = test_items.iter().find(|item| item.id == executed_test_id);
let matched_test_item = test_items.iter().find(|item| {
let item_path = item.path.strip_prefix(workspace_root.to_str().unwrap()).unwrap_or(&item.path);
let item_path = item_path.strip_suffix(".rs").unwrap_or(item_path);
let item_path = item_path.replace('/', "::")
.replace("::src::lib", "")
.replace("::src::main", "")
.replace("::src::", "");
let exact_id = format!("{}::{}", item_path, item.id);
tracing::info!("DEBUGPRINT[7]: util.rs:301: item_path={:#?}, exact_id={:#?}, id_with_file={:#?}", item_path, exact_id, id_with_file);
exact_id == id_with_file
});
let lnum = m.get(3).unwrap().as_str().parse::<u32>().unwrap() - 1;
let col = m.get(4).unwrap().as_str().parse::<u32>().unwrap() - 1;
@ -358,7 +362,7 @@ pub fn parse_cargo_diagnostics(
..Diagnostic::default()
};
result_map
.entry(file_path.to_string())
.entry(test_item.path.to_string())
.or_default()
.push(diagnostic);
}

View file

@ -213,6 +213,7 @@ mod tests {
TestItem {
id: "describe text::pass".to_string(),
name: "describe text::pass".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 4,
@ -237,6 +238,7 @@ mod tests {
TestItem {
id: "describe text::fail".to_string(),
name: "describe text::fail".to_string(),
path: file_path.to_string(),
start_position: Range {
start: Position {
line: 8,