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: Remove unnecessary duplication in how we test Noir compiler #2248

Merged
merged 1 commit into from
Aug 10, 2023
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
63 changes: 0 additions & 63 deletions crates/nargo_cli/src/cli/check_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,10 @@ fn create_input_toml_template(

#[cfg(test)]
mod tests {
use std::path::PathBuf;

use nargo_toml::{find_package_manifest, resolve_workspace_from_toml};
use noirc_abi::{AbiParameter, AbiType, AbiVisibility, Sign};
use noirc_driver::CompileOptions;

use super::create_input_toml_template;

const TEST_DATA_DIR: &str = "tests/target_tests_data";

#[test]
fn valid_toml_template() {
let typed_param = |name: &str, typ: AbiType| AbiParameter {
Expand Down Expand Up @@ -159,63 +153,6 @@ d2 = ["", "", ""]
"#;
assert_eq!(toml_str, expected_toml_str);
}

#[test]
fn pass() {
let pass_dir =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("{TEST_DATA_DIR}/pass"));

let config = CompileOptions::default();
let paths = std::fs::read_dir(pass_dir).unwrap();
for path in paths.flatten() {
let path = path.path();
let toml_path = find_package_manifest(&path).unwrap();
let workspace = resolve_workspace_from_toml(&toml_path, None).unwrap();
for package in &workspace {
assert!(super::check_package(package, &config).is_ok(), "path: {}", path.display());
}
}
}

#[test]
#[ignore = "This test fails because the reporter exits the process with 1"]
fn fail() {
let fail_dir =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("{TEST_DATA_DIR}/fail"));

let config = CompileOptions::default();
let paths = std::fs::read_dir(fail_dir).unwrap();
for path in paths.flatten() {
let path = path.path();
let toml_path = find_package_manifest(&path).unwrap();
let workspace = resolve_workspace_from_toml(&toml_path, None).unwrap();
for package in &workspace {
assert!(
super::check_package(package, &config).is_err(),
"path: {}",
path.display()
);
}
}
}

#[test]
fn pass_with_warnings() {
let pass_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join(format!("{TEST_DATA_DIR}/pass_dev_mode"));

let config = CompileOptions { deny_warnings: false, ..Default::default() };

let paths = std::fs::read_dir(pass_dir).unwrap();
for path in paths.flatten() {
let path = path.path();
let toml_path = find_package_manifest(&path).unwrap();
let workspace = resolve_workspace_from_toml(&toml_path, None).unwrap();
for package in &workspace {
assert!(super::check_package(package, &config).is_ok(), "path: {}", path.display());
}
}
}
}

/// Run the lexing, parsing, name resolution, and type checking passes and report any warnings
Expand Down
58 changes: 0 additions & 58 deletions crates/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,61 +86,3 @@ pub(crate) fn start_cli() -> eyre::Result<()> {

Ok(())
}

// FIXME: I not sure that this is the right place for this tests.
#[cfg(test)]
mod tests {
use fm::FileManager;
use noirc_driver::{check_crate, prepare_crate};
use noirc_errors::reporter;
use noirc_frontend::{graph::CrateGraph, hir::Context};

use std::path::{Path, PathBuf};

const TEST_DATA_DIR: &str = "tests/compile_tests_data";

/// Compiles a file and returns true if compilation was successful
///
/// This is used for tests.
fn file_compiles(root_dir: &Path, root_file: &Path) -> bool {
let fm = FileManager::new(root_dir);
let graph = CrateGraph::default();
let mut context = Context::new(fm, graph);
let crate_id = prepare_crate(&mut context, root_file);

let result = check_crate(&mut context, crate_id, false);
let success = result.is_ok();

let errors = match result {
Ok(warnings) => warnings,
Err(errors) => errors,
};

reporter::report_all(&context.file_manager, &errors, false);
success
}

#[test]
fn compilation_pass() {
let pass_dir =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("{TEST_DATA_DIR}/pass"));

let paths = std::fs::read_dir(&pass_dir).unwrap();
for path in paths.flatten() {
let path = path.path();
assert!(file_compiles(&pass_dir, &path), "path: {}", path.display());
}
}

#[test]
fn compilation_fail() {
let fail_dir =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("{TEST_DATA_DIR}/fail"));

let paths = std::fs::read_dir(&fail_dir).unwrap();
for path in paths.flatten() {
let path = path.path();
assert!(!file_compiles(&fail_dir, &path), "path: {}", path.display());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "fail_dup_func"
name = "constrain_typo"
type = "bin"
authors = [""]
compiler_version = "0.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "pass_import"
name = "duplicate_declaration"
type = "bin"
authors = [""]
compiler_version = "0.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "pass_basic"
name = "unused_variables"
type = "bin"
authors = [""]
compiler_version = "0.1"
Expand Down
7 changes: 0 additions & 7 deletions crates/nargo_cli/tests/compile_tests_data/fail/basic.nr

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions crates/nargo_cli/tests/compile_tests_data/fail/dup_func.nr

This file was deleted.

4 changes: 0 additions & 4 deletions crates/nargo_cli/tests/compile_tests_data/pass/basic.nr

This file was deleted.

11 changes: 0 additions & 11 deletions crates/nargo_cli/tests/compile_tests_data/pass/basic_import.nr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "fail_basic"
name = "import"
type = "bin"
authors = [""]
compiler_version = "0.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"private"},{"name":"y","type":{"kind":"field"},"visibility":"private"}],"param_witnesses":{"x":[1],"y":[2]},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/7VTSQ7DIAw0SRt66ltslmBu/UpRyf9fULVSieQmucWMhGw4jMdjcwOACX4wLTfi/m75+D0X+MfY4qNFPAcygsvjHEJNrpKnJ7pcOGKIZWZiihxfjr2vHDjlkhNmCr7SErNfGtmgyHXV6xFH4a+EUfZSU7PUO4l83YfhYCemDj3Bps7Wx/vBm2rxHkPqYZQFveXv1bfVnxEKyp3msz5YRZ2D0Cg/z4oPWGlYTZUFAAA=","proving_key":null,"verification_key":null}
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.