Skip to content

Commit

Permalink
Require explicit dependence on cairo_test (i.e. test_plugin)"
Browse files Browse the repository at this point in the history
commit-id:83a53c59
  • Loading branch information
maciektr committed Jun 13, 2024
1 parent 4b9921b commit 6ffa5dc
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 30 deletions.
3 changes: 3 additions & 0 deletions examples/dependencies/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ version = "0.1.0"

[dependencies]
alexandria_math = { git = "https://github.com/keep-starknet-strange/alexandria.git" }

[dev-dependencies]
cairo_test = "2.6.0"
3 changes: 3 additions & 0 deletions examples/hello_world/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ edition = "2023_10"
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]

[dev-dependencies]
cairo_test = "2.6.0"
3 changes: 3 additions & 0 deletions examples/starknet_hello_world/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ version = "0.1.0"
[dependencies]
starknet = "2.6.0"

[dev-dependencies]
cairo_test = "2.6.0"

[[target.starknet-contract]]
3 changes: 3 additions & 0 deletions examples/starknet_multiple_contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ version = "0.1.0"
[dependencies]
starknet = "2.6.0"

[dev-dependencies]
cairo_test = "2.6.0"

[[target.starknet-contract]]
4 changes: 4 additions & 0 deletions examples/workspaces/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test = "snforge"
exit_first = true

[workspace.dependencies]
cairo_test = "2.6.0"
starknet = "2.6.0"

[workspace.package]
Expand All @@ -30,4 +31,7 @@ starknet.workspace = true
fibonacci = { path = "crates/fibonacci" }
addition = { path = "crates/addition" }

[dev-dependencies]
cairo_test.workspace = true

[[target.starknet-contract]]
3 changes: 3 additions & 0 deletions examples/workspaces/crates/addition/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ name = "addition"
version.workspace = true

[lib]

[dev-dependencies]
cairo_test.workspace = true
3 changes: 3 additions & 0 deletions examples/workspaces/crates/fibonacci/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ snforge.workspace = true

[dependencies]
addition = { path = "../addition" }

[dev-dependencies]
cairo_test.workspace = true
4 changes: 4 additions & 0 deletions extensions/scarb-cairo-test/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fn can_test_without_gas() {
}
}
"#})
.dep_cairo_test()
.manifest_extra(indoc! {r#"
[cairo]
enable-gas = false
Expand Down Expand Up @@ -86,6 +87,7 @@ fn can_print_test_resources() {
}
}
"#})
.dep_cairo_test()
.build(&t);
Scarb::quick_snapbox()
.arg("cairo-test")
Expand Down Expand Up @@ -130,6 +132,7 @@ fn get_features_test_build(t: &TempDir) {
}
}
"#})
.dep_cairo_test()
.build(t);
}

Expand Down Expand Up @@ -219,6 +222,7 @@ fn integration_tests() {
{test_case}
"#})
.dep_cairo_test()
.src("tests/a.cairo", test_case)
.src("tests/b.cairo", test_case)
.build(&t);
Expand Down
20 changes: 1 addition & 19 deletions scarb/src/core/manifest/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use typed_builder::TypedBuilder;
#[cfg(doc)]
use crate::core::Manifest;
use crate::core::{
Checksum, DepKind, DependencyVersionReq, ManifestDependency, PackageId, PackageName, SourceId,
TargetKind,
Checksum, DepKind, DependencyVersionReq, ManifestDependency, PackageId, PackageName, TargetKind,
};

/// Subset of a [`Manifest`] that contains only the most important information about a package.
Expand Down Expand Up @@ -79,27 +78,10 @@ impl Summary {
.version_req(DependencyVersionReq::exact(&cairo_version))
.build()
});

static TEST_PLUGIN_DEPENDENCY: Lazy<ManifestDependency> = Lazy::new(|| {
// NOTE: Pin test plugin to exact version, because we know that's the only one we have.
let cairo_version = crate::version::get().cairo.version.parse().unwrap();
ManifestDependency::builder()
.kind(DepKind::Target(TargetKind::TEST))
.name(PackageName::TEST_PLUGIN)
.source_id(SourceId::default())
.version_req(DependencyVersionReq::exact(&cairo_version))
.build()
});

let mut deps: Vec<&ManifestDependency> = Vec::new();

if !self.no_core {
deps.push(&CORE_DEPENDENCY);
}
if self.target_kinds.contains(&TargetKind::TEST) {
deps.push(&TEST_PLUGIN_DEPENDENCY);
}

deps.into_iter()
}

Expand Down
2 changes: 2 additions & 0 deletions scarb/tests/build_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ fn compile_test_target() {
let t = TempDir::new().unwrap();
ProjectBuilder::start()
.name("hello")
.dep_cairo_test()
.lib_cairo(r#"fn f() -> felt252 { 42 }"#)
.build(&t);
t.child("tests").create_dir_all().unwrap();
Expand Down Expand Up @@ -365,6 +366,7 @@ fn integration_tests_do_not_enable_cfg_in_main_package() {
let t = TempDir::new().unwrap();
ProjectBuilder::start()
.name("hello")
.dep_cairo_test()
.lib_cairo(indoc! {r#"
#[cfg(test)]
fn f() -> felt252 { 42 }
Expand Down
3 changes: 3 additions & 0 deletions scarb/tests/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fn expand_integration_test() {
"#};
ProjectBuilder::start()
.name("hello")
.dep_cairo_test()
.lib_cairo(formatdoc! {r#"
fn fib(mut n: u32) -> u32 {{
let mut a: u32 = 0;
Expand Down Expand Up @@ -112,6 +113,7 @@ fn can_select_target_by_kind() {
let t = TempDir::new().unwrap();
ProjectBuilder::start()
.name("hello")
.dep_cairo_test()
.lib_cairo(indoc! {r#"
fn hello() -> felt252 {
42
Expand Down Expand Up @@ -179,6 +181,7 @@ fn can_expand_multiple_targets() {
"#};
ProjectBuilder::start()
.name("hello")
.dep_cairo_test()
.lib_cairo(formatdoc! {r#"
fn fib(mut n: u32) -> u32 {{
let mut a: u32 = 0;
Expand Down
3 changes: 3 additions & 0 deletions scarb/tests/git_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,12 @@ fn transitive_path_dep() {
let git_dep = gitx::new("dep1", |t| {
ProjectBuilder::start()
.name("dep0")
.dep_cairo_test()
.lib_cairo("fn hello() -> felt252 { 42 }")
.build(&t.child("zero"));
ProjectBuilder::start()
.name("dep1")
.dep_cairo_test()
.lib_cairo("fn hello() -> felt252 { dep0::hello() }")
.dep("dep0", Dep.path("../zero"))
.build(&t.child("one"));
Expand All @@ -436,6 +438,7 @@ fn transitive_path_dep() {
ProjectBuilder::start()
.name("hello")
.version("1.0.0")
.dep_cairo_test()
.dep("dep0", &git_dep)
.dep("dep1", &git_dep)
.lib_cairo("fn world() -> felt252 { dep1::hello() }")
Expand Down
Loading

0 comments on commit 6ffa5dc

Please sign in to comment.