How trybuild normalizes compiler error messages
masterWhen comparing compiler output (stderr) against saved snapshots, trybuild uses a normalization process to ensure tests don't break due to non-semantic changes (like absolute paths, line numbers, or minor compiler version differences).
Instead of a single comparison, trybuild generates a set of Variations. A test passes if the actual compiler output matches any of these variations. This allows the library to introduce new normalization steps without breaking existing snapshots.
Key concepts in normalization include:
- Path Normalization: Replacing absolute paths with placeholders like
$DIR/,$WORKSPACE/,$RUST/, or$CARGO/. - Stripping: Removing noise like
error: Could not compile...orFor more information...messages. - Unindenting: Adjusting the indentation of error blocks to make them more resilient to formatting changes.
- Placeholder Substitution: Replacing specific crate names or dependency versions with generic tokens like
$CRATEor$VERSION.