From 22cf3e323f48720d5f080af43d7f59cca52bf4f9 Mon Sep 17 00:00:00 2001 From: piotmag769 Date: Mon, 13 Jan 2025 15:51:24 +0100 Subject: [PATCH] Scarb test simple deps commit-id:934fb368 --- tests/e2e/main.rs | 1 + tests/e2e/scarb/mod.rs | 1 + tests/e2e/scarb/simple_deps.rs | 46 ++++++++ tests/e2e/support/fixture.rs | 2 +- tests/test_data/scarb/simple_deps.txt | 154 ++++++++++++++++++++++++++ 5 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 tests/e2e/scarb/mod.rs create mode 100644 tests/e2e/scarb/simple_deps.rs create mode 100644 tests/test_data/scarb/simple_deps.txt diff --git a/tests/e2e/main.rs b/tests/e2e/main.rs index c0104873..275599ec 100644 --- a/tests/e2e/main.rs +++ b/tests/e2e/main.rs @@ -5,6 +5,7 @@ mod goto_definition; mod hover; mod macro_expand; mod references; +mod scarb; mod semantic_tokens; mod support; mod workspace_configuration; diff --git a/tests/e2e/scarb/mod.rs b/tests/e2e/scarb/mod.rs new file mode 100644 index 00000000..4d1d35a9 --- /dev/null +++ b/tests/e2e/scarb/mod.rs @@ -0,0 +1 @@ +mod simple_deps; diff --git a/tests/e2e/scarb/simple_deps.rs b/tests/e2e/scarb/simple_deps.rs new file mode 100644 index 00000000..2c424c8b --- /dev/null +++ b/tests/e2e/scarb/simple_deps.rs @@ -0,0 +1,46 @@ +use cairo_lang_test_utils::parse_test_file::TestRunnerResult; +use cairo_lang_utils::ordered_hash_map::OrderedHashMap; +use cairo_language_server::lsp; +use lsp_types::NumberOrString; + +use crate::support::normalize::normalize; +use crate::support::sandbox; + +cairo_lang_test_utils::test_file_test!( + simple_deps, + "tests/test_data/scarb", + { + simple_deps: "simple_deps.txt" + }, + test_simple_deps +); + +fn test_simple_deps( + inputs: &OrderedHashMap, + _args: &OrderedHashMap, +) -> TestRunnerResult { + let mut ls = sandbox! { + files { + "a/Scarb.toml" => &inputs["a/Scarb.toml"], + "a/src/lib.cairo" => &inputs["a/src/lib.cairo"], + "b/Scarb.toml" => &inputs["b/Scarb.toml"], + "b/src/lib.cairo" => &inputs["b/src/lib.cairo"], + } + }; + + assert!(ls.open_and_wait_for_diagnostics("a/src/lib.cairo").diagnostics.is_empty()); + // Check if opening `a` triggers calculating diagnostics for `b`. + let diagnostics_from_b = ls.wait_for_diagnostics("b/src/lib.cairo"); + assert_eq!(diagnostics_from_b.diagnostics.len(), 1); + assert_eq!( + diagnostics_from_b.diagnostics[0].code, + Some(NumberOrString::String("E0005".to_string())) + ); + + let analyzed_crates = ls.send_request::(()); + + TestRunnerResult::success(OrderedHashMap::from([( + "Analyzed crates".to_string(), + normalize(&ls, analyzed_crates), + )])) +} diff --git a/tests/e2e/support/fixture.rs b/tests/e2e/support/fixture.rs index d2feedb8..5b625414 100644 --- a/tests/e2e/support/fixture.rs +++ b/tests/e2e/support/fixture.rs @@ -35,7 +35,7 @@ impl Fixture { } pub fn root_url(&self) -> Url { - Url::from_directory_path(self.t.path()).unwrap() + Url::from_directory_path(self.t.path().canonicalize().unwrap()).unwrap() } pub fn file_absolute_path(&self, path: impl AsRef) -> PathBuf { diff --git a/tests/test_data/scarb/simple_deps.txt b/tests/test_data/scarb/simple_deps.txt new file mode 100644 index 00000000..f29e1006 --- /dev/null +++ b/tests/test_data/scarb/simple_deps.txt @@ -0,0 +1,154 @@ +//! > Test simple Scarb deps. + +//! > test_runner_name +test_simple_deps + +//! > a/Scarb.toml +[package] +name = "a" +version = "0.1.0" +edition = "2024_07" + +[dependencies] +b = { path = "../b" } + +//! > a/src/lib.cairo +use b::Foo; + +fn main() { + let foo = Foo::Bar; + match foo { + Foo::Baz => {}, + _ => {} + } +} + +//! > b/Scarb.toml +[package] +name = "b" +version = "0.1.0" +edition = "2024_07" + +//! > b/src/lib.cairo +pub enum Foo { + Bar, + Baz, +} + +mod non_existent; + +//! > 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: 1, + }, + ), + 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, + }, + } + ```