Skip to content

Commit

Permalink
Implement sozo test
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev committed Jun 3, 2023
1 parent 95c1fc8 commit 81386f2
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 151 deletions.
15 changes: 1 addition & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ members = [
"crates/dojo-lang",
"crates/dojo-language-server",
"crates/dojo-world",
"crates/dojo-test-runner",
"crates/dojo-test-utils",
"crates/dojo-signers",
"crates/katana",
Expand Down
21 changes: 0 additions & 21 deletions crates/dojo-test-runner/Cargo.toml

This file was deleted.

31 changes: 0 additions & 31 deletions crates/dojo-test-runner/README.md

This file was deleted.

42 changes: 0 additions & 42 deletions crates/dojo-test-runner/src/compiler.rs

This file was deleted.

1 change: 1 addition & 0 deletions crates/sozo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cairo-lang-project.workspace = true
cairo-lang-sierra.workspace = true
cairo-lang-sierra-to-casm.workspace = true
cairo-lang-starknet.workspace = true
cairo-lang-test-runner.workspace = true
scarb.workspace = true
semver.workspace = true
serde.workspace = true
Expand Down
25 changes: 6 additions & 19 deletions crates/sozo/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
use clap::{Args, Parser, Subcommand};
use clap::{Parser, Subcommand};

use self::build::BuildArgs;
use self::init::InitArgs;
use self::migrate::MigrateArgs;
use self::test::TestArgs;

pub(crate) mod build;
pub(crate) mod init;
pub(crate) mod migrate;
pub(crate) mod test;

#[derive(Subcommand)]
pub enum Commands {
#[command(
about = "Build the project's ECS, outputting smart contracts artifacts for deployment"
)]
#[command(about = "Build the world, generating the necessary artifacts for deployment")]
Build(BuildArgs),
#[command(about = "Initialize a new project")]
Init(InitArgs),
#[command(about = "Run a migration, declaring and deploying contracts as necessary to \
update the world")]
Migrate(MigrateArgs),
#[command(about = "Generate rust contract bindings")]
Bind(BindArgs),
#[command(about = "Retrieve an entity's state by entity ID")]
Inspect(InspectArgs),
#[command(about = "Test the project's smart contracts")]
Test(TestArgs),
}

#[derive(Parser)]
Expand All @@ -32,14 +30,3 @@ pub struct App {
#[command(subcommand)]
pub command: Commands,
}

#[derive(Args)]
pub struct BindArgs {}

#[derive(Args)]
pub struct InspectArgs {
#[clap(short, long, help = "Entity ID to retrieve state for")]
id: String,
#[clap(short, long, help = "World address to retrieve entity state from")]
world_address: String,
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
//! Compiles and runs a Dojo project.
//! Compiles and runs tests for a Dojo project.
use std::env::{self, current_dir};

use anyhow::{bail, Result};
use cairo_lang_compiler::db::RootDatabase;
use cairo_lang_compiler::diagnostics::DiagnosticsReporter;
use cairo_lang_test_runner::TestRunner;
use camino::Utf8PathBuf;
use clap::Parser;
use compiler::DojoTestCompiler;
use clap::Args;
use dojo_lang::compiler::collect_main_crate_ids;
use dojo_lang::plugin::CairoPluginRepository;
use scarb::compiler::CompilerRepository;
use scarb::core::Config;
use scarb::compiler::{CompilationUnit, Compiler, CompilerRepository};
use scarb::core::{Config, Workspace};
use scarb::ops;
use scarb::ui::Verbosity;

mod compiler;

/// Command line args parser.
/// Exits with 0/1 if the input is formatted correctly/incorrectly.
#[derive(Parser, Debug)]
#[clap(version, verbatim_doc_comment)]
struct Args {
#[derive(Args)]
pub struct TestArgs {
/// The path to compile and run its tests.
path: Utf8PathBuf,
/// The filter for the tests, running only tests containing the filter string.
Expand All @@ -31,8 +30,7 @@ struct Args {
ignored: bool,
}

fn main() -> anyhow::Result<()> {
let args = Args::parse();
pub fn run(args: TestArgs) -> anyhow::Result<()> {
let source_dir = if args.path.is_absolute() {
args.path
} else {
Expand Down Expand Up @@ -62,3 +60,38 @@ fn main() -> anyhow::Result<()> {

ops::compile(&ws)
}

pub struct DojoTestCompiler;

impl Compiler for DojoTestCompiler {
fn target_kind(&self) -> &str {
"dojo"
}

fn compile(
&self,
unit: CompilationUnit,
db: &mut RootDatabase,
_: &Workspace<'_>,
) -> Result<()> {
let main_crate_ids = collect_main_crate_ids(&unit, db);

if DiagnosticsReporter::stderr().check(db) {
bail!("failed to compile");
}

let runner = TestRunner {
db: db.snapshot(),
main_crate_ids,
// TODO: Pass these in
filter: "".to_string(),
include_ignored: false,
ignored: false,
starknet: true,
};

runner.run()?;

Ok(())
}
}
5 changes: 2 additions & 3 deletions crates/sozo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use log::error;

mod commands;

use self::commands::{build, init, migrate, App, Commands};
use self::commands::{build, init, migrate, test, App, Commands};

fn main() {
env_logger::Builder::from_env(Env::default().default_filter_or("sozo=info")).init();
Expand All @@ -23,8 +23,7 @@ fn main() {
Ok(())
}
Commands::Migrate(args) => migrate::run(args),
Commands::Bind(..) => Ok(print!("Bind")),
Commands::Inspect(..) => Ok(print!("Inspect")),
Commands::Test(args) => test::run(args),
};

if let Err(err) = res {
Expand Down
12 changes: 6 additions & 6 deletions scripts/cairo_test.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
set -euxo pipefail

cargo +nightly-2023-05-28 run --bin dojo-test -- crates/dojo-core
cargo +nightly-2023-05-28 run --bin dojo-test -- crates/dojo-erc
#cargo +nightly-2023-05-28 run --bin dojo-test -- crates/dojo-physics
cargo +nightly-2023-05-28 run --bin dojo-test -- crates/dojo-core/tests
# cargo +nightly-2023-05-28 run --bin dojo-test -- crates/dojo-defi
cargo +nightly-2023-05-28 run --bin dojo-test -- examples/ecs
cargo +nightly-2023-05-28 run --bin sozo -- test crates/dojo-core
cargo +nightly-2023-05-28 run --bin sozo -- test crates/dojo-erc
#cargo +nightly-2023-05-28 run --bin sozo -- test crates/dojo-physics
cargo +nightly-2023-05-28 run --bin sozo -- test crates/dojo-core/tests
# cargo +nightly-2023-05-28 run --bin sozo -- test crates/dojo-defi
cargo +nightly-2023-05-28 run --bin sozo -- test examples/ecs

0 comments on commit 81386f2

Please sign in to comment.