From ed4051dbb54c16203ac2bb2d4bec889d07cdb027 Mon Sep 17 00:00:00 2001 From: Akosh Farkash Date: Fri, 25 Oct 2024 13:40:42 +0100 Subject: [PATCH 1/2] Run test matrix on stdlib tests --- Cargo.lock | 34 +++++++++++++++++++++++++ Cargo.toml | 1 + tooling/nargo_cli/Cargo.toml | 1 + tooling/nargo_cli/tests/stdlib-tests.rs | 17 ++++++++++--- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dabac0a7570..3add28d3939 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2587,6 +2587,7 @@ dependencies = [ "termcolor", "termion", "test-binary", + "test-case", "thiserror", "tokio", "tokio-util 0.7.10", @@ -4423,6 +4424,39 @@ dependencies = [ "thiserror", ] +[[package]] +name = "test-case" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb2550dd13afcd286853192af8601920d959b14c401fcece38071d53bf0768a8" +dependencies = [ + "test-case-macros", +] + +[[package]] +name = "test-case-core" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adcb7fd841cd518e279be3d5a3eb0636409487998a4aff22f3de87b81e88384f" +dependencies = [ + "cfg-if 1.0.0", + "proc-macro2", + "quote", + "syn 2.0.64", +] + +[[package]] +name = "test-case-macros" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.64", + "test-case-core", +] + [[package]] name = "textwrap" version = "0.13.4" diff --git a/Cargo.toml b/Cargo.toml index 36b4d4c2ce1..222e7dce859 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -146,6 +146,7 @@ num-bigint = "0.4" num-traits = "0.2" similar-asserts = "1.5.0" tempfile = "3.6.0" +test-case = "3.3.1" jsonrpc = { version = "0.16.0", features = ["minreq_http"] } flate2 = "1.0.24" color-eyre = "0.6.2" diff --git a/tooling/nargo_cli/Cargo.toml b/tooling/nargo_cli/Cargo.toml index d72556ab936..d48e44415b0 100644 --- a/tooling/nargo_cli/Cargo.toml +++ b/tooling/nargo_cli/Cargo.toml @@ -86,6 +86,7 @@ sha2.workspace = true sha3.workspace = true iai = "0.1.1" test-binary = "3.0.2" +test-case.workspace = true light-poseidon = "0.2.0" diff --git a/tooling/nargo_cli/tests/stdlib-tests.rs b/tooling/nargo_cli/tests/stdlib-tests.rs index 46a241b7e0b..f44d21ea689 100644 --- a/tooling/nargo_cli/tests/stdlib-tests.rs +++ b/tooling/nargo_cli/tests/stdlib-tests.rs @@ -12,6 +12,7 @@ use nargo::{ parse_all, prepare_package, }; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; +use test_case::test_matrix; #[derive(Parser, Debug)] #[command(ignore_errors = true)] @@ -29,14 +30,22 @@ pub struct Options { impl Options { pub fn function_name_match(&self) -> FunctionNameMatch { match self.args.as_slice() { - [_, lib] => FunctionNameMatch::Contains(lib.as_str()), + [_test_name, lib] => FunctionNameMatch::Contains(lib.as_str()), _ => FunctionNameMatch::Anything, } } } -#[test] -fn run_stdlib_tests() { +/// Inliner aggressiveness results in different SSA. +/// Inlining happens if `inline_cost - retain_cost < aggressiveness` (see `inlining.rs`). +/// NB the CLI uses maximum aggressiveness. +/// +/// Even with the same inlining aggressiveness, forcing Brillig can trigger different behaviour. +#[test_matrix( + [false, true], + [i64::MIN, 0, i64::MAX] +)] +fn run_stdlib_tests(force_brillig: bool, inliner_aggressiveness: i64) { let opts = Options::parse(); let mut file_manager = file_manager_with_stdlib(&PathBuf::from(".")); @@ -80,7 +89,7 @@ fn run_stdlib_tests() { None, Some(dummy_package.root_dir.clone()), Some(dummy_package.name.to_string()), - &CompileOptions::default(), + &CompileOptions { force_brillig, inliner_aggressiveness, ..Default::default() }, ); (test_name, status) }) From e1dcd0b12d2d942f4d1291daa391473222e99630 Mon Sep 17 00:00:00 2001 From: Akosh Farkash Date: Fri, 25 Oct 2024 13:58:56 +0100 Subject: [PATCH 2/2] Disable clippy warning about method after test matrix --- tooling/nargo_cli/tests/stdlib-tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tooling/nargo_cli/tests/stdlib-tests.rs b/tooling/nargo_cli/tests/stdlib-tests.rs index f44d21ea689..bdc92e625ab 100644 --- a/tooling/nargo_cli/tests/stdlib-tests.rs +++ b/tooling/nargo_cli/tests/stdlib-tests.rs @@ -1,4 +1,5 @@ //! Execute unit tests in the Noir standard library. +#![allow(clippy::items_after_test_module)] use clap::Parser; use fm::FileManager; use noirc_driver::{check_crate, file_manager_with_stdlib, CompileOptions};