about summary refs log tree commit diff
diff options
context:
space:
mode:
authorlucasholten <lucasholten@dreamsolution.nl>2025-01-02 15:52:06 +0100
committerlucasholten <lucasholten@dreamsolution.nl>2025-01-02 15:52:06 +0100
commit943ee02ee924703640e5386de06c5f616b004c35 (patch)
tree208d105ab516da2fd37d6220f45e978d98320d38
parent4485cbb0d42de605fd09a922d1a3a8b174af9839 (diff)
Remove rust-analyzer duplicate crates integration tests
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/tests/crate_graph.rs126
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/tests/test_data/deduplication_crate_graph_A.json140
-rw-r--r--src/tools/rust-analyzer/crates/rust-analyzer/tests/test_data/deduplication_crate_graph_B.json66
3 files changed, 0 insertions, 332 deletions
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/crate_graph.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/crate_graph.rs
deleted file mode 100644
index e2a0fdf61e1..00000000000
--- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/crate_graph.rs
+++ /dev/null
@@ -1,126 +0,0 @@
-use std::path::PathBuf;
-
-use project_model::{
-    CargoWorkspace, ManifestPath, Metadata, ProjectWorkspace, ProjectWorkspaceKind, Sysroot,
-    SysrootQueryMetadata, WorkspaceBuildScripts,
-};
-use rust_analyzer::ws_to_crate_graph;
-use rustc_hash::FxHashMap;
-use serde::de::DeserializeOwned;
-use vfs::{AbsPathBuf, FileId};
-
-fn load_cargo_with_fake_sysroot(file: &str) -> ProjectWorkspace {
-    let meta: Metadata = get_test_json_file(file);
-    let manifest_path =
-        ManifestPath::try_from(AbsPathBuf::try_from(meta.workspace_root.clone()).unwrap()).unwrap();
-    let cargo_workspace = CargoWorkspace::new(meta, manifest_path, Default::default());
-    ProjectWorkspace {
-        kind: ProjectWorkspaceKind::Cargo {
-            cargo: cargo_workspace,
-            build_scripts: WorkspaceBuildScripts::default(),
-            rustc: Err(None),
-            error: None,
-            set_test: true,
-        },
-        sysroot: get_fake_sysroot(),
-        rustc_cfg: Vec::new(),
-        cfg_overrides: Default::default(),
-        toolchain: None,
-        target_layout: Err("target_data_layout not loaded".into()),
-    }
-}
-
-fn get_test_json_file<T: DeserializeOwned>(file: &str) -> T {
-    let base = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
-    let file = base.join("tests/test_data").join(file);
-    let data = std::fs::read_to_string(file).unwrap();
-    let mut json = data.parse::<serde_json::Value>().unwrap();
-    fixup_paths(&mut json);
-    return serde_json::from_value(json).unwrap();
-
-    fn fixup_paths(val: &mut serde_json::Value) {
-        match val {
-            serde_json::Value::String(s) => replace_root(s, true),
-            serde_json::Value::Array(vals) => vals.iter_mut().for_each(fixup_paths),
-            serde_json::Value::Object(kvals) => kvals.values_mut().for_each(fixup_paths),
-            serde_json::Value::Null | serde_json::Value::Bool(_) | serde_json::Value::Number(_) => {
-            }
-        }
-    }
-}
-
-fn replace_root(s: &mut String, direction: bool) {
-    if direction {
-        let root = if cfg!(windows) { r#"C:\\ROOT\"# } else { "/ROOT/" };
-        *s = s.replace("$ROOT$", root)
-    } else {
-        let root = if cfg!(windows) { r#"C:\\\\ROOT\\"# } else { "/ROOT/" };
-        *s = s.replace(root, "$ROOT$")
-    }
-}
-
-fn get_fake_sysroot_path() -> PathBuf {
-    let base = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
-    base.join("../project-model/test_data/fake-sysroot")
-}
-
-fn get_fake_sysroot() -> Sysroot {
-    let sysroot_path = get_fake_sysroot_path();
-    // there's no `libexec/` directory with a `proc-macro-srv` binary in that
-    // fake sysroot, so we give them both the same path:
-    let sysroot_dir = AbsPathBuf::assert_utf8(sysroot_path);
-    let sysroot_src_dir = sysroot_dir.clone();
-    Sysroot::load(Some(sysroot_dir), Some(sysroot_src_dir), &SysrootQueryMetadata::None)
-}
-
-#[test]
-fn test_deduplicate_origin_dev() {
-    let path_map = &mut FxHashMap::default();
-    let ws = load_cargo_with_fake_sysroot("deduplication_crate_graph_A.json");
-    let ws2 = load_cargo_with_fake_sysroot("deduplication_crate_graph_B.json");
-
-    let (crate_graph, ..) = ws_to_crate_graph(&[ws, ws2], &Default::default(), |path| {
-        let len = path_map.len();
-        Some(*path_map.entry(path.to_path_buf()).or_insert(FileId::from_raw(len as u32)))
-    });
-
-    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() == "p2" {
-                crates_named_p2.push(krate);
-            }
-        }
-    }
-
-    assert_eq!(crates_named_p2.len(), 1);
-    let p2 = crates_named_p2[0];
-    assert!(p2.origin.is_local());
-}
-
-#[test]
-fn test_deduplicate_origin_dev_rev() {
-    let path_map = &mut FxHashMap::default();
-    let ws = load_cargo_with_fake_sysroot("deduplication_crate_graph_B.json");
-    let ws2 = load_cargo_with_fake_sysroot("deduplication_crate_graph_A.json");
-
-    let (crate_graph, ..) = ws_to_crate_graph(&[ws, ws2], &Default::default(), |path| {
-        let len = path_map.len();
-        Some(*path_map.entry(path.to_path_buf()).or_insert(FileId::from_raw(len as u32)))
-    });
-
-    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() == "p2" {
-                crates_named_p2.push(krate);
-            }
-        }
-    }
-
-    assert_eq!(crates_named_p2.len(), 1);
-    let p2 = crates_named_p2[0];
-    assert!(p2.origin.is_local());
-}
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/test_data/deduplication_crate_graph_A.json b/src/tools/rust-analyzer/crates/rust-analyzer/tests/test_data/deduplication_crate_graph_A.json
deleted file mode 100644
index b0fb5845cef..00000000000
--- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/test_data/deduplication_crate_graph_A.json
+++ /dev/null
@@ -1,140 +0,0 @@
-{
-  "packages": [
-    {
-      "name": "p1",
-      "version": "0.1.0",
-      "id": "p1 0.1.0 (path+file:///example_project/p1)",
-      "license": null,
-      "license_file": null,
-      "description": null,
-      "source": null,
-      "dependencies": [
-        {
-          "name": "p2",
-          "source": null,
-          "req": "*",
-          "kind": null,
-          "rename": null,
-          "optional": false,
-          "uses_default_features": true,
-          "features": [],
-          "target": null,
-          "registry": null,
-          "path": "$ROOT$example_project/p2"
-        }
-      ],
-      "targets": [
-        {
-          "kind": [
-            "lib"
-          ],
-          "crate_types": [
-            "lib"
-          ],
-          "name": "p1",
-          "src_path": "$ROOT$example_project/p1/src/lib.rs",
-          "edition": "2021",
-          "doc": true,
-          "doctest": true,
-          "test": true
-        }
-      ],
-      "features": {},
-      "manifest_path": "$ROOT$example_project/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:///example_project/p2)",
-      "license": null,
-      "license_file": null,
-      "description": null,
-      "source": null,
-      "dependencies": [],
-      "targets": [
-        {
-          "kind": [
-            "lib"
-          ],
-          "crate_types": [
-            "lib"
-          ],
-          "name": "p2",
-          "src_path": "$ROOT$example_project/p2/src/lib.rs",
-          "edition": "2021",
-          "doc": true,
-          "doctest": true,
-          "test": true
-        }
-      ],
-      "features": {},
-      "manifest_path": "$ROOT$example_project/p2/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
-    }
-  ],
-  "workspace_members": [
-    "p1 0.1.0 (path+file:///example_project/p1)"
-  ],
-  "workspace_default_members": [
-    "p1 0.1.0 (path+file:///example_project/p1)"
-  ],
-  "resolve": {
-    "nodes": [
-      {
-        "id": "p1 0.1.0 (path+file:///example_project/p1)",
-        "dependencies": [
-          "p2 0.1.0 (path+file:///example_project/p2)"
-        ],
-        "deps": [
-          {
-            "name": "p2",
-            "pkg": "p2 0.1.0 (path+file:///example_project/p2)",
-            "dep_kinds": [
-              {
-                "kind": null,
-                "target": null
-              }
-            ]
-          }
-        ],
-        "features": []
-      },
-      {
-        "id": "p2 0.1.0 (path+file:///example_project/p2)",
-        "dependencies": [],
-        "deps": [],
-        "features": []
-      }
-    ],
-    "root": "p1 0.1.0 (path+file:///example_project/p1)"
-  },
-  "target_directory": "$ROOT$example_project/p1/target",
-  "version": 1,
-  "workspace_root": "$ROOT$example_project/p1",
-  "metadata": null
-}
\ No newline at end of file
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/test_data/deduplication_crate_graph_B.json b/src/tools/rust-analyzer/crates/rust-analyzer/tests/test_data/deduplication_crate_graph_B.json
deleted file mode 100644
index b5d1e16e62e..00000000000
--- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/test_data/deduplication_crate_graph_B.json
+++ /dev/null
@@ -1,66 +0,0 @@
-{
-  "packages": [
-    {
-      "name": "p2",
-      "version": "0.1.0",
-      "id": "p2 0.1.0 (path+file:///example_project/p2)",
-      "license": null,
-      "license_file": null,
-      "description": null,
-      "source": null,
-      "dependencies": [],
-      "targets": [
-        {
-          "kind": [
-            "lib"
-          ],
-          "crate_types": [
-            "lib"
-          ],
-          "name": "p2",
-          "src_path": "$ROOT$example_project/p2/src/lib.rs",
-          "edition": "2021",
-          "doc": true,
-          "doctest": true,
-          "test": true
-        }
-      ],
-      "features": {},
-      "manifest_path": "$ROOT$example_project/p2/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
-    }
-  ],
-  "workspace_members": [
-    "p2 0.1.0 (path+file:///example_project/p2)"
-  ],
-  "workspace_default_members": [
-    "p2 0.1.0 (path+file:///example_project/p2)"
-  ],
-  "resolve": {
-    "nodes": [
-      {
-        "id": "p2 0.1.0 (path+file:///example_project/p2)",
-        "dependencies": [],
-        "deps": [],
-        "features": []
-      }
-    ],
-    "root": "p2 0.1.0 (path+file:///example_project/p2)"
-  },
-  "target_directory": "$ROOT$example_project/p2/target",
-  "version": 1,
-  "workspace_root": "$ROOT$example_project/p2",
-  "metadata": null
-}
\ No newline at end of file