diff --git a/compiler/noirc_frontend/src/test_utils.rs b/compiler/noirc_frontend/src/test_utils.rs index 3a2bf7ba68c..bbe4c530e88 100644 --- a/compiler/noirc_frontend/src/test_utils.rs +++ b/compiler/noirc_frontend/src/test_utils.rs @@ -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(), @@ -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, @@ -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) } @@ -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", diff --git a/compiler/noirc_frontend/src/tests.rs b/compiler/noirc_frontend/src/tests.rs index 65ea464d34a..2fafe0911b9 100644 --- a/compiler/noirc_frontend/src/tests.rs +++ b/compiler/noirc_frontend/src/tests.rs @@ -37,7 +37,7 @@ use crate::hir_def::stmt::HirStatement; 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) { @@ -74,7 +74,7 @@ fn assert_no_errors(src: &str, test_path: &str) { /// /// 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( @@ -86,7 +86,7 @@ fn check_errors(src: &str, test_path: &str) { ); } -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 = @@ -95,13 +95,13 @@ fn check_errors_using_features(src: &str, test_path: &str, features: &[UnstableF } #[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; @@ -117,7 +117,7 @@ pub(super) fn check_monomorphization_error_using_features( fn check_errors_with_options( src: &str, - test_path: &str, + test_path: Option<&str>, allow_parser_errors: bool, monomorphize: bool, options: FrontendOptions, @@ -305,7 +305,7 @@ macro_rules! get_program_using_features { ($src:expr, $expect:expr, $features:expr) => { $crate::tests::get_program_using_features( $src, - $crate::function_path!(), + Some($crate::function_path!()), $expect, $features, ) @@ -334,7 +334,7 @@ macro_rules! get_program_with_options { ($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, @@ -354,7 +354,7 @@ macro_rules! get_program_captures { #[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) @@ -365,7 +365,7 @@ macro_rules! check_errors { #[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) }; } @@ -373,7 +373,7 @@ macro_rules! check_errors_using_features { #[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!())) }; } @@ -383,7 +383,7 @@ macro_rules! check_monomorphization_error_using_features { ($src:expr, $features:expr) => { $crate::tests::check_monomorphization_error_using_features( $src, - $crate::function_path!(), + Some($crate::function_path!()), $features, ) }; @@ -2071,7 +2071,7 @@ fn normal_generic_used_when_numeric_expected_in_where_clause() { 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#" @@ -2095,7 +2095,7 @@ fn normal_generic_used_when_numeric_expected_in_where_clause() { T::deserialize(fields) } "#; - check_errors(src, &format!("{}_2", function_path!())); + check_errors(src, Some(&format!("{}_2", function_path!()))); } #[named] @@ -3314,7 +3314,7 @@ fn unconditional_recursion_fail() { ]; for (index, src) in srcs.into_iter().enumerate() { - check_errors(src, &format!("{}_{index}", function_path!())); + check_errors(src, Some(&format!("{}_{index}", function_path!()))); } } @@ -4379,7 +4379,6 @@ fn deny_attaching_mut_ref_to_immutable_object() { check_errors!(src); } -#[named] #[test] fn immutable_references_with_ownership_feature() { let src = r#" @@ -4392,7 +4391,7 @@ fn immutable_references_with_ownership_feature() { "#; 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); } diff --git a/test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_without_ownership_feature/Nargo.toml b/test_programs/compile_failure/noirc_frontend_tests_immutable_references_without_ownership_feature/Nargo.toml similarity index 100% rename from test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_without_ownership_feature/Nargo.toml rename to test_programs/compile_failure/noirc_frontend_tests_immutable_references_without_ownership_feature/Nargo.toml diff --git a/test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_without_ownership_feature/src/main.nr b/test_programs/compile_failure/noirc_frontend_tests_immutable_references_without_ownership_feature/src/main.nr similarity index 100% rename from test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_without_ownership_feature/src/main.nr rename to test_programs/compile_failure/noirc_frontend_tests_immutable_references_without_ownership_feature/src/main.nr diff --git a/test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_without_ownership_feature/src_hash.txt b/test_programs/compile_failure/noirc_frontend_tests_immutable_references_without_ownership_feature/src_hash.txt similarity index 100% rename from test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_without_ownership_feature/src_hash.txt rename to test_programs/compile_failure/noirc_frontend_tests_immutable_references_without_ownership_feature/src_hash.txt diff --git a/test_programs/compile_failure/noirc_frontend_tests_immutable_references_without_ownership_feature/stderr.txt b/test_programs/compile_failure/noirc_frontend_tests_immutable_references_without_ownership_feature/stderr.txt new file mode 100644 index 00000000000..59beaeb7311 --- /dev/null +++ b/test_programs/compile_failure/noirc_frontend_tests_immutable_references_without_ownership_feature/stderr.txt @@ -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 diff --git a/test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_with_ownership_feature/Nargo.toml b/test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_with_ownership_feature/Nargo.toml deleted file mode 100644 index bd8f309d6bb..00000000000 --- a/test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_with_ownership_feature/Nargo.toml +++ /dev/null @@ -1,7 +0,0 @@ - - [package] - name = "noirc_frontend_tests_immutable_references_with_ownership_feature" - type = "bin" - authors = [""] - - [dependencies] \ No newline at end of file diff --git a/test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_with_ownership_feature/src/main.nr b/test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_with_ownership_feature/src/main.nr deleted file mode 100644 index b5c718ba0c1..00000000000 --- a/test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_with_ownership_feature/src/main.nr +++ /dev/null @@ -1,8 +0,0 @@ - - unconstrained fn main() { - let mut array = [1, 2, 3]; - borrow(&array); - } - - fn borrow(_array: &[Field; 3]) {} - \ No newline at end of file diff --git a/test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_with_ownership_feature/src_hash.txt b/test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_with_ownership_feature/src_hash.txt deleted file mode 100644 index a123823669f..00000000000 --- a/test_programs/compile_success_no_bug/noirc_frontend_tests_immutable_references_with_ownership_feature/src_hash.txt +++ /dev/null @@ -1 +0,0 @@ -12653056743387050233 \ No newline at end of file diff --git a/tooling/nargo_cli/tests/execute.rs b/tooling/nargo_cli/tests/execute.rs index 8839441de44..f49cdf98cc3 100644 --- a/tooling/nargo_cli/tests/execute.rs +++ b/tooling/nargo_cli/tests/execute.rs @@ -36,7 +36,6 @@ mod tests { // Enable enums and ownership as unstable features nargo.arg("-Zenums"); - nargo.arg("-Zownership"); if force_brillig.0 { {