Skip to content
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
14 changes: 10 additions & 4 deletions compiler/noirc_frontend/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub(crate) fn get_program<'a, 'b>(
let allow_parser_errors = false;
get_program_with_options(
src,
test_path,
Some(test_path),
expect,
allow_parser_errors,
FrontendOptions::test_default(),
Expand All @@ -82,9 +82,13 @@ pub enum Expect {
/// Compile a program.
///
/// The stdlib is not available for these snippets.
///
/// An optional test path is supplied as an argument.
/// The existence of a test path indicates that we want to emit integration tests
/// for the supplied program as well.
pub(crate) fn get_program_with_options(
src: &str,
test_path: &str,
test_path: Option<&str>,
expect: Expect,
allow_parser_errors: bool,
options: FrontendOptions,
Expand Down Expand Up @@ -136,7 +140,10 @@ pub(crate) fn get_program_with_options(
));
}

emit_compile_test(test_path, src, expect);
if let Some(test_path) = test_path {
emit_compile_test(test_path, src, expect);
}

(program, context, errors)
}

Expand Down Expand Up @@ -164,7 +171,6 @@ fn emit_compile_test(test_path: &str, src: &str, mut expect: Expect) {
let error_to_warn_cases = [
"cast_256_to_u8_size_checks",
"enums_errors_on_unspecified_unstable_enum",
"immutable_references_without_ownership_feature",
"imports_warns_on_use_of_private_exported_item",
"metaprogramming_does_not_fail_to_parse_macro_on_parser_warning",
"resolve_unused_var",
Expand Down
33 changes: 16 additions & 17 deletions compiler/noirc_frontend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

pub(crate) fn get_program_using_features(
src: &str,
test_path: &str,
test_path: Option<&str>,
expect: Expect,
features: &[UnstableFeature],
) -> (ParsedModule, Context<'static, 'static>, Vec<CompilationError>) {
Expand Down Expand Up @@ -74,7 +74,7 @@
///
/// this method will check that compiling the program without those error markers
/// will produce errors at those locations and with/ those messages.
fn check_errors(src: &str, test_path: &str) {
fn check_errors(src: &str, test_path: Option<&str>) {
let allow_parser_errors = false;
let monomorphize = false;
check_errors_with_options(
Expand All @@ -86,7 +86,7 @@
);
}

fn check_errors_using_features(src: &str, test_path: &str, features: &[UnstableFeature]) {
fn check_errors_using_features(src: &str, test_path: Option<&str>, features: &[UnstableFeature]) {
let allow_parser_errors = false;
let monomorphize = false;
let options =
Expand All @@ -95,13 +95,13 @@
}

#[allow(unused)]
pub(super) fn check_monomorphization_error(src: &str, test_path: &str) {
pub(super) fn check_monomorphization_error(src: &str, test_path: Option<&str>) {
check_monomorphization_error_using_features(src, test_path, &[]);
}

pub(super) fn check_monomorphization_error_using_features(
src: &str,
test_path: &str,
test_path: Option<&str>,
features: &[UnstableFeature],
) {
let allow_parser_errors = false;
Expand All @@ -117,7 +117,7 @@

fn check_errors_with_options(
src: &str,
test_path: &str,
test_path: Option<&str>,
allow_parser_errors: bool,
monomorphize: bool,
options: FrontendOptions,
Expand Down Expand Up @@ -284,7 +284,7 @@

let chars = line.chars().collect::<Vec<_>>();
let first_caret = chars.iter().position(|c| *c == char).unwrap();
let last_caret = chars.iter().rposition(|c| *c == char).unwrap();

Check warning on line 287 in compiler/noirc_frontend/src/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (rposition)
let start = byte - last_line_length;
let span = Span::from((start + first_caret - 1) as u32..(start + last_caret) as u32);
let error = line.trim().trim_start_matches(char).trim().to_string();
Expand All @@ -305,7 +305,7 @@
($src:expr, $expect:expr, $features:expr) => {
$crate::tests::get_program_using_features(
$src,
$crate::function_path!(),
Some($crate::function_path!()),
$expect,
$features,
)
Expand Down Expand Up @@ -334,7 +334,7 @@
($src:expr, $expect:expr, $allow_parser_errors:expr, $options:expr) => {
$crate::tests::get_program_with_options(
$src,
$crate::function_path!(),
Some($crate::function_path!()),
$expect,
$allow_parser_errors,
$options,
Expand All @@ -354,7 +354,7 @@
#[macro_export]
macro_rules! check_errors {
($src:expr) => {
$crate::tests::check_errors($src, $crate::function_path!())
$crate::tests::check_errors($src, Some($crate::function_path!()))
};
($src:expr,) => {
$crate::check_errors!($src)
Expand All @@ -365,15 +365,15 @@
#[macro_export]
macro_rules! check_errors_using_features {
($src:expr, $features:expr) => {
$crate::tests::check_errors_using_features($src, $crate::function_path!(), $features)
$crate::tests::check_errors_using_features($src, Some($crate::function_path!()), $features)
};
}

// NOTE: this will fail in CI when called twice within one test: test names must be unique
#[macro_export]
macro_rules! check_monomorphization_error {
($src:expr) => {
$crate::tests::check_monomorphization_error($src, $crate::function_path!())
$crate::tests::check_monomorphization_error($src, Some($crate::function_path!()))
};
}

Expand All @@ -383,7 +383,7 @@
($src:expr, $features:expr) => {
$crate::tests::check_monomorphization_error_using_features(
$src,
$crate::function_path!(),
Some($crate::function_path!()),
$features,
)
};
Expand Down Expand Up @@ -2071,7 +2071,7 @@
T::deserialize([0, 1])
}
"#;
check_errors(src, &format!("{}_1", function_path!()));
check_errors(src, Some(&format!("{}_1", function_path!())));

// TODO: improve the error location for the array (should be on N)
let src = r#"
Expand All @@ -2095,7 +2095,7 @@
T::deserialize(fields)
}
"#;
check_errors(src, &format!("{}_2", function_path!()));
check_errors(src, Some(&format!("{}_2", function_path!())));
}

#[named]
Expand Down Expand Up @@ -3231,7 +3231,7 @@
// wouldn't panic due to infinite recursion, but the errors asserted here
// come from the compilation checks, which does static analysis to catch the
// problem before it even has a chance to cause a panic.
let srcs = vec![

Check warning on line 3234 in compiler/noirc_frontend/src/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (srcs)
r#"
fn main() {
^^^^ function `main` cannot return without recursing
Expand Down Expand Up @@ -3313,15 +3313,15 @@
"#,
];

for (index, src) in srcs.into_iter().enumerate() {

Check warning on line 3316 in compiler/noirc_frontend/src/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (srcs)
check_errors(src, &format!("{}_{index}", function_path!()));
check_errors(src, Some(&format!("{}_{index}", function_path!())));
}
}

#[named]
#[test]
fn unconditional_recursion_pass() {
let srcs = vec![

Check warning on line 3324 in compiler/noirc_frontend/src/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (srcs)
r#"
fn main() {
if false { main(); }
Expand Down Expand Up @@ -3363,7 +3363,7 @@
"#,
];

for (index, src) in srcs.into_iter().enumerate() {

Check warning on line 3366 in compiler/noirc_frontend/src/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (srcs)
assert_no_errors(src, &format!("{}_{index}", function_path!()));
}
}
Expand Down Expand Up @@ -4379,7 +4379,6 @@
check_errors!(src);
}

#[named]
#[test]
fn immutable_references_with_ownership_feature() {
let src = r#"
Expand All @@ -4392,7 +4391,7 @@
"#;

let (_, _, errors) =
get_program_using_features!(src, Expect::Success, &[UnstableFeature::Ownership]);
get_program_using_features(src, None, Expect::Success, &[UnstableFeature::Ownership]);
assert_eq!(errors.len(), 0);
}

Expand All @@ -4404,12 +4403,12 @@
let mut array = [1, 2, 3];
borrow(&array);
^^^^^^ This requires the unstable feature 'ownership' which is not enabled
~~~~~~ Pass -Zownership to nargo to enable this feature at your own risk.

Check warning on line 4406 in compiler/noirc_frontend/src/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Zownership)
}

fn borrow(_array: &[Field; 3]) {}
^^^^^^^^^^^ This requires the unstable feature 'ownership' which is not enabled
~~~~~~~~~~~ Pass -Zownership to nargo to enable this feature at your own risk.

Check warning on line 4411 in compiler/noirc_frontend/src/tests.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Zownership)
"#;
check_errors!(src);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: This requires the unstable feature 'ownership' which is not enabled
┌─ src/main.nr:7:27
7 │ fn borrow(_array: &[Field; 3]) {}
│ ----------- Pass -Zownership to nargo to enable this feature at your own risk.

error: This requires the unstable feature 'ownership' which is not enabled
┌─ src/main.nr:4:20
4 │ borrow(&array);
│ ------ Pass -Zownership to nargo to enable this feature at your own risk.

Aborting due to 2 previous errors

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion tooling/nargo_cli/tests/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
nargo.arg("--enable-brillig-debug-assertions");

// Enable enums and ownership as unstable features
nargo.arg("-Zenums");

Check warning on line 38 in tooling/nargo_cli/tests/execute.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Zenums)
nargo.arg("-Zownership");

if force_brillig.0 {
{
Expand Down
Loading