用途:该技能面向为 noirc_frontend 添加、编写或审查前端单元测试,覆盖回归测试、复现测试与错误检查等场景。测试位于 compiler/noirc_frontend/src/tests/,根模块 tests.rs 定义辅助函数并按主题声明子模块。
主要能力:tests.rs 提供编译辅助,如 assert_no_errors(src)(程序应无错编译,失败打印诊断并返回 Context)、assert_no_errors_without_report(src)、get_program_errors(src) 返回错误列表、get_program_using_features(src, &[UnstableFeature]);错误检查辅助包括 check_errors(src)、check_errors_with_stdlib(src, stdlib_src)、check_errors_using_features、check_monomorphization_error。内联错误标注配合 check_errors 使用,^^^ 表示主错误跨度与信息,~~~ 表示次错误跨度,标记与上一行代码逐字符对齐。test_utils.rs 可经 test_utils feature 供其他 crate 使用,提供 get_program、get_program_with_options、get_monomorphized、get_monomorphized_with_stdlib 及 stdlib_src 预置片段;GetProgramOptions 控制解析/elaborator 错误、stdlib 与前后端选项。
使用方式:回归测试用 assert_no_errors;未修复复现测试加 #[should_panic(expected = "Expected no errors")];预期编译错误用 check_errors。运行命令:cargo nextest run -p noirc_frontend -E 'test(test_name)'。
适用场景与限制:警告会被当作错误,未使用项会使 assert_no_errors 失败,需用 pub 标记或 _ 占位;程序必须含 fn main() {};默认不含 stdlib,需要时用 check_errors_with_stdlib 或 root_and_stdlib: true。