noir-lang/noir · Archived

noir-frontend-tests

Guide for writing noirc_frontend unit tests. Use when adding, writing, or reviewing frontend tests — regression tests, reproduction tests, error-checking tests, or should_panic tests in the compiler frontend.

First seen Mar 29, 2026

Installation

$ npx skills add noir-lang/noir --skill noir-frontend-tests

Stronger alternatives

This repository is archived — consider an actively maintained alternative.

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from noir-lang/noir.

npx skills add noir-lang/noir

Browse all from noir-lang/noir

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

Stars 1.4K
License LICENSE-APACHE
Default branch master
Open issues 620
Status Archived

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 4,696 B
  • docs SUMMARY.md 237 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 1 installs

SKILL.md

Writing noirc_frontend Unit Tests

Tests live under compiler/noirc_frontend/src/tests/. The root module tests.rs defines helpers and declares submodules organized by topic.

Helpers in tests.rs

Importable from submodules via use crate::tests::{...}.

Compilation

Helper Use when
assertnoerrors(src) Program should compile without errors. Panics with "Expected no errors" and prints diagnostics. Returns Context.
assertnoerrorswithoutreport(src) Same but doesn't print diagnostics on failure.
getprogramerrors(src) -> Vec<CompilationError> Get raw error list for manual inspection.
getprogramusing_features(src, &[UnstableFeature]) Compile with specific unstable features enabled.

Error Checking with Inline Annotations

Helper Use when
check_errors(src) Program has inline error annotations (see below).
checkerrorswithstdlib(src, stdlibsrc) Same but prefixes stdlib snippets.
checkerrorsusing_features(src, &[UnstableFeature]) Same with unstable features.
checkmonomorphizationerror(src) Error occurs during monomorphization, not elaboration.

Inline Error Annotation Syntax

Used with check_errors(). Error markers go on the line below the code that produces the error:

let src = r#"
    impl Foo::Bar { }
         ^^^^^^^^ Cannot define a trait impl on associated types
         ~~~~~~~~ secondary message here

    fn main() { }
"#;
check_errors(src);
  • ^^^ = primary error span + message
  • ~~~ = secondary error span + message
  • Markers align character-by-character with the code line above

Helpers in test_utils.rs

Importable via use crate::testutils::{...}. Also usable by other crates via the testutils feature.

Helper Use when
get_program(src) Raw (ParsedModule, Context, Vec<CompilationError>). No stdlib.
getprogramwith_options(src, GetProgramOptions) Full control over compilation.
get_monomorphized(src) Compile + monomorphize. Returns Result<Program, MonomorphizationError>.
getmonomorphizedwithstdlib(usersrc, stdlib_src) Monomorphize with stdlib prefix.
stdlib_src::ZEROED, EQ, ORD Pre-written stdlib snippets for tests needing stdlib traits.

GetProgramOptions

GetProgramOptions {
    allow_parser_errors: bool,       // default: false
    allow_elaborator_errors: bool,   // default: false — needed for check_errors
    root_and_stdlib: bool,           // default: false — treat as stdlib (enables builtins)
    frontend_options: FrontendOptions,
}

Patterns

Regression test for a bug that should compile (already fixed)

/// Regression test for https://github.com/noir-lang/noir/issues/XXXXX
#[test]
fn descriptive_name() {
    let src = r#"
    // ... Noir program ...
    fn main() {}
    "#;
    assert_no_errors(src);
}

Reproduction test for a bug that should compile (not yet fixed)

/// TODO(https://github.com/noir-lang/noir/issues/XXXXX): remove should_panic once fixed
#[test]
#[should_panic(expected = "Expected no errors")]
fn descriptive_name() {
    let src = r#"
    // ... Noir program ...
    fn main() {}
    "#;
    assert_no_errors(src);
}

Test for expected compile error

#[test]
fn descriptive_name() {
    let src = r#"
    fn main() {
        let x: bool = 42;
                       ^^ expected type annotation
    }
    "#;
    check_errors(src);
}

Gotchas

  • Warnings count as errors: getprogram returns warnings (dead code, unused functions) in the Vec<CompilationError>. Unused items cause assertno_errors to fail.

- Fix: mark items pub to suppress "unused" warnings. - pub struct, pub fn for items not called from main(). - If a struct is pub but never constructed, that's still a warning — add pub to fields too, or construct it. - Use the placeholder to suppress unused variable warnings (e.g., an unused x: u32 param becomes x: u32)

  • Always include fn main() {}: Programs without main will fail differently.
  • No stdlib by default: getprogram doesn't include the stdlib. Use checkerrorswithstdlib or rootandstdlib: true if you need stdlib types/traits.
  • Run command: cargo nextest run -p noircfrontend -E 'test(testname)'