From 736994f02664aa4cd84f55be481aae33bcf48ca3 Mon Sep 17 00:00:00 2001 From: Ali Bektas Date: Thu, 23 Nov 2023 02:08:30 +0100 Subject: [PATCH] Make test cases simpler --- crates/base-db/src/input.rs | 2 +- crates/project-model/src/tests.rs | 32 +++--- .../deduplication_crate_graph_A.json | 44 +++---- .../deduplication_crate_graph_B.json | 108 ++---------------- 4 files changed, 48 insertions(+), 138 deletions(-) diff --git a/crates/base-db/src/input.rs b/crates/base-db/src/input.rs index 82149892bd6..e4f78321e21 100644 --- a/crates/base-db/src/input.rs +++ b/crates/base-db/src/input.rs @@ -668,7 +668,7 @@ impl CrateGraph { // If the origins differ, check if the two crates are equal without // considering the dev dependencies, if they are, they most likely are in // different loaded workspaces which may cause issues. We keep the local - // version and discard the library one as the local version may have + // version and discard the library one as the local version may have // dev-dependencies that we want to keep resolving. See #15656 for more // information. if data.eq_ignoring_origin_and_deps(&crate_data, true) { diff --git a/crates/project-model/src/tests.rs b/crates/project-model/src/tests.rs index 35ac80eee32..98f3063bb98 100644 --- a/crates/project-model/src/tests.rs +++ b/crates/project-model/src/tests.rs @@ -3,7 +3,7 @@ use std::{ path::{Path, PathBuf}, }; -use base_db::{CrateGraph, DependencyKind, FileId, ProcMacroPaths}; +use base_db::{CrateGraph, FileId, ProcMacroPaths}; use cfg::{CfgAtom, CfgDiff}; use expect_test::{expect_file, ExpectFile}; use paths::{AbsPath, AbsPathBuf}; @@ -251,7 +251,7 @@ fn crate_graph_dedup() { } #[test] -fn test_deduplicate_crate_differing_in_origin() { +fn test_deduplicate_origin_dev() { let path_map = &mut Default::default(); let (mut crate_graph, _proc_macros) = load_cargo_with_sysroot(path_map, "deduplication_crate_graph_A.json"); @@ -261,24 +261,23 @@ fn test_deduplicate_crate_differing_in_origin() { crate_graph.extend(crate_graph_1, &mut _proc_macros_2); - let mut crates_named_p1 = vec![]; + let mut crates_named_p2 = vec![]; for id in crate_graph.iter() { let krate = &crate_graph[id]; if let Some(name) = krate.display_name.as_ref() { - if name.to_string() == "p1" { - crates_named_p1.push(krate); + if name.to_string() == "p2" { + crates_named_p2.push(krate); } } } - assert!(crates_named_p1.len() == 1); - let p1 = crates_named_p1[0]; - assert!(p1.dependencies.iter().filter(|dep| dep.kind() == DependencyKind::Dev).count() == 1); - assert!(p1.origin.is_local()); + assert!(crates_named_p2.len() == 1); + let p2 = crates_named_p2[0]; + assert!(p2.origin.is_local()); } #[test] -fn test_deduplicate_crate_differing_in_origin_in_rev_resolution_order() { +fn test_deduplicate_origin_dev_rev() { let path_map = &mut Default::default(); let (mut crate_graph, _proc_macros) = load_cargo_with_sysroot(path_map, "deduplication_crate_graph_B.json"); @@ -288,18 +287,17 @@ fn test_deduplicate_crate_differing_in_origin_in_rev_resolution_order() { crate_graph.extend(crate_graph_1, &mut _proc_macros_2); - let mut crates_named_p1 = vec![]; + let mut crates_named_p2 = vec![]; for id in crate_graph.iter() { let krate = &crate_graph[id]; if let Some(name) = krate.display_name.as_ref() { - if name.to_string() == "p1" { - crates_named_p1.push(krate); + if name.to_string() == "p2" { + crates_named_p2.push(krate); } } } - assert!(crates_named_p1.len() == 1); - let p1 = crates_named_p1[0]; - assert!(p1.dependencies.iter().filter(|dep| dep.kind() == DependencyKind::Dev).count() == 1); - assert!(p1.origin.is_local()); + assert!(crates_named_p2.len() == 1); + let p2 = crates_named_p2[0]; + assert!(p2.origin.is_local()); } diff --git a/crates/project-model/test_data/deduplication_crate_graph_A.json b/crates/project-model/test_data/deduplication_crate_graph_A.json index edaf185fc61..66bfcb2bf6e 100644 --- a/crates/project-model/test_data/deduplication_crate_graph_A.json +++ b/crates/project-model/test_data/deduplication_crate_graph_A.json @@ -3,24 +3,24 @@ { "name": "p1", "version": "0.1.0", - "id": "p1 0.1.0 (path+file:///path/to/project/example_project/projects/p1)", + "id": "p1 0.1.0 (path+file:///example_project/p1)", "license": null, "license_file": null, "description": null, "source": null, "dependencies": [ { - "name": "p3", + "name": "p2", "source": null, "req": "*", - "kind": "dev", + "kind": null, "rename": null, "optional": false, "uses_default_features": true, "features": [], "target": null, "registry": null, - "path": "/path/to/project/example_project/projects/p3" + "path": "/example_project/p2" } ], "targets": [ @@ -32,7 +32,7 @@ "lib" ], "name": "p1", - "src_path": "/path/to/project/example_project/projects/p1/src/lib.rs", + "src_path": "/example_project/p1/src/lib.rs", "edition": "2021", "doc": true, "doctest": true, @@ -40,7 +40,7 @@ } ], "features": {}, - "manifest_path": "/path/to/project/example_project/projects/p1/Cargo.toml", + "manifest_path": "/example_project/p1/Cargo.toml", "metadata": null, "publish": null, "authors": [], @@ -56,9 +56,9 @@ "rust_version": null }, { - "name": "p3", + "name": "p2", "version": "0.1.0", - "id": "p3 0.1.0 (path+file:///path/to/project/example_project/projects/p3)", + "id": "p2 0.1.0 (path+file:///example_project/p2)", "license": null, "license_file": null, "description": null, @@ -72,8 +72,8 @@ "crate_types": [ "lib" ], - "name": "p3", - "src_path": "/path/to/project/example_project/projects/p3/src/lib.rs", + "name": "p2", + "src_path": "/example_project/p2/src/lib.rs", "edition": "2021", "doc": true, "doctest": true, @@ -81,7 +81,7 @@ } ], "features": {}, - "manifest_path": "/path/to/project/example_project/projects/p3/Cargo.toml", + "manifest_path": "/example_project/p2/Cargo.toml", "metadata": null, "publish": null, "authors": [], @@ -98,25 +98,25 @@ } ], "workspace_members": [ - "p1 0.1.0 (path+file:///path/to/project/example_project/projects/p1)" + "p1 0.1.0 (path+file:///example_project/p1)" ], "workspace_default_members": [ - "p1 0.1.0 (path+file:///path/to/project/example_project/projects/p1)" + "p1 0.1.0 (path+file:///example_project/p1)" ], "resolve": { "nodes": [ { - "id": "p1 0.1.0 (path+file:///path/to/project/example_project/projects/p1)", + "id": "p1 0.1.0 (path+file:///example_project/p1)", "dependencies": [ - "p3 0.1.0 (path+file:///path/to/project/example_project/projects/p3)" + "p2 0.1.0 (path+file:///example_project/p2)" ], "deps": [ { - "name": "p3", - "pkg": "p3 0.1.0 (path+file:///path/to/project/example_project/projects/p3)", + "name": "p2", + "pkg": "p2 0.1.0 (path+file:///example_project/p2)", "dep_kinds": [ { - "kind": "dev", + "kind": null, "target": null } ] @@ -125,16 +125,16 @@ "features": [] }, { - "id": "p3 0.1.0 (path+file:///path/to/project/example_project/projects/p3)", + "id": "p2 0.1.0 (path+file:///example_project/p2)", "dependencies": [], "deps": [], "features": [] } ], - "root": "p1 0.1.0 (path+file:///path/to/project/example_project/projects/p1)" + "root": "p1 0.1.0 (path+file:///example_project/p1)" }, - "target_directory": "/path/to/project/example_project/projects/p1/target", + "target_directory": "/example_project/p1/target", "version": 1, - "workspace_root": "/path/to/project/example_project/projects/p1", + "workspace_root": "/example_project/p1", "metadata": null } \ No newline at end of file diff --git a/crates/project-model/test_data/deduplication_crate_graph_B.json b/crates/project-model/test_data/deduplication_crate_graph_B.json index 4f753db71bf..6e67da7eae1 100644 --- a/crates/project-model/test_data/deduplication_crate_graph_B.json +++ b/crates/project-model/test_data/deduplication_crate_graph_B.json @@ -1,83 +1,14 @@ { "packages": [ - { - "name": "p1", - "version": "0.1.0", - "id": "p1 0.1.0 (path+file:///path/to/project/example_project/projects/p1)", - "license": null, - "license_file": null, - "description": null, - "source": null, - "dependencies": [ - { - "name": "p3", - "source": null, - "req": "*", - "kind": "dev", - "rename": null, - "optional": false, - "uses_default_features": true, - "features": [], - "target": null, - "registry": null, - "path": "/path/to/project/example_project/projects/p3" - } - ], - "targets": [ - { - "kind": [ - "lib" - ], - "crate_types": [ - "lib" - ], - "name": "p1", - "src_path": "/path/to/project/example_project/projects/p1/src/lib.rs", - "edition": "2021", - "doc": true, - "doctest": true, - "test": true - } - ], - "features": {}, - "manifest_path": "/path/to/project/example_project/projects/p1/Cargo.toml", - "metadata": null, - "publish": null, - "authors": [], - "categories": [], - "keywords": [], - "readme": null, - "repository": null, - "homepage": null, - "documentation": null, - "edition": "2021", - "links": null, - "default_run": null, - "rust_version": null - }, { "name": "p2", "version": "0.1.0", - "id": "p2 0.1.0 (path+file:///path/to/project/example_project/projects/p2)", + "id": "p2 0.1.0 (path+file:///example_project/p2)", "license": null, "license_file": null, "description": null, "source": null, - "dependencies": [ - { - "name": "p1", - "source": null, - "req": "*", - "kind": null, - "rename": null, - "optional": false, - "uses_default_features": true, - "features": [], - "target": null, - "registry": null, - "path": "/path/to/project/example_project/projects/p1" - } - ], + "dependencies": [], "targets": [ { "kind": [ @@ -87,7 +18,7 @@ "lib" ], "name": "p2", - "src_path": "/path/to/project/example_project/projects/p2/src/lib.rs", + "src_path": "/example_project/p2/src/lib.rs", "edition": "2021", "doc": true, "doctest": true, @@ -95,7 +26,7 @@ } ], "features": {}, - "manifest_path": "/path/to/project/example_project/projects/p2/Cargo.toml", + "manifest_path": "/example_project/p2/Cargo.toml", "metadata": null, "publish": null, "authors": [], @@ -112,43 +43,24 @@ } ], "workspace_members": [ - "p2 0.1.0 (path+file:///path/to/project/example_project/projects/p2)" + "p2 0.1.0 (path+file:///example_project/p2)" ], "workspace_default_members": [ - "p2 0.1.0 (path+file:///path/to/project/example_project/projects/p2)" + "p2 0.1.0 (path+file:///example_project/p2)" ], "resolve": { "nodes": [ { - "id": "p1 0.1.0 (path+file:///path/to/project/example_project/projects/p1)", + "id": "p2 0.1.0 (path+file:///example_project/p2)", "dependencies": [], "deps": [], "features": [] - }, - { - "id": "p2 0.1.0 (path+file:///path/to/project/example_project/projects/p2)", - "dependencies": [ - "p1 0.1.0 (path+file:///path/to/project/example_project/projects/p1)" - ], - "deps": [ - { - "name": "p1", - "pkg": "p1 0.1.0 (path+file:///path/to/project/example_project/projects/p1)", - "dep_kinds": [ - { - "kind": null, - "target": null - } - ] - } - ], - "features": [] } ], - "root": "p2 0.1.0 (path+file:///path/to/project/example_project/projects/p2)" + "root": "p2 0.1.0 (path+file:///example_project/p2)" }, - "target_directory": "/path/to/project/example_project/projects/p2/target", + "target_directory": "/example_project/p2/target", "version": 1, - "workspace_root": "/path/to/project/example_project/projects/p2", + "workspace_root": "/example_project/p2", "metadata": null } \ No newline at end of file