Skip to content

Commit

Permalink
Scarb test simple deps
Browse files Browse the repository at this point in the history
commit-id:934fb368
  • Loading branch information
piotmag769 committed Jan 13, 2025
1 parent 3401f22 commit 22cf3e3
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/e2e/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod goto_definition;
mod hover;
mod macro_expand;
mod references;
mod scarb;
mod semantic_tokens;
mod support;
mod workspace_configuration;
1 change: 1 addition & 0 deletions tests/e2e/scarb/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod simple_deps;
46 changes: 46 additions & 0 deletions tests/e2e/scarb/simple_deps.rs
Original file line number Diff line number Diff line change
@@ -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<String, String>,
_args: &OrderedHashMap<String, String>,
) -> 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::<lsp::ext::ViewAnalyzedCrates>(());

TestRunnerResult::success(OrderedHashMap::from([(
"Analyzed crates".to_string(),
normalize(&ls, analyzed_crates),
)]))
}
2 changes: 1 addition & 1 deletion tests/e2e/support/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>) -> PathBuf {
Expand Down
154 changes: 154 additions & 0 deletions tests/test_data/scarb/simple_deps.txt
Original file line number Diff line number Diff line change
@@ -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,
},
}
```

0 comments on commit 22cf3e3

Please sign in to comment.