Skip to content

Commit

Permalink
use snforge command to run sozo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
remybar committed Dec 10, 2024
1 parent 452a0ee commit 1c7c7e3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
31 changes: 21 additions & 10 deletions bin/sozo/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ use scarb::ops;
use scarb::ops::{validate_features, FeaturesOpts};
use scarb_ui::args::{FeaturesSpec, PackagesFilter};
use serde::{Deserialize, Serialize};
use std::ffi::{OsStr, OsString};

use super::check_package_dojo_version;

const TEST_COMMAND: &str = "snforge";
const TEST_COMMAND_FIRST_ARG: &str = "test";

#[derive(Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct Props {
Expand Down Expand Up @@ -62,30 +64,39 @@ impl TestArgs {
let features_opts: FeaturesOpts = self.features.clone().try_into()?;
validate_features(&packages, &features_opts)?;

let args = self.build_args();

packages.iter().try_for_each(|package| {
ops::execute_test_subcommand(package, &args, &ws, self.features.clone()).map(|_| ())
std::process::Command::new(TEST_COMMAND)
.args(self.build_args())
.current_dir(package.root())
.stdout(std::process::Stdio::inherit())
.output()
.map_err(|_| {
anyhow::anyhow!(
"Unable to run `{TEST_COMMAND}` for {}",
package.manifest_path()
)
})
.map(|_| ())
})
}

pub fn build_args(&self) -> Vec<OsString> {
let mut args = vec![];
pub fn build_args(&self) -> Vec<&str> {
let mut args = vec![TEST_COMMAND_FIRST_ARG];

if self.include_ignored {
args.push(OsStr::new("--include-ignored").to_os_string());
args.push("--include-ignored");
}

if self.ignored {
args.push(OsStr::new("--ignored").to_os_string());
args.push("--ignored");
}

if self.print_resource_usage {
args.push(OsStr::new("--detailed-resources").to_os_string());
args.push("--detailed-resources");
}

if self.profiler {
args.push(OsStr::new("--build-profile").to_os_string());
args.push("--build-profile");
}

args
Expand Down
Empty file.
16 changes: 16 additions & 0 deletions crates/dojo/core/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,24 @@ name = "dojo"
version = "1.0.4"
dependencies = [
"dojo_macros",
"snforge_std",
]

[[package]]
name = "dojo_macros"
version = "0.1.0"

[[package]]
name = "snforge_scarb_plugin"
version = "0.33.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:b4dd6088372decd367652827091e0589bbf6bc550dfc3957baa3e9c61d6eb449"

[[package]]
name = "snforge_std"
version = "0.33.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:f7dc3349f8a6ef4915c93df447a00bd5a53a31129fd0990a00afa0ad31d91b06"
dependencies = [
"snforge_scarb_plugin",
]
3 changes: 3 additions & 0 deletions crates/dojo/core/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ version = "1.0.4"
starknet = "=2.8.4"
dojo_macros = { path = "../macros" }

[dev-dependencies]
snforge_std = "0.33.0"

[lib]

[[target.starknet-contract]]
Expand Down

0 comments on commit 1c7c7e3

Please sign in to comment.