Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: split test_programs into modules #6101

Merged
merged 7 commits into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 73 additions & 11 deletions tooling/nargo_cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ fn read_test_cases(

fn generate_test_case(
test_file: &mut File,
test_type: &str,
test_name: &str,
test_dir: &std::path::Display,
test_content: &str,
Expand All @@ -90,7 +89,7 @@ fn generate_test_case(
test_file,
r#"
#[test]
fn {test_type}_{test_name}() {{
fn test_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");

let mut nargo = Command::cargo_bin("nargo").unwrap();
Expand All @@ -105,12 +104,19 @@ fn {test_type}_{test_name}() {{
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();

generate_test_case(
test_file,
test_type,
&test_name,
&test_dir,
r#"
Expand All @@ -122,7 +128,6 @@ fn generate_execution_success_tests(test_file: &mut File, test_data_dir: &Path)
if !IGNORED_BRILLIG_TESTS.contains(&test_name.as_str()) {
generate_test_case(
test_file,
test_type,
&format!("{test_name}_brillig"),
&test_dir,
r#"
Expand All @@ -132,17 +137,25 @@ fn generate_execution_success_tests(test_file: &mut File, test_data_dir: &Path)
);
}
}
writeln!(test_file, "}}").unwrap();
}

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_case(
test_file,
test_type,
&test_name,
&test_dir,
r#"
Expand All @@ -151,17 +164,25 @@ fn generate_execution_failure_tests(test_file: &mut File, test_data_dir: &Path)
nargo.assert().failure().stderr(predicate::str::contains("The application panicked (crashed).").not());"#,
);
}
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_case(
test_file,
test_type,
&test_name,
&test_dir,
r#"
Expand All @@ -170,16 +191,24 @@ fn generate_noir_test_success_tests(test_file: &mut File, test_data_dir: &Path)
nargo.assert().success();"#,
);
}
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_case(
test_file,
test_type,
&test_name,
&test_dir,
r#"
Expand All @@ -188,11 +217,20 @@ fn generate_noir_test_failure_tests(test_file: &mut File, test_data_dir: &Path)
nargo.assert().failure();"#,
);
}
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();

Expand All @@ -213,7 +251,6 @@ fn generate_compile_success_empty_tests(test_file: &mut File, test_data_dir: &Pa

generate_test_case(
test_file,
test_type,
&test_name,
&test_dir,
&format!(
Expand All @@ -224,59 +261,84 @@ fn generate_compile_success_empty_tests(test_file: &mut File, test_data_dir: &Pa
),
);
}
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_case(
test_file,
test_type,
&test_name,
&test_dir,
r#"
nargo.arg("compile").arg("--force");
nargo.assert().success();"#,
);
}
writeln!(test_file, "}}").unwrap();
}

/// Generate tests for checking that the contract compiles and there are no "bugs" in stderr
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_case(
test_file,
test_type,
&test_name,
&test_dir,
r#"
nargo.arg("compile").arg("--force");
nargo.assert().success().stderr(predicate::str::contains("bug:").not());"#,
);
}
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_case(
test_file,
test_type,
&test_name,
&test_dir,
r#"nargo.arg("compile").arg("--force");

nargo.assert().failure().stderr(predicate::str::contains("The application panicked (crashed).").not());"#,
);
}
writeln!(test_file, "}}").unwrap();
}
Loading