noir-frontend-tests

Guides writing unit tests for the noirc_frontend compiler crate in Rust.

1.4k|408|Updated Aug 4, 2020
One-click install
npx skills add https://github.com/noir-lang/noir --skill noir-frontend-tests
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: noir-frontend-tests
Source: https://github.com/noir-lang/noir/tree/main/.claude/skills/noir-frontend-tests
Command: npx skills add https://github.com/noir-lang/noir --skill noir-frontend-tests

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing tests for the Noir compiler frontend requires knowing which helper functions to use, how inline error annotations work, and how to avoid common pitfalls like warnings being treated as errors. This Skill provides the conventions and patterns needed to write correct noirc_frontend unit tests.

Core Features & Use Cases

  • Test Helper Reference: Documents compilation helpers like assert_no_errors, get_program_errors, and check_errors, plus monomorphization utilities from test_utils.
  • Inline Error Annotation Syntax: Explains the ^^^ and ~~~ marker syntax for asserting primary and secondary compiler error spans and messages.
  • Test Patterns: Provides templates for regression tests, should_panic reproduction tests for unfixed bugs, and expected-error tests.
  • Use Case: When fixing a compiler bug in noirc_frontend, use this Skill to write a regression test that compiles a Noir snippet with assert_no_errors and links the GitHub issue.

Quick Start

Write a noirc_frontend regression test for a Noir snippet that should compile without errors, following the skill's patterns and helpers.

Frequently Asked Questions about noir-frontend-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a unit test for the Noir compiler frontend?

Add a test under compiler/noirc_frontend/src/tests/ using helpers from tests.rs. Use assert_no_errors(src) for programs that should compile, or check_errors(src) with inline error annotations for programs that should fail.

How do I test expected compile errors in noirc_frontend?

Use check_errors with inline annotations placed on the line below the erroneous code. Carets (^^^) mark the primary error span and message, while tildes (~~~) mark secondary messages, aligned character-by-character with the code above.

Why does assert_no_errors fail even though my Noir code compiles?

Warnings count as errors because get_program returns warnings like dead code and unused functions in the error list. Mark items pub, add pub to struct fields, or prefix unused variables with an underscore to suppress them.

How do I write a reproduction test for an unfixed Noir compiler bug?

Combine assert_no_errors with #[should_panic(expected = "Expected no errors")] and a TODO comment linking the GitHub issue. Once the bug is fixed, remove the should_panic attribute so the test passes normally.

Does noirc_frontend test code include the standard library by default?

No, get_program compiles without the stdlib. Use check_errors_with_stdlib, get_monomorphized_with_stdlib, or set root_and_stdlib: true in GetProgramOptions when tests need stdlib types or traits.

How do I run a single noirc_frontend test?

Run cargo nextest run -p noirc_frontend -E 'test(test_name)' to execute a specific test by name within the noirc_frontend package.