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: separate tests for execution failures from compilation failures #4559

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
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

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion test_programs/compile_failure/depend_on_bin/Prover.toml

This file was deleted.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
26 changes: 0 additions & 26 deletions test_programs/compile_failure/hashmap_load_factor/Prover.toml

This file was deleted.

Empty file.
2 changes: 0 additions & 2 deletions test_programs/compile_failure/orphaned_trait_impl/Prover.toml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

41 changes: 40 additions & 1 deletion tooling/nargo_cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn main() {
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_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);
Expand Down Expand Up @@ -86,6 +87,44 @@ fn execution_success_{test_name}() {{
}
}

fn generate_execution_failure_tests(test_file: &mut File, test_data_dir: &Path) {
let test_sub_dir = "execution_failure";
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());

for test_dir in test_case_dirs {
let test_name =
test_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 `_`"
);
};
let test_dir = &test_dir.path();

write!(
test_file,
r#"
#[test]
fn execution_failure_{test_name}() {{
let test_program_dir = PathBuf::from("{test_dir}");

let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.env("NARGO_BACKEND_PATH", path_to_mock_backend());
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("execute").arg("--force");

cmd.assert().failure().stderr(predicate::str::contains("The application panicked (crashed).").not());
}}
"#,
test_dir = test_dir.display(),
)
.expect("Could not write templated test file.");
}
}

fn generate_noir_test_success_tests(test_file: &mut File, test_data_dir: &Path) {
let test_sub_dir = "noir_test_success";
let test_data_dir = test_data_dir.join(test_sub_dir);
Expand Down Expand Up @@ -281,7 +320,7 @@ fn compile_failure_{test_name}() {{
let mut cmd = Command::cargo_bin("nargo").unwrap();
cmd.env("NARGO_BACKEND_PATH", path_to_mock_backend());
cmd.arg("--program-dir").arg(test_program_dir);
cmd.arg("execute").arg("--force");
cmd.arg("compile").arg("--force");

cmd.assert().failure().stderr(predicate::str::contains("The application panicked (crashed).").not());
}}
Expand Down
Loading