From 90b1395b03cad60061c2e5c49c02c8be8e701360 Mon Sep 17 00:00:00 2001 From: piotmag769 Date: Mon, 13 Jan 2025 15:58:32 +0100 Subject: [PATCH] Scarb test: removing dependency commit-id:4d859745 --- tests/e2e/scarb/scarb_toml_change.rs | 58 +++ tests/test_data/scarb/removing_dependency.txt | 357 ++++++++++++++++++ 2 files changed, 415 insertions(+) create mode 100644 tests/test_data/scarb/removing_dependency.txt diff --git a/tests/e2e/scarb/scarb_toml_change.rs b/tests/e2e/scarb/scarb_toml_change.rs index 3864a6c..d908d1e 100644 --- a/tests/e2e/scarb/scarb_toml_change.rs +++ b/tests/e2e/scarb/scarb_toml_change.rs @@ -20,6 +20,15 @@ cairo_lang_test_utils::test_file_test!( test_removing_member ); +cairo_lang_test_utils::test_file_test!( + removing_dependency, + "tests/test_data/scarb", + { + removing_dependency: "removing_dependency.txt" + }, + test_removing_dependency +); + fn caps(base: ClientCapabilities) -> ClientCapabilities { ClientCapabilities { text_document: base.text_document.or_else(Default::default), @@ -77,3 +86,52 @@ fn test_removing_member( ), ])) } + +fn test_removing_dependency( + inputs: &OrderedHashMap, + _args: &OrderedHashMap, +) -> TestRunnerResult { + let mut ls = sandbox! { + files { + "a/Scarb.toml" => &inputs["a/Scarb.toml"], + "a/src/lib.cairo" => "", + "b/Scarb.toml" => &inputs["b/Scarb.toml"], + "b/src/lib.cairo" => "", + } + client_capabilities = caps; + }; + + assert!(ls.open_and_wait_for_diagnostics("a/src/lib.cairo").diagnostics.is_empty()); + // Check if opening `a` triggers calculating diagnostics for `b`. + assert!(ls.wait_for_diagnostics("b/src/lib.cairo").diagnostics.is_empty()); + + let analyzed_crates = ls.send_request::(()); + + ls.edit_file("a/Scarb.toml", indoc! {r#" + [package] + name = "a" + version = "0.1.0" + edition = "2024_07" + "# + }); + + ls.send_notification::(DidChangeWatchedFilesParams { + changes: vec![FileEvent { + uri: ls.doc_id("a/Scarb.toml").uri, + typ: FileChangeType::CHANGED, + }], + }); + ls.wait_for_project_update(); + + // FIXME(#90): `b` should disappear from the project model - `CrateId` representing `b` + // should be removed from db.crate_configs(). + let analyzed_crates_after_dep_removal = ls.send_request::(()); + + TestRunnerResult::success(OrderedHashMap::from([ + ("Analyzed crates".to_string(), normalize(&ls, analyzed_crates)), + ( + "Analyzed crates after dependency removal".to_string(), + normalize(&ls, analyzed_crates_after_dep_removal), + ), + ])) +} diff --git a/tests/test_data/scarb/removing_dependency.txt b/tests/test_data/scarb/removing_dependency.txt new file mode 100644 index 0000000..9d33a95 --- /dev/null +++ b/tests/test_data/scarb/removing_dependency.txt @@ -0,0 +1,357 @@ +//! > Test removing dependency in Scarb project. + +//! > test_runner_name +test_removing_dependency + +//! > a/Scarb.toml +[package] +name = "a" +version = "0.1.0" +edition = "2024_07" + +[dependencies] +b = { path = "../b" } + +//! > b/Scarb.toml +[package] +name = "b" +version = "0.1.0" +edition = "2024_07" + +//! > Analyzed crates +# Analyzed Crates + +- `a`: `["[ROOT]/a/src/lib.cairo"]` + ```rust + CrateSettings { + name: Some( + "a", + ), + edition: V2024_07, + version: Some( + Version { + major: 0, + minor: 1, + patch: 0, + }, + ), + cfg_set: Some( + CfgSet( + target: "lib", + target: "test", + test, + ), + ), + dependencies: { + "a": DependencySettings { + discriminator: Some( + "a 0.1.0 (path+[ROOT_URL]a/Scarb.toml)", + ), + }, + "b": DependencySettings { + discriminator: Some( + "b 0.1.0 (path+[ROOT_URL]b/Scarb.toml)", + ), + }, + "core": DependencySettings { + discriminator: None, + }, + }, + experimental_features: ExperimentalFeaturesConfig { + negative_impls: false, + associated_item_constraints: false, + coupons: false, + }, + } + ``` +- `b`: `["[ROOT]/b/src/lib.cairo"]` + ```rust + CrateSettings { + name: Some( + "b", + ), + edition: V2024_07, + version: Some( + Version { + major: 0, + minor: 1, + patch: 0, + }, + ), + cfg_set: Some( + CfgSet( + target: "lib", + target: "test", + ), + ), + dependencies: { + "b": DependencySettings { + discriminator: Some( + "b 0.1.0 (path+[ROOT_URL]b/Scarb.toml)", + ), + }, + "core": DependencySettings { + discriminator: None, + }, + }, + experimental_features: ExperimentalFeaturesConfig { + negative_impls: false, + associated_item_constraints: false, + coupons: false, + }, + } + ``` +- `core`: `["[SCARB_REGISTRY_STD]/core/src/lib.cairo"]` + ```rust + CrateSettings { + name: Some( + "core", + ), + edition: V2024_07, + version: Some( + Version { + major: 2, + minor: 9, + patch: 2, + }, + ), + cfg_set: Some( + CfgSet( + target: "lib", + target: "test", + ), + ), + dependencies: { + "core": DependencySettings { + discriminator: None, + }, + }, + experimental_features: ExperimentalFeaturesConfig { + negative_impls: true, + associated_item_constraints: true, + coupons: true, + }, + } + ``` + +//! > Analyzed crates after member removal +# Analyzed Crates + +- `a`: `["[ROOT]/a/src/lib.cairo"]` + ```rust + CrateSettings { + name: Some( + "a", + ), + edition: V2024_07, + version: Some( + Version { + major: 0, + minor: 1, + patch: 0, + }, + ), + cfg_set: Some( + CfgSet( + target: "lib", + target: "test", + test, + ), + ), + dependencies: { + "a": DependencySettings { + discriminator: Some( + "a 0.1.0 (path+[ROOT_URL]a/Scarb.toml)", + ), + }, + "core": DependencySettings { + discriminator: None, + }, + }, + experimental_features: ExperimentalFeaturesConfig { + negative_impls: false, + associated_item_constraints: false, + coupons: false, + }, + } + ``` +- `b`: `["[ROOT]/b/src/lib.cairo"]` + ```rust + CrateSettings { + name: Some( + "b", + ), + edition: V2024_07, + version: Some( + Version { + major: 0, + minor: 1, + patch: 0, + }, + ), + cfg_set: Some( + CfgSet( + target: "lib", + target: "test", + ), + ), + dependencies: { + "b": DependencySettings { + discriminator: Some( + "b 0.1.0 (path+[ROOT_URL]b/Scarb.toml)", + ), + }, + "core": DependencySettings { + discriminator: None, + }, + }, + experimental_features: ExperimentalFeaturesConfig { + negative_impls: false, + associated_item_constraints: false, + coupons: false, + }, + } + ``` +- `core`: `["[SCARB_REGISTRY_STD]/core/src/lib.cairo"]` + ```rust + CrateSettings { + name: Some( + "core", + ), + edition: V2024_07, + version: Some( + Version { + major: 2, + minor: 9, + patch: 2, + }, + ), + cfg_set: Some( + CfgSet( + target: "lib", + target: "test", + ), + ), + dependencies: { + "core": DependencySettings { + discriminator: None, + }, + }, + experimental_features: ExperimentalFeaturesConfig { + negative_impls: true, + associated_item_constraints: true, + coupons: true, + }, + } + ``` + +//! > Analyzed crates after dependency removal +# Analyzed Crates + +- `a`: `["[ROOT]/a/src/lib.cairo"]` + ```rust + CrateSettings { + name: Some( + "a", + ), + edition: V2024_07, + version: Some( + Version { + major: 0, + minor: 1, + patch: 0, + }, + ), + cfg_set: Some( + CfgSet( + target: "lib", + target: "test", + test, + ), + ), + dependencies: { + "a": DependencySettings { + discriminator: Some( + "a 0.1.0 (path+[ROOT_URL]a/Scarb.toml)", + ), + }, + "core": DependencySettings { + discriminator: None, + }, + }, + experimental_features: ExperimentalFeaturesConfig { + negative_impls: false, + associated_item_constraints: false, + coupons: false, + }, + } + ``` +- `b`: `["[ROOT]/b/src/lib.cairo"]` + ```rust + CrateSettings { + name: Some( + "b", + ), + edition: V2024_07, + version: Some( + Version { + major: 0, + minor: 1, + patch: 0, + }, + ), + cfg_set: Some( + CfgSet( + target: "lib", + target: "test", + ), + ), + dependencies: { + "b": DependencySettings { + discriminator: Some( + "b 0.1.0 (path+[ROOT_URL]b/Scarb.toml)", + ), + }, + "core": DependencySettings { + discriminator: None, + }, + }, + experimental_features: ExperimentalFeaturesConfig { + negative_impls: false, + associated_item_constraints: false, + coupons: false, + }, + } + ``` +- `core`: `["[SCARB_REGISTRY_STD]/core/src/lib.cairo"]` + ```rust + CrateSettings { + name: Some( + "core", + ), + edition: V2024_07, + version: Some( + Version { + major: 2, + minor: 9, + patch: 2, + }, + ), + cfg_set: Some( + CfgSet( + target: "lib", + target: "test", + ), + ), + dependencies: { + "core": DependencySettings { + discriminator: None, + }, + }, + experimental_features: ExperimentalFeaturesConfig { + negative_impls: true, + associated_item_constraints: true, + coupons: true, + }, + } + ```