Skip to content

Commit

Permalink
chore: Remove unnecessary duplication in how we test Noir compiler (#…
Browse files Browse the repository at this point in the history
…2248)

chore: remove unnecessary tests
  • Loading branch information
TomAFrench authored Aug 10, 2023
1 parent ed5273c commit 5690229
Show file tree
Hide file tree
Showing 24 changed files with 5 additions and 183 deletions.
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.

0 comments on commit 5690229

Please sign in to comment.