Skip to content

Commit

Permalink
chore: export run_test through nargo_cli
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Jun 18, 2024
1 parent 0ec71b1 commit 4375e87
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 51 deletions.
2 changes: 2 additions & 0 deletions tooling/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ mod lsp_cmd;
mod new_cmd;
mod test_cmd;

pub use test_cmd::run_test;

const GIT_HASH: &str = env!("GIT_COMMIT");
const IS_DIRTY: &str = env!("GIT_DIRTY");
const NARGO_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_cli/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn run_tests<S: BlackBoxFunctionSolver<FieldElement> + Default>(
Ok(test_report)
}

fn run_test<S: BlackBoxFunctionSolver<FieldElement> + Default>(
pub fn run_test<S: BlackBoxFunctionSolver<FieldElement> + Default>(
file_manager: &FileManager,
parsed_files: &ParsedFiles,
package: &Package,
Expand Down
6 changes: 6 additions & 0 deletions tooling/nargo_cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[allow(clippy::all)]
#[allow(dead_code)]
mod cli;
mod errors;

pub use cli::run_test;
5 changes: 5 additions & 0 deletions tooling/nargo_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//! This name was used because it sounds like `cargo` and
//! Noir Package Manager abbreviated is npm, which is already taken.
// Hack to appease compiler warnings
use nargo_cli as _;

mod cli;
mod errors;

Expand All @@ -17,6 +20,8 @@ use color_eyre::config::HookBuilder;
use tracing_appender::rolling;
use tracing_subscriber::{fmt::format::FmtSpan, EnvFilter};

pub use cli::run_test;

const PANIC_MESSAGE: &str = "This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.\nIf there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml";

fn main() {
Expand Down
64 changes: 14 additions & 50 deletions tooling/nargo_cli/tests/stdlib-tests.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use std::io::Write;
use std::{collections::BTreeMap, path::PathBuf};

use acvm::blackbox_solver::StubbedBlackBoxSolver;
use bn254_blackbox_solver::Bn254BlackBoxSolver;
use fm::FileManager;
use noirc_driver::{check_crate, compile_no_check, file_manager_with_stdlib, CompileOptions};
use noirc_driver::{check_crate, file_manager_with_stdlib, CompileOptions};
use noirc_frontend::hir::FunctionNameMatch;

use nargo::{
ops::{report_errors, run_test, TestStatus},
ops::{report_errors, TestStatus},
package::{Package, PackageType},
parse_all, prepare_package,
};
use nargo_cli::run_test;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};

#[test]
Expand Down Expand Up @@ -46,53 +47,16 @@ fn run_stdlib_tests() {

let test_report: Vec<(String, TestStatus)> = test_functions
.into_iter()
.map(|(test_name, test_function)| {
let test_function_has_no_arguments = context
.def_interner
.function_meta(&test_function.get_id())
.function_signature()
.0
.is_empty();

let status = if test_function_has_no_arguments {
run_test(
&StubbedBlackBoxSolver,
&mut context,
&test_function,
false,
None,
&CompileOptions::default(),
)
} else {
use noir_fuzzer::FuzzedExecutor;
use proptest::test_runner::TestRunner;

let compiled_program = compile_no_check(
&mut context,
&CompileOptions::default(),
test_function.get_id(),
None,
false,
);
match compiled_program {
Ok(compiled_program) => {
let runner = TestRunner::default();

let fuzzer = FuzzedExecutor::new(compiled_program.into(), runner);

let result = fuzzer.fuzz();
if result.success {
TestStatus::Pass
} else {
TestStatus::Fail {
message: result.reason.unwrap_or_default(),
error_diagnostic: None,
}
}
}
Err(err) => TestStatus::CompileError(err.into()),
}
};
.map(|(test_name, _)| {
let status = run_test::<Bn254BlackBoxSolver>(
&file_manager,
&parsed_files,
&dummy_package,
&test_name,
false,
None,
&CompileOptions::default(),
);
(test_name, status)
})
.collect();
Expand Down

0 comments on commit 4375e87

Please sign in to comment.