Skip to content

Commit

Permalink
Make test cases simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
alibektas committed Nov 23, 2023
1 parent f79e818 commit be91d95
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 138 deletions.
2 changes: 1 addition & 1 deletion crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
32 changes: 15 additions & 17 deletions crates/project-model/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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());
}
44 changes: 22 additions & 22 deletions crates/project-model/test_data/deduplication_crate_graph_A.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -32,15 +32,15 @@
"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,
"test": true
}
],
"features": {},
"manifest_path": "/path/to/project/example_project/projects/p1/Cargo.toml",
"manifest_path": "/example_project/p1/Cargo.toml",
"metadata": null,
"publish": null,
"authors": [],
Expand All @@ -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,
Expand All @@ -72,16 +72,16 @@
"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,
"test": true
}
],
"features": {},
"manifest_path": "/path/to/project/example_project/projects/p3/Cargo.toml",
"manifest_path": "/example_project/p2/Cargo.toml",
"metadata": null,
"publish": null,
"authors": [],
Expand All @@ -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
}
]
Expand All @@ -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
}
108 changes: 10 additions & 98 deletions crates/project-model/test_data/deduplication_crate_graph_B.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -87,15 +18,15 @@
"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,
"test": true
}
],
"features": {},
"manifest_path": "/path/to/project/example_project/projects/p2/Cargo.toml",
"manifest_path": "/example_project/p2/Cargo.toml",
"metadata": null,
"publish": null,
"authors": [],
Expand All @@ -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
}

0 comments on commit be91d95

Please sign in to comment.