Skip to content

Commit

Permalink
Scarb test: removing dependency
Browse files Browse the repository at this point in the history
commit-id:4d859745
  • Loading branch information
piotmag769 committed Jan 13, 2025
1 parent 06bfeb7 commit 90b1395
Show file tree
Hide file tree
Showing 2 changed files with 415 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/e2e/scarb/scarb_toml_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -77,3 +86,52 @@ fn test_removing_member(
),
]))
}

fn test_removing_dependency(
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" => "",
"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::<lsp::ext::ViewAnalyzedCrates>(());

ls.edit_file("a/Scarb.toml", indoc! {r#"
[package]
name = "a"
version = "0.1.0"
edition = "2024_07"
"#
});

ls.send_notification::<DidChangeWatchedFiles>(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::<lsp::ext::ViewAnalyzedCrates>(());

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),
),
]))
}
Loading

0 comments on commit 90b1395

Please sign in to comment.