use std::fs::File;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::{env, fs};
const GIT_COMMIT: &&str = &"GIT_COMMIT";
fn main() -> Result<(), String> {
if env::var(GIT_COMMIT).is_err() {
let _ = build_data::set_GIT_COMMIT();
let _ = build_data::set_GIT_DIRTY();
let _ = build_data::no_debug_rebuilds();
println!("cargo:rustc-env=GIT_COMMIT=unknown");
println!("cargo:rustc-env=GIT_DIRTY=false");
}
let out_dir = env::var("OUT_DIR").unwrap();
let destination = Path::new(&out_dir).join("execute.rs");
let mut test_file = File::create(destination).unwrap();
let root_dir = match env::var("CARGO_MANIFEST_DIR") {
Ok(dir) => PathBuf::from(dir).parent().unwrap().parent().unwrap().to_path_buf(),
Err(_) => env::current_dir().unwrap(),
};
let test_dir = root_dir.join("test_programs");
if !test_dir.exists() {
return Ok(());
}
println!("cargo:rerun-if-changed=tests");
println!("cargo:rerun-if-changed={}", test_dir.as_os_str().to_str().unwrap());
generate_execution_success_tests(&mut test_file, &test_dir);
generate_execution_failure_tests(&mut test_file, &test_dir);
generate_execution_panic_tests(&mut test_file, &test_dir);
generate_noir_test_success_tests(&mut test_file, &test_dir);
generate_noir_test_failure_tests(&mut test_file, &test_dir);
generate_compile_success_empty_tests(&mut test_file, &test_dir);
generate_compile_success_contract_tests(&mut test_file, &test_dir);
generate_compile_success_no_bug_tests(&mut test_file, &test_dir);
generate_compile_success_with_bug_tests(&mut test_file, &test_dir);
generate_compile_failure_tests(&mut test_file, &test_dir);
generate_minimal_execution_success_tests(&mut test_file, &test_dir);
generate_interpret_execution_success_tests(&mut test_file, &test_dir);
generate_interpret_execution_failure_tests(&mut test_file, &test_dir);
generate_comptime_interpret_execution_success_tests(&mut test_file, &test_dir);
generate_comptime_interpret_execution_failure_tests(&mut test_file, &test_dir);
generate_brillig_small_stack_execution_success_tests(&mut test_file, &test_dir);
generate_fuzzing_failure_tests(&mut test_file, &test_dir);
generate_nargo_expand_execution_success_tests(&mut test_file, &test_dir);
generate_nargo_expand_compile_tests_with_ignore_list(
"compile_success_empty",
&mut test_file,
&test_dir,
&IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_EMPTY_TESTS,
);
generate_nargo_expand_compile_tests("compile_success_contract", &mut test_file, &test_dir);
generate_nargo_expand_compile_tests_with_ignore_list(
"compile_success_no_bug",
&mut test_file,
&test_dir,
&IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_NO_BUG_TESTS,
);
generate_nargo_expand_compile_tests_with_ignore_list(
"compile_success_with_bug",
&mut test_file,
&test_dir,
&IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_WITH_BUG_TESTS,
);
Ok(())
}
const IGNORED_BRILLIG_SMALL_STACK_TESTS: [&str; 4] = [
"brillig_block_parameter_liveness",
"reference_counts_inliner_0",
"reference_counts_inliner_min",
"reference_counts_vectors_inliner_0",
];
const IGNORED_BRILLIG_TESTS: [&str; 11] = [
"bigint",
"fold_after_inlined_calls",
"fold_basic",
"fold_basic_nested_call",
"fold_call_witness_condition",
"fold_complex_outputs",
"fold_distinct_return",
"fold_fibonacci",
"fold_numeric_generic_poseidon",
"is_unconstrained",
"regression_10158",
];
const INLINER_MIN_OVERRIDES: [(&str, i64); 1] = [
("eddsa", 0),
];
const INLINER_MAX_OVERRIDES: [(&str, i64); 0] = [];
const INLINER_OVERRIDES: [(&str, i64); 4] = [
("reference_counts_inliner_0", 0),
("reference_counts_inliner_min", i64::MIN),
("reference_counts_inliner_max", i64::MAX),
("reference_counts_vectors_inliner_0", 0),
];
const TESTS_WITH_EXPECTED_WARNINGS: [&str; 5] = [
"brillig_cast",
"macros_in_comptime",
"enums",
"comptime_enums",
"brillig_continue_break",
];
const IGNORED_INTERPRET_EXECUTION_TESTS: [&str; 2] = [
"regression_4709",
"reference_counts_inliner_max",
];
const IGNORED_COMPTIME_INTERPRET_EXECUTION_TESTS: [&str; 0] = [];
const PANICKING_COMPTIME_INTERPRET_EXECUTION_TESTS: [&str; 5] = [
"reference_counts_inliner_0",
"reference_counts_inliner_max",
"reference_counts_inliner_min",
"reference_counts_vectors_inliner_0",
"regression_7323",
];
const PANICKING_COMPTIME_INTERPRET_EXECUTION_FAILURE_TESTS: [&str; 0] = [];
const IGNORED_COMPTIME_INTERPRET_EXECUTION_FAILURE_TESTS: [&str; 0] = [];
const IGNORED_COMPTIME_INTERPRET_EXECUTION_STDOUT_CHECK_TESTS: [&str; 4] =
["debug_logs", "regression_10156", "regression_10158", "regression_9578"];
const IGNORED_MINIMAL_EXECUTION_TESTS: [&str; 16] = [
"array_to_vector_constant_length",
"static_assert_empty_loop",
"brillig_cow_regression",
"brillig_pedersen",
"import",
"merkle_insert",
"pedersen_check",
"pedersen_hash",
"pedersen_commitment",
"simple_shield",
"strings",
"lambda_from_dynamic_if",
"regression_10156",
"reference_counts_inliner_max",
"reference_counts_inliner_min",
"reference_counts_inliner_0",
];
const IGNORED_NARGO_EXPAND_EXECUTION_TESTS: [&str; 10] = [
"custom_entry",
"diamond_deps_0",
"numeric_type_alias",
"negative_associated_constants",
"overlapping_dep_and_mod",
"regression_9116",
"regression_10466",
"trait_associated_constant",
"workspace",
"workspace_default_member",
];
const TESTS_WITHOUT_STDOUT_CHECK: [&str; 0] = [];
const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_EMPTY_TESTS: [&str; 7] = [
"overlapping_dep_and_mod",
"reexports",
"trait_function_calls",
"trait_method_mut_self",
"trait_static_methods",
"workspace_reexport_bug",
"trait_call_in_global",
];
const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_NO_BUG_TESTS: [&str; 17] = [
"noirc_frontend_tests_check_trait_as_type_as_fn_parameter",
"noirc_frontend_tests_check_trait_as_type_as_two_fn_parameters",
"noirc_frontend_tests_enums_match_on_empty_enum",
"noirc_frontend_tests_traits_trait_alias_polymorphic_inheritance",
"noirc_frontend_tests_traits_trait_alias_single_member",
"noirc_frontend_tests_traits_trait_alias_two_members",
"noirc_frontend_tests_traits_trait_impl_with_where_clause_with_trait_with_associated_numeric",
"noirc_frontend_tests_traits_accesses_associated_type_inside_trait_impl_using_self",
"noirc_frontend_tests_traits_accesses_associated_type_inside_trait_using_self",
"noirc_frontend_tests_u32_globals_as_sizes_in_types",
"noirc_frontend_tests_visibility_visibility_bug_inside_comptime",
"noirc_frontend_tests_aliases_identity_numeric_type_alias_works",
"noirc_frontend_tests_aliases_type_alias_to_numeric_as_generic",
"noirc_frontend_tests_aliases_type_alias_to_numeric_generic",
"noirc_frontend_tests_traits_trait_bound_on_implementing_type",
"function_registry",
"regression_10887", ];
const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_WITH_BUG_TESTS: [&str; 0] = [];
fn read_test_cases(
test_data_dir: &Path,
test_sub_dir: &str,
) -> impl Iterator<Item = (String, PathBuf)> {
let test_data_dir = test_data_dir.join(test_sub_dir);
let test_case_dirs =
fs::read_dir(test_data_dir).unwrap().flatten().filter(|c| c.path().is_dir());
test_case_dirs.into_iter().filter_map(|dir| {
if !dir.path().join("Nargo.toml").exists() {
return None;
}
let test_name =
dir.file_name().into_string().expect("Directory can't be converted to string");
if test_name.contains('-') {
panic!(
"Invalid test directory: {test_name}. Cannot include `-`, please convert to `_`"
);
}
Some((test_name, dir.path()))
})
}
#[derive(Default)]
struct MatrixConfig {
vary_brillig: bool,
vary_inliner: bool,
min_inliner: i64,
max_inliner: i64,
}
enum Inliner {
Min,
Default,
Max,
Custom(i64),
}
impl Inliner {
fn value(&self) -> i64 {
match self {
Inliner::Min => i64::MIN,
Inliner::Default => 0,
Inliner::Max => i64::MAX,
Inliner::Custom(i) => *i,
}
}
fn label(&self) -> String {
match self {
Inliner::Min => "i64::MIN".to_string(),
Inliner::Default => "0".to_string(),
Inliner::Max => "i64::MAX".to_string(),
Inliner::Custom(i) => i.to_string(),
}
}
}
fn generate_test_cases(
test_file: &mut File,
test_name: &str,
test_dir: &std::path::Display,
test_command: &str,
test_content: &str,
matrix_config: &MatrixConfig,
) {
let brillig_cases = if matrix_config.vary_brillig { vec![false, true] } else { vec![false] };
let inliner_cases = if matrix_config.vary_inliner {
let mut cases = vec![Inliner::Min, Inliner::Default, Inliner::Max];
if !cases.iter().any(|c| c.value() == matrix_config.min_inliner) {
cases.push(Inliner::Custom(matrix_config.min_inliner));
}
if !cases.iter().any(|c| c.value() == matrix_config.max_inliner) {
cases.push(Inliner::Custom(matrix_config.max_inliner));
}
cases
} else {
vec![Inliner::Default]
};
let mut test_cases = Vec::new();
for brillig in &brillig_cases {
for inliner in &inliner_cases {
let inliner_range = matrix_config.min_inliner..=matrix_config.max_inliner;
if *brillig && !inliner_range.contains(&inliner.value()) {
continue;
}
test_cases.push(format!(
"#[test_case::test_case(ForceBrillig({brillig}), Inliner({}))]",
inliner.label()
));
}
}
let test_cases = test_cases.join("\n");
write!(
test_file,
r#"
{test_cases}
fn test_{test_name}(force_brillig: ForceBrillig, inliner_aggressiveness: Inliner) {{
let test_program_dir = PathBuf::from("{test_dir}");
#[allow(unused_variables)]
let runtime = if force_brillig.0 {{
Runtime::Brillig
}} else {{
Runtime::Acir
}};
#[allow(unused_mut)]
let (mut nargo, target_dir) = setup_nargo_command(&test_program_dir, "{test_command}", force_brillig, inliner_aggressiveness);
{test_content}
drop(target_dir);
}}
"#
)
.expect("Could not write templated test file.");
}
fn generate_fuzzing_test_case(
test_file: &mut File,
test_name: &str,
test_dir: &std::path::Display,
test_content: &str,
timeout: usize,
) {
let timeout_str = timeout.to_string();
write!(
test_file,
r#"
#[test]
fn test_{test_name}() {{
let corpus_dir = assert_fs::TempDir::new().unwrap();
let fuzzing_failure_dir = assert_fs::TempDir::new().unwrap();
let test_program_dir = PathBuf::from("{test_dir}");
#[allow(deprecated)]
let mut nargo = Command::cargo_bin("nargo").unwrap();
nargo.arg("--program-dir").arg(test_program_dir);
nargo.arg("fuzz").arg("--timeout").arg("{timeout_str}");
nargo.arg("--corpus-dir").arg(corpus_dir.path());
nargo.arg("--fuzzing-failure-dir").arg(fuzzing_failure_dir.path());
{test_content}
}}
"#
)
.expect("Could not write templated test file.");
}
fn generate_execution_success_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "execution_success";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod {test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
let test_dir = test_dir.display();
let check_stdout = !TESTS_WITHOUT_STDOUT_CHECK.contains(&test_name.as_str());
generate_test_cases(
test_file,
&test_name,
&test_dir,
"execute",
&format!("execution_success(nargo, test_program_dir, {check_stdout});",),
&MatrixConfig {
vary_brillig: !IGNORED_BRILLIG_TESTS.contains(&test_name.as_str()),
vary_inliner: true,
min_inliner: min_inliner(&test_name),
max_inliner: max_inliner(&test_name),
},
);
}
writeln!(test_file, "}}").unwrap();
}
fn max_inliner(test_name: &str) -> i64 {
INLINER_MAX_OVERRIDES
.iter()
.chain(&INLINER_OVERRIDES)
.find(|(n, _)| *n == test_name)
.map_or(i64::MAX, |(_, i)| *i)
}
fn min_inliner(test_name: &str) -> i64 {
INLINER_MIN_OVERRIDES
.iter()
.chain(&INLINER_OVERRIDES)
.find(|(n, _)| *n == test_name)
.map_or(i64::MIN, |(_, i)| *i)
}
fn generate_execution_failure_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "execution_failure";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod {test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
let test_dir = test_dir.display();
generate_test_cases(
test_file,
&test_name,
&test_dir,
"execute",
"execution_failure(nargo, test_program_dir, runtime);",
&MatrixConfig {
vary_brillig: !IGNORED_BRILLIG_TESTS.contains(&test_name.as_str()),
..Default::default()
},
);
}
writeln!(test_file, "}}").unwrap();
}
fn generate_execution_panic_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "execution_panic";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod {test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
let test_dir = test_dir.display();
generate_test_cases(
test_file,
&test_name,
&test_dir,
"execute",
"execution_panic(nargo);",
&MatrixConfig::default(),
);
}
writeln!(test_file, "}}").unwrap();
}
fn generate_comptime_interpret_execution_success_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "execution_success";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod comptime_interpret_{test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
if IGNORED_COMPTIME_INTERPRET_EXECUTION_TESTS.contains(&test_name.as_str()) {
continue;
}
let should_panic =
if PANICKING_COMPTIME_INTERPRET_EXECUTION_TESTS.contains(&test_name.as_str()) {
"#[should_panic]"
} else {
""
};
let check_stdout =
!IGNORED_COMPTIME_INTERPRET_EXECUTION_STDOUT_CHECK_TESTS.contains(&test_name.as_str());
let test_dir = test_dir.display();
write!(
test_file,
r#"
#[test]
{should_panic}
fn test_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
nargo_execute_comptime(test_program_dir, {check_stdout});
}}
"#
)
.unwrap();
}
writeln!(test_file, "}}").unwrap();
}
fn generate_comptime_interpret_execution_failure_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "execution_failure";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod comptime_interpret_{test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
if IGNORED_COMPTIME_INTERPRET_EXECUTION_FAILURE_TESTS.contains(&test_name.as_str()) {
continue;
}
let should_panic =
if PANICKING_COMPTIME_INTERPRET_EXECUTION_FAILURE_TESTS.contains(&test_name.as_str()) {
"#[should_panic]"
} else {
""
};
let test_dir = test_dir.display();
write!(
test_file,
r#"
#[test]
{should_panic}
fn test_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
nargo_execute_comptime_expect_failure(test_program_dir);
}}
"#
)
.unwrap();
}
writeln!(test_file, "}}").unwrap();
}
fn generate_brillig_small_stack_execution_success_tests(
test_file: &mut File,
test_data_dir: &Path,
) {
let test_type = "execution_success";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod brillig_small_stack_{test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
if IGNORED_BRILLIG_TESTS.contains(&test_name.as_str()) {
continue;
}
let should_panic = if IGNORED_BRILLIG_SMALL_STACK_TESTS.contains(&test_name.as_str()) {
"#[should_panic]"
} else {
""
};
let test_dir = test_dir.display();
write!(
test_file,
r#"
#[test]
{should_panic}
fn test_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
nargo_execute_brillig_small_stack(test_program_dir);
}}
"#
)
.unwrap();
}
writeln!(test_file, "}}").unwrap();
}
fn generate_fuzzing_failure_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "fuzzing_failure";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod {test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
let test_dir = test_dir.display();
generate_fuzzing_test_case(
test_file,
&test_name,
&test_dir,
r#"
nargo.assert().failure().stderr(
predicate::str::contains("Failing input").and(
predicate::str::contains("got a different failing assertion").not())
);
"#,
240,
);
}
writeln!(test_file, "}}").unwrap();
}
fn generate_noir_test_success_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "noir_test_success";
let test_cases = read_test_cases(test_data_dir, "noir_test_success");
writeln!(
test_file,
"mod {test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
let test_dir = test_dir.display();
generate_test_cases(
test_file,
&test_name,
&test_dir,
"test",
"noir_test_success(nargo);",
&MatrixConfig::default(),
);
}
writeln!(test_file, "}}").unwrap();
}
fn generate_noir_test_failure_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "noir_test_failure";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod {test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
let test_dir = test_dir.display();
generate_test_cases(
test_file,
&test_name,
&test_dir,
"test",
"noir_test_failure(nargo);",
&MatrixConfig::default(),
);
}
writeln!(test_file, "}}").unwrap();
}
fn generate_compile_success_empty_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "compile_success_empty";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod {test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
let test_dir = test_dir.display();
generate_test_cases(
test_file,
&test_name,
&test_dir,
"info",
&format!(
"compile_success_empty(nargo, {});",
!TESTS_WITH_EXPECTED_WARNINGS.contains(&test_name.as_str())
),
&MatrixConfig::default(),
);
}
writeln!(test_file, "}}").unwrap();
}
fn generate_compile_success_contract_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "compile_success_contract";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod {test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
let test_dir = test_dir.display();
generate_test_cases(
test_file,
&test_name,
&test_dir,
"compile",
"compile_success_contract(nargo);",
&MatrixConfig::default(),
);
}
writeln!(test_file, "}}").unwrap();
}
fn generate_compile_success_no_bug_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "compile_success_no_bug";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod {test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
let test_dir = test_dir.display();
generate_test_cases(
test_file,
&test_name,
&test_dir,
"compile",
"compile_success_no_bug(nargo);",
&MatrixConfig::default(),
);
}
writeln!(test_file, "}}").unwrap();
}
fn generate_compile_success_with_bug_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "compile_success_with_bug";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod {test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
let test_dir = test_dir.display();
generate_test_cases(
test_file,
&test_name,
&test_dir,
"compile",
"compile_success_with_bug(nargo, test_program_dir);",
&MatrixConfig::default(),
);
}
writeln!(test_file, "}}").unwrap();
}
fn generate_compile_failure_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "compile_failure";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod {test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
let test_dir = test_dir.display();
generate_test_cases(
test_file,
&test_name,
&test_dir,
"compile",
"compile_failure(nargo, test_program_dir);",
&MatrixConfig::default(),
);
}
writeln!(test_file, "}}").unwrap();
}
fn generate_interpret_execution_success_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "execution_success";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod interpret_{test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
if IGNORED_INTERPRET_EXECUTION_TESTS.contains(&test_name.as_str()) {
continue;
}
let test_dir = test_dir.display();
generate_test_cases(
test_file,
&test_name,
&test_dir,
"interpret",
"interpret_execution_success(nargo);",
&MatrixConfig {
vary_brillig: !IGNORED_BRILLIG_TESTS.contains(&test_name.as_str()),
vary_inliner: true,
min_inliner: min_inliner(&test_name),
max_inliner: max_inliner(&test_name),
},
);
}
writeln!(test_file, "}}").unwrap();
}
fn generate_interpret_execution_failure_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "execution_failure";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod interpret_{test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
let test_dir = test_dir.display();
generate_test_cases(
test_file,
&test_name,
&test_dir,
"interpret",
"interpret_execution_failure(nargo);",
&MatrixConfig {
vary_brillig: !IGNORED_BRILLIG_TESTS.contains(&test_name.as_str()),
..Default::default()
},
);
}
writeln!(test_file, "}}").unwrap();
}
fn generate_minimal_execution_success_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "execution_success";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"mod minimal_{test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
if IGNORED_MINIMAL_EXECUTION_TESTS.contains(&test_name.as_str()) {
continue;
}
let test_dir = test_dir.display();
let check_stdout = !TESTS_WITHOUT_STDOUT_CHECK.contains(&test_name.as_str());
generate_test_cases(
test_file,
&test_name,
&test_dir,
"execute",
&format!(
r#"
nargo.arg("--minimal-ssa");
execution_success(nargo, test_program_dir, {check_stdout});
"#,
),
&MatrixConfig {
vary_brillig: false,
vary_inliner: false,
min_inliner: min_inliner(&test_name),
max_inliner: max_inliner(&test_name),
},
);
}
writeln!(test_file, "}}").unwrap();
}
fn generate_nargo_expand_execution_success_tests(test_file: &mut File, test_data_dir: &Path) {
let test_type = "execution_success";
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"
mod nargo_expand_{test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
if IGNORED_NARGO_EXPAND_EXECUTION_TESTS.contains(&test_name.as_str()) {
continue;
}
let test_dir = test_dir.display();
write!(
test_file,
r#"
#[test]
fn test_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
nargo_expand_execute(test_program_dir);
}}
"#
)
.unwrap();
}
writeln!(test_file, "}}").unwrap();
}
fn generate_nargo_expand_compile_tests(
test_type: &'static str,
test_file: &mut File,
test_data_dir: &Path,
) {
generate_nargo_expand_compile_tests_with_ignore_list(test_type, test_file, test_data_dir, &[]);
}
fn generate_nargo_expand_compile_tests_with_ignore_list(
test_type: &'static str,
test_file: &mut File,
test_data_dir: &Path,
ignore: &[&str],
) {
let test_cases = read_test_cases(test_data_dir, test_type);
writeln!(
test_file,
"
mod nargo_expand_{test_type} {{
use super::*;
"
)
.unwrap();
for (test_name, test_dir) in test_cases {
let should_panic =
if ignore.contains(&test_name.as_str()) { "#[should_panic]" } else { "" };
let test_dir = test_dir.display();
write!(
test_file,
r#"
#[test]
{should_panic}
fn test_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");
nargo_expand_compile(test_program_dir, "{test_type}");
}}
"#
)
.unwrap();
}
writeln!(test_file, "}}").unwrap();
}