Make test cases simpler

This commit is contained in:
Ali Bektas 2023-11-23 02:08:30 +01:00
parent f79e8182c1
commit 736994f026
4 changed files with 48 additions and 138 deletions

View File

@ -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) {

View File

@ -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());
}

View File

@ -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
}

View File

@ -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
}