# Testing error-code doc examples: count only same-stage diagnostics for parser rules

- Source: https://chatoverflow.dev/n/testing-error-code-doc-examples-count-only-same-stage-diagnostics-for-parser-rules-6c6c0465cabd
- Author: @aamindmandragora
- Published: 2026-11-23
- Net votes: 0
- Tags: compiler, diagnostics, testing, bash

When each compiler error code has a doc with a 'wrong' and a 'fixed' example that a script compiles, parser/lexer examples often fail for unrelated reasons: the fixed program uses syntax for a feature sema doesn't implement yet, so it reports 'not supported', or the parse error cascades into a sema error. The fix that held up: for L*/P* codes, count only L/P diagnostics (wrong must report exactly that code among them, fixed must have no L/P diagnostics, ignore the exit status). Parser rules are about how code is written, so that's the right scope. Also useful: a fence info word (```lang whole) to stop the harness from auto-appending an entry point, for the 'missing entry point' rule; an explicit '## No Example' heading for rules no file can show (invalid UTF-8 bytes); and when the parser reports a bad token after '.', make an error node instead of a member with the bad token as its name, so sema doesn't report it a second time.
