diff --git a/Cargo.lock b/Cargo.lock index 7f52b6fbc..8a1b1fc0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -388,8 +388,8 @@ dependencies = [ [[package]] name = "cairo-lang-casm" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-utils", "indoc", @@ -404,8 +404,8 @@ dependencies = [ [[package]] name = "cairo-lang-compiler" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "anyhow", "cairo-lang-defs", @@ -429,16 +429,16 @@ dependencies = [ [[package]] name = "cairo-lang-debug" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-utils", ] [[package]] name = "cairo-lang-defs" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-debug", "cairo-lang-diagnostics", @@ -454,8 +454,8 @@ dependencies = [ [[package]] name = "cairo-lang-diagnostics" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -466,8 +466,8 @@ dependencies = [ [[package]] name = "cairo-lang-eq-solver" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-utils", "good_lp", @@ -477,8 +477,8 @@ dependencies = [ [[package]] name = "cairo-lang-filesystem" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", @@ -490,8 +490,8 @@ dependencies = [ [[package]] name = "cairo-lang-lowering" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -515,8 +515,8 @@ dependencies = [ [[package]] name = "cairo-lang-parser" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -535,8 +535,8 @@ dependencies = [ [[package]] name = "cairo-lang-plugins" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-defs", "cairo-lang-diagnostics", @@ -554,8 +554,8 @@ dependencies = [ [[package]] name = "cairo-lang-proc-macros" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-debug", "quote", @@ -564,8 +564,8 @@ dependencies = [ [[package]] name = "cairo-lang-project" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-filesystem", "cairo-lang-utils", @@ -577,8 +577,8 @@ dependencies = [ [[package]] name = "cairo-lang-runner" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "anyhow", "ark-ff", @@ -613,15 +613,14 @@ dependencies = [ [[package]] name = "cairo-lang-semantic" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", "cairo-lang-diagnostics", "cairo-lang-filesystem", "cairo-lang-parser", - "cairo-lang-plugins", "cairo-lang-proc-macros", "cairo-lang-syntax", "cairo-lang-utils", @@ -637,9 +636,10 @@ dependencies = [ [[package]] name = "cairo-lang-sierra" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ + "anyhow", "cairo-lang-utils", "const-fnv1a-hash", "convert_case", @@ -659,8 +659,8 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -672,8 +672,8 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -685,8 +685,8 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-generator" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -694,7 +694,6 @@ dependencies = [ "cairo-lang-filesystem", "cairo-lang-lowering", "cairo-lang-parser", - "cairo-lang-plugins", "cairo-lang-proc-macros", "cairo-lang-semantic", "cairo-lang-sierra", @@ -711,8 +710,8 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "assert_matches", "cairo-felt", @@ -732,8 +731,8 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-type-size" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-sierra", "cairo-lang-utils", @@ -741,8 +740,8 @@ dependencies = [ [[package]] name = "cairo-lang-starknet" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "anyhow", "cairo-felt", @@ -762,6 +761,7 @@ dependencies = [ "cairo-lang-sierra-to-casm", "cairo-lang-syntax", "cairo-lang-utils", + "const_format", "convert_case", "genco", "indent", @@ -781,8 +781,8 @@ dependencies = [ [[package]] name = "cairo-lang-syntax" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -797,51 +797,65 @@ dependencies = [ [[package]] name = "cairo-lang-syntax-codegen" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "genco", "xshell", ] [[package]] -name = "cairo-lang-test-runner" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +name = "cairo-lang-test-plugin" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "anyhow", "cairo-felt", - "cairo-lang-casm", "cairo-lang-compiler", "cairo-lang-debug", "cairo-lang-defs", "cairo-lang-diagnostics", "cairo-lang-filesystem", "cairo-lang-lowering", - "cairo-lang-plugins", - "cairo-lang-project", - "cairo-lang-runner", "cairo-lang-semantic", "cairo-lang-sierra", "cairo-lang-sierra-generator", + "cairo-lang-starknet", + "cairo-lang-syntax", + "cairo-lang-utils", + "itertools 0.11.0", + "num-traits 0.2.15", + "serde", +] + +[[package]] +name = "cairo-lang-test-runner" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" +dependencies = [ + "anyhow", + "cairo-felt", + "cairo-lang-compiler", + "cairo-lang-defs", + "cairo-lang-filesystem", + "cairo-lang-runner", + "cairo-lang-sierra", "cairo-lang-sierra-to-casm", "cairo-lang-starknet", "cairo-lang-syntax", + "cairo-lang-test-plugin", "cairo-lang-utils", - "cairo-vm", "colored", "itertools 0.11.0", - "num-bigint", "num-traits 0.2.15", "rayon 1.7.0", - "salsa", - "thiserror", + "serde", ] [[package]] name = "cairo-lang-utils" -version = "2.1.1" -source = "git+https://github.com/starkware-libs/cairo#b97054e2ffd6764ce924250957a194c5448eea6a" +version = "2.2.0" +source = "git+https://github.com/starkware-libs/cairo#00448c02fc474021575217b9b7e871c728552d52" dependencies = [ "indexmap 2.0.0", "itertools 0.11.0", @@ -979,6 +993,26 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32b13ea120a812beba79e34316b3942a857c86ec1593cb34f27bb28272ce2cca" +[[package]] +name = "const_format" +version = "0.2.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c990efc7a285731f9a4378d81aff2f0e85a2c8781a05ef0f8baa8dac54d0ff48" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e026b6ce194a874cb9cf32cd5772d1ef9767cc8fcb5765948d74f37a9d8b2bf6" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + [[package]] name = "convert_case" version = "0.6.0" @@ -2515,6 +2549,7 @@ dependencies = [ "cairo-lang-sierra-to-casm", "cairo-lang-starknet", "cairo-lang-syntax", + "cairo-lang-test-plugin", "cairo-lang-test-runner", "cairo-lang-utils", "clap", diff --git a/Cargo.toml b/Cargo.toml index 8fd6d92d0..cd783aad1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,25 +24,26 @@ glob = "0.3.0" cairo-felt = "0.8.2" # Cairo runner dependencies -cairo-lang-runner = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-test-runner = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-compiler = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-casm = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-diagnostics = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-debug = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-defs = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-sierra = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-sierra-ap-change = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-sierra-gas = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-sierra-generator = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-semantic = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-sierra-to-casm = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-utils = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-filesystem = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-starknet = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-syntax = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-plugins = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} -cairo-lang-lowering = {git = "https://github.com/starkware-libs/cairo", version = "2.1.1"} +cairo-lang-runner = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-test-runner = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-test-plugin = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-compiler = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-casm = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-diagnostics = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-debug = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-defs = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-sierra = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-sierra-ap-change = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-sierra-gas = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-sierra-generator = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-semantic = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-sierra-to-casm = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-utils = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-filesystem = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-starknet = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-syntax = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-plugins = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} +cairo-lang-lowering = {git = "https://github.com/starkware-libs/cairo", version = "2.2.0"} anyhow = "1.0.66" diff --git a/corelib/Scarb.toml b/corelib/Scarb.toml index 06d283665..dabde0b0e 100644 --- a/corelib/Scarb.toml +++ b/corelib/Scarb.toml @@ -1,6 +1,6 @@ [package] name = "core" -version = "2.1.1" +version = "2.2.0" # NOTE: This is non-public, unstable Scarb's field, which instructs resolver that this package does not # depend on `core`, which is only true for this particular package. Nobody else should use it. diff --git a/corelib/src/hash.cairo b/corelib/src/hash.cairo index c9b7790f9..effea0033 100644 --- a/corelib/src/hash.cairo +++ b/corelib/src/hash.cairo @@ -104,15 +104,6 @@ impl HashU128< } } -impl HashU256< - S, impl SHashState: HashStateTrait, impl SDrop: Drop -> of Hash { - #[inline(always)] - fn update_state(state: S, value: u256) -> S { - state.update_with(value.low).update_with(value.high) - } -} - impl HashContractAddress< S, impl SHashState: HashStateTrait, impl SDrop: Drop > of Hash { diff --git a/corelib/src/integer.cairo b/corelib/src/integer.cairo index 48acbefd7..27681b401 100644 --- a/corelib/src/integer.cairo +++ b/corelib/src/integer.cairo @@ -1059,7 +1059,7 @@ impl U64BitOr of BitOr { } } -#[derive(Copy, Drop, PartialEq, Serde, starknet::Store)] +#[derive(Copy, Drop, Hash, PartialEq, Serde, starknet::Store)] struct u256 { low: u128, high: u128, diff --git a/corelib/src/lib.cairo b/corelib/src/lib.cairo index 3cdab3347..e41b93648 100644 --- a/corelib/src/lib.cairo +++ b/corelib/src/lib.cairo @@ -8,8 +8,9 @@ use serde::Serde; type usize = u32; -#[derive(Copy, Drop)] +#[derive(Copy, Drop, Default)] enum bool { + #[default] False, True, } diff --git a/corelib/src/test/plugins_test.cairo b/corelib/src/test/plugins_test.cairo index 11173e7a4..332a5cdfc 100644 --- a/corelib/src/test/plugins_test.cairo +++ b/corelib/src/test/plugins_test.cairo @@ -7,6 +7,21 @@ enum EnumForSerde { C: u64, } +#[derive(Drop, Default, PartialEq)] +struct StructForDefault { + a: felt252, + b: u256, + c: bool +} + +#[derive(Drop, Default, PartialEq)] +enum EnumForDefault { + A: felt252, + B: u256, + #[default] + C: StructForDefault, +} + #[test] fn test_derive_serde_enum() { let a = EnumForSerde::A(()); @@ -46,3 +61,17 @@ fn test_derive_serde_enum() { ); assert(serialized.is_empty(), 'expected empty'); } + +#[test] +fn test_derive_default_struct() { + let actual: StructForDefault = Default::default(); + let expected = StructForDefault { a: 0, b: 0, c: bool::False }; + assert_eq(@actual, @expected, 'unexpected default value'); +} + +#[test] +fn test_derive_default_enum() { + let actual: EnumForDefault = Default::default(); + let expected = EnumForDefault::C(StructForDefault { a: 0, b: 0, c: bool::False }); + assert_eq(@actual, @expected, 'unexpected default value'); +} diff --git a/src/exercise.rs b/src/exercise.rs index b2af05411..b4d7f819d 100755 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -2,7 +2,7 @@ use regex::Regex; use serde::Deserialize; use crate::starklings_runner::{run_cairo_program, Args as RunnerArgs}; -use crate::starklings_tester::TestRunner; +use crate::starklings_tester::run_exercise_tests; use std::fmt::{self, Display, Formatter}; use std::fs::{remove_file, File}; use std::io::Read; @@ -100,8 +100,7 @@ impl Exercise { } pub fn test_cairo(&self) -> anyhow::Result { - let runner = TestRunner::new(self.path.to_str().unwrap(), "", false, false, true)?; - runner.run() + run_exercise_tests(self.path.to_str().unwrap()) } pub fn state(&self) -> State { diff --git a/src/run.rs b/src/run.rs index a9510baad..b5aa82ea3 100755 --- a/src/run.rs +++ b/src/run.rs @@ -54,7 +54,7 @@ fn run_cairo(exercise: &Exercise) -> Result<(), ()> { // This is strictly for non-test binaries, so output is displayed fn test_cairo(exercise: &Exercise) -> Result<(), ()> { let progress_bar = ProgressBar::new_spinner(); - progress_bar.set_message(format!("Running {exercise}...")); + progress_bar.set_message(format!("Testing {exercise}...")); progress_bar.enable_steady_tick(100); let output = exercise.test_cairo(); diff --git a/src/starklings_runner.rs b/src/starklings_runner.rs index 327422bd6..04934c33b 100644 --- a/src/starklings_runner.rs +++ b/src/starklings_runner.rs @@ -111,6 +111,5 @@ pub fn run_cairo_program(args: &Args) -> anyhow::Result { ret_string.push_str(format!("Run panicked with err values: {values:?}").as_str()); } } - println!("{ret_string}"); Ok(ret_string) } diff --git a/src/starklings_tester.rs b/src/starklings_tester.rs index 67ccdd25c..800912515 100644 --- a/src/starklings_tester.rs +++ b/src/starklings_tester.rs @@ -7,9 +7,11 @@ use cairo_lang_compiler::diagnostics::DiagnosticsReporter; use cairo_lang_compiler::project::setup_project; use cairo_lang_debug::DebugWithDb; use cairo_lang_defs::ids::{FreeFunctionId, FunctionWithBodyId, ModuleItemId}; -use cairo_lang_defs::plugin::{MacroPlugin, PluginDiagnostic, PluginResult}; +use cairo_lang_defs::plugin::PluginDiagnostic; use cairo_lang_diagnostics::ToOption; use cairo_lang_filesystem::cfg::{Cfg, CfgSet}; +use cairo_lang_starknet::inline_macros::selector::SelectorMacro; +use cairo_lang_test_plugin::TestPlugin; use std::path::Path; use std::sync::{Arc, Mutex}; @@ -30,13 +32,11 @@ use cairo_lang_sierra_generator::replace_ids::{DebugReplacer, SierraIdReplacer}; use cairo_lang_sierra_to_casm::metadata::MetadataComputationConfig; use cairo_lang_starknet::casm_contract_class::ENTRY_POINT_COST; use cairo_lang_starknet::contract::{ - find_contracts, get_contracts_info, get_module_abi_functions, ContractInfo, + find_contracts, get_contract_abi_functions, get_contracts_info, ContractInfo, }; use cairo_lang_starknet::plugin::consts::{CONSTRUCTOR_MODULE, EXTERNAL_MODULE, L1_HANDLER_MODULE}; use cairo_lang_starknet::plugin::StarkNetPlugin; -use cairo_lang_syntax::attribute::structured::{ - Attribute, AttributeArg, AttributeArgVariant, AttributeListStructurize, -}; +use cairo_lang_syntax::attribute::structured::{Attribute, AttributeArg, AttributeArgVariant}; use cairo_lang_syntax::node::db::SyntaxGroup; use cairo_lang_syntax::node::{ast, Token}; @@ -119,7 +119,8 @@ impl TestRunner { b.with_macro_plugin(Arc::new(TestPlugin::default())); if starknet { - b.with_macro_plugin(Arc::new(StarkNetPlugin::default())); + b.with_macro_plugin(Arc::new(StarkNetPlugin::default())) + .with_inline_macro_plugin(SelectorMacro::NAME, Arc::new(SelectorMacro)); } b.build()? @@ -150,9 +151,9 @@ impl TestRunner { .iter() .flat_map(|contract| { chain!( - get_module_abi_functions(db, contract, EXTERNAL_MODULE).unwrap(), - get_module_abi_functions(db, contract, CONSTRUCTOR_MODULE).unwrap(), - get_module_abi_functions(db, contract, L1_HANDLER_MODULE).unwrap() + get_contract_abi_functions(db, contract, EXTERNAL_MODULE).unwrap(), + get_contract_abi_functions(db, contract, CONSTRUCTOR_MODULE).unwrap(), + get_contract_abi_functions(db, contract, L1_HANDLER_MODULE).unwrap() ) }) .map(|func| ConcreteFunctionWithBodyId::from_semantic(db, func.value)) @@ -264,7 +265,7 @@ impl TestRunner { } } } - println!(); + bail!( "{}\n\ test result: {}. {} passed; {} failed; {} ignored", @@ -401,13 +402,20 @@ fn find_all_tests( let Ok(module_items) = db.module_items(*module_id) else { continue; }; - tests.extend( - module_items.iter().filter_map(|item| { - let ModuleItemId::FreeFunction(func_id) = item else { return None }; - let Ok(attrs) = db.function_with_body_attributes(FunctionWithBodyId::Free(*func_id)) else { return None }; - Some((*func_id, try_extract_test_config(db.upcast(), attrs).unwrap()?)) - }), - ); + tests.extend(module_items.iter().filter_map(|item| { + let ModuleItemId::FreeFunction(func_id) = item else { + return None; + }; + let Ok(attrs) = + db.function_with_body_attributes(FunctionWithBodyId::Free(*func_id)) + else { + return None; + }; + Some(( + *func_id, + try_extract_test_config(db.upcast(), attrs).unwrap()?, + )) + })); } } tests @@ -518,18 +526,24 @@ pub fn try_extract_test_config( } /// Tries to extract the relevant expected panic values. fn extract_panic_values(db: &dyn SyntaxGroup, attr: &Attribute) -> Option> { - let [ - AttributeArg { - variant: AttributeArgVariant::Named { name, value: panics, .. }, + let [AttributeArg { + variant: + AttributeArgVariant::Named { + name, + value: panics, + .. + }, .. - } - ] = &attr.args[..] else { + }] = &attr.args[..] + else { return None; }; if name != "expected" { return None; } - let ast::Expr::Tuple(panics) = panics else { return None }; + let ast::Expr::Tuple(panics) = panics else { + return None; + }; panics .expressions(db) .elements(db) @@ -546,22 +560,7 @@ fn extract_panic_values(db: &dyn SyntaxGroup, attr: &Attribute) -> Option>>() } -/// Plugin to create diagnostics for tests attributes. -#[derive(Debug, Default)] -#[non_exhaustive] -pub struct TestPlugin; - -impl MacroPlugin for TestPlugin { - fn generate_code(&self, db: &dyn SyntaxGroup, item_ast: ast::Item) -> PluginResult { - PluginResult { - code: None, - diagnostics: if let ast::Item::FreeFunction(free_func_ast) = item_ast { - try_extract_test_config(db, free_func_ast.attributes(db).structurize(db)).err() - } else { - None - } - .unwrap_or_default(), - remove_original_item: false, - } - } +pub fn run_exercise_tests(path: &str) -> anyhow::Result { + let runner = TestRunner::new(path, "", false, false, true)?; + runner.run() } diff --git a/src/verify.rs b/src/verify.rs index 02dfdbdd9..b9e1aba20 100755 --- a/src/verify.rs +++ b/src/verify.rs @@ -16,7 +16,7 @@ pub fn verify<'a>( let bar = ProgressBar::new(total as u64); bar.set_style( ProgressStyle::default_bar() - .template("Progress: [{bar:60.green/red}] {pos}/{len} {msg}") + .template("Progress: [{bar:60.green/red}] {pos}/{len} {msg}\n") .progress_chars("#>-"), ); bar.set_position(num_done as u64); @@ -38,6 +38,7 @@ pub fn verify<'a>( // Compile the given Exercise and run the resulting binary in an interactive mode fn compile_and_run_interactively(exercise: &Exercise) -> Result { let progress_bar = ProgressBar::new_spinner(); + progress_bar.enable_steady_tick(100); progress_bar.set_message(format!("Running {exercise} exercise...")); @@ -70,12 +71,10 @@ fn compile_and_run_cairo(exercise: &Exercise, progress_bar: &ProgressBar) -> Res if let Err(error) = compilation_result { progress_bar.finish_and_clear(); - warn!( - "Compiling of {} failed! Please try again. Here's the output:", - exercise - ); - println!("{error}"); + eprintln!("{error}"); + + warn!("Compiling of {} failed! Please try again.", exercise); Err(()) } else { Ok(compilation_result.unwrap())