Skip to content

Commit

Permalink
Fix assert macros (#1563)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciektr committed Aug 29, 2024
1 parent ba72e5d commit 2b945d5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion scarb/src/compiler/plugin/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl CairoPlugin for BuiltinTestAssertsPlugin {
fn id(&self) -> PackageId {
PackageId::new(
PackageName::TEST_ASSERTS_PLUGIN,
semver::Version::new(0, 1, 0),
crate::version::get().cairo.version.to_version().unwrap(),
SourceId::for_std(),
)
}
Expand Down
2 changes: 1 addition & 1 deletion scarb/src/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn resolve_workspace_with_opts(
ManifestDependency::builder()
.kind(DepKind::Target(TargetKind::TEST))
.name(PackageName::TEST_ASSERTS_PLUGIN)
.version_req(DependencyVersionReq::exact(&semver::Version::new(0, 1, 0)))
.version_req(version_req.clone())
.source_id(SourceId::for_std())
.build(),
],
Expand Down
20 changes: 20 additions & 0 deletions scarb/tests/test_subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,23 @@ fn errors_when_missing_script_and_cairo_test() {
error: no such command: `cairo-test`
"#});
}

#[test]
fn assert_macros_available() {
let t = TempDir::new().unwrap();
ProjectBuilder::start()
.dev_dep_builtin("assert_macros")
.dep_cairo_test()
.lib_cairo(indoc! {r#"
#[test]
fn some() {
assert_eq!(1, 1);
}
"#})
.build(&t);
Scarb::quick_snapbox()
.args(["build", "--test"])
.current_dir(&t)
.assert()
.success();
}
18 changes: 13 additions & 5 deletions utils/scarb-test-support/src/project_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,24 @@ impl ProjectBuilder {
self
}

pub fn dep_starknet(self) -> Self {
self.dep("starknet", Dep.version(CAIRO_VERSION))
pub fn dep_builtin(self, name: impl ToString) -> Self {
self.dep(name, Dep.version(CAIRO_VERSION))
}

pub fn dep_cairo_test(self) -> Self {
self.dev_dep("cairo_test", Dep.version(CAIRO_VERSION))
pub fn dev_dep_builtin(self, name: impl ToString) -> Self {
self.dev_dep(name, Dep.version(CAIRO_VERSION))
}

pub fn dep_cairo_run(self) -> Self {
self.dep("cairo_run", Dep.version(CAIRO_VERSION))
self.dep_builtin("cairo_run")
}

pub fn dep_starknet(self) -> Self {
self.dep_builtin("starknet")
}

pub fn dep_cairo_test(self) -> Self {
self.dev_dep_builtin("cairo_test")
}

pub fn manifest_package_extra(mut self, extra: impl ToString) -> Self {
Expand Down

0 comments on commit 2b945d5

Please sign in to comment.